auto try connect + upgrade (when no initial connection yet)

This commit is contained in:
André Mussche 2013-12-10 20:53:20 +01:00
parent be087753c5
commit 28aa5d1a7a
2 changed files with 27 additions and 4 deletions

View file

@ -55,6 +55,9 @@ type
function TryUpgradeToWebsocket: Boolean;
procedure UpgradeToWebsocket;
procedure Connect; override;
function TryConnect: Boolean;
procedure Disconnect(ANotifyPeer: Boolean); override;
property IOHandler: TIdIOHandlerWebsocket read GetIOHandlerWS write SetIOHandlerWS;
@ -234,6 +237,12 @@ begin
end);
end;
procedure TIdHTTPWebsocketClient.Connect;
begin
FHeartBeat.Enabled := True;
inherited Connect;
end;
destructor TIdHTTPWebsocketClient.Destroy;
var tmr: TObject;
begin
@ -342,6 +351,20 @@ begin
end;
end;
function TIdHTTPWebsocketClient.TryConnect: Boolean;
begin
try
if Connected then Exit(True);
Connect;
Result := Connected;
if Result and SocketIOCompatible then
Result := TryUpgradeToWebsocket;
except
Result := False;
end
end;
function TIdHTTPWebsocketClient.TryUpgradeToWebsocket: Boolean;
var
sError: string;

View file

@ -6094,7 +6094,7 @@ function TSuperRttiContext.FromJson(TypeInfo: PTypeInfo; const obj: ISuperObject
begin
if ObjectIsType(obj, stObject) and (f.FieldType <> nil) then
begin
p := IValueData(TValueData(Value).FHeapData).GetReferenceToRawData;
p := IValueData(TValueData(Value).FValueData).GetReferenceToRawData;
Result := FromJson(f.FieldType.Handle, GetFieldDefault(f, obj.AsObject[GetFieldName(f)]), v);
if Result then
f.SetValue(p, v) else
@ -6408,7 +6408,7 @@ function TSuperRttiContext.ToJson(var value: TValue; const index: ISuperObject):
Result := TSuperObject.Create(stObject);
for f in Context.GetType(Value.TypeInfo).GetFields do
begin
v := f.GetValue(IValueData(TValueData(Value).FHeapData).GetReferenceToRawData);
v := f.GetValue(IValueData(TValueData(Value).FValueData).GetReferenceToRawData);
Result.AsObject[GetFieldName(f)] := ToJson(v, index);
end;
end;
@ -6483,8 +6483,8 @@ function TSuperRttiContext.ToJson(var value: TValue; const index: ISuperObject):
procedure ToInterface;
begin
if TValueData(Value).FHeapData <> nil then
TValueData(Value).FHeapData.QueryInterface(ISuperObject, Result) else
if TValueData(Value).FValueData <> nil then
TValueData(Value).FValueData.QueryInterface(ISuperObject, Result) else
Result := nil;
end;