private void ProcessReceivedItem(GSObject response, GSConnection connection) { string theType = response.Type; if (theType.EndsWith("Response")) { if (theType.Equals(".AuthenticationResponse")) { SetUserId(response.GetString("userId")); } ProcessReceivedResponse(response, connection); } else if (theType.EndsWith("Message")) { GSPlatform.ExecuteOnMainThread(() => { try { GSMessageHandler.HandleMessage(this, response); } catch (Exception e) { GSPlatform.DebugMsg(e.ToString()); } }); } }
private void TrimOldConnections() { List <GSConnection> connectionsToCheck = null; lock (_connections) { connectionsToCheck = new List <GSConnection> (_connections); } foreach (GSConnection connection in connectionsToCheck) { if (connection.PendingRequestCount == 0 && connection._stopped) { lock (_connections) { _connections.Remove(connection); } connection.Close(); if (TraceMessages) { GSPlatform.DebugMsg("REMOVING CONNECTION"); } } } }
private void Log(string message) { if (TraceMessages) { GSPlatform.DebugMsg(message); } }
internal void WebSocketClient_OnError(String errorMessage, GSConnection connection) { if (errorMessage.Contains("INVALID LOCATION")) { Disconnect(); } else if (errorMessage.Contains("UNKNOWN SERVICE")) { GSPlatform.DebugMsg("ERROR: UNKNOWN SERVICE"); Disconnect(); } _currentSocketUrl = BuildServiceUrl(GSPlatform); if (TraceMessages) { GSPlatform.DebugMsg("ERROR:" + errorMessage); } }
private void ProcessQueues() { try { ExecuteRequestedActions(); ConnectIfRequired(); TrimOldConnections(); ProcessPersistantQueue(); ProcessSendQueue(); ProcessPendingQueue(); } catch (Exception e) { GSPlatform.ExecuteOnMainThread(() => { if (TraceMessages) { GSPlatform.DebugMsg(e.ToString()); } }); } }
internal void OnMessageReceived(String message, GSConnection connection) { GSPlatform.DebugMsg("RECV:" + message); GSObject response = GSObject.FromJson(message); if (response.ContainsKey("connectUrl")) { _currentSocketUrl = response.GetString("connectUrl"); connection.Stop(); CalcNewReconnectionTimeout(0); NewConnection(); } if (response.ContainsKey("authToken")) { GSPlatform.ExecuteOnMainThread(() => { GSPlatform.AuthToken = response.GetString("authToken"); }); } if (response.Type != null) { if (".AuthenticatedConnectResponse".Equals(response.Type)) { Handshake(response, connection); } else { ProcessReceivedItem(response, connection); } } }
private void CancelRequest(GSRequest request) { if (request.Durable) { return; } GSObject error = new GSObject("ClientError"); error.AddObject("error", new GSRequestData().AddString("error", "timeout")); error.AddString("requestId", request.GetString("requestId")); GSPlatform.ExecuteOnMainThread(() => { try { request.Complete(this, error); } catch (Exception e) { GSPlatform.DebugMsg(e.ToString()); } }); }
private void Handshake(GSObject response, GSConnection connection) { if (response.ContainsKey("error")) { GSPlatform.DebugMsg(response.GetString("error")); ShutDown(null); } else if (response.ContainsKey("nonce")) { SendHandshake(response, connection); } else { if (response.ContainsKey("sessionId")) { _sessionId = response.GetString("sessionId"); connection.SessionId = _sessionId; if (response.ContainsKey("authToken")) { GSPlatform.ExecuteOnMainThread(() => { GSPlatform.AuthToken = response.GetString("authToken"); }); } else { GSPlatform.ExecuteOnMainThread(() => { GSPlatform.AuthToken = "0"; GSPlatform.UserId = ""; }); } if (response.ContainsKey("clientConfig")) { GSData clientConfig = response.GetGSData("clientConfig"); RetryBase = clientConfig.GetInt("retryBase").GetValueOrDefault(GS.RetryBase); RetryMax = clientConfig.GetInt("retryMax").GetValueOrDefault(GS.RetryMax); RequestTimeout = clientConfig.GetInt("requestTimeout").GetValueOrDefault(GS.RequestTimeout); DurableConcurrentRequests = clientConfig.GetInt("durableConcurrentRequests").GetValueOrDefault(GS.DurableConcurrentRequests); DurableDrainInterval = clientConfig.GetInt("durableDrainInterval").GetValueOrDefault(GS.DurableDrainInterval); HandshakeOffset = clientConfig.GetInt("handshakeOffset").GetValueOrDefault(GS.HandshakeOffset); } else { RetryBase = GS.RetryBase; RetryMax = GS.RetryMax; RequestTimeout = GS.RequestTimeout; DurableConcurrentRequests = GS.DurableConcurrentRequests; DurableDrainInterval = GS.DurableDrainInterval; HandshakeOffset = GS.HandshakeOffset; } //We want availability to be triggered before authenticated GSPlatform.DebugMsg("Available"); connection.Ready = true; setAvailability(true); if (response.ContainsKey("userId")) { SetUserId(response.GetString("userId")); } CalcNewReconnectionTimeout(0); } } }