public Router(HttpClient httpClient, Func <IClientWebSocket> clientWebSocketProvider, SocketIOOptions options) { HttpClient = httpClient; ClientWebSocketProvider = clientWebSocketProvider; UriConverter = new UriConverter(); _messageQueue = new Queue <IMessage>(); Options = options; }
//public WebSocketTransport(IClientWebSocket ws, SocketIOOptions options, IJsonSerializer jsonSerializer, ILogger logger) // : base(options, jsonSerializer, logger) public WebSocketTransport(IClientWebSocket ws, SocketIOOptions options, IJsonSerializer jsonSerializer) : base(options, jsonSerializer) { _ws = ws; _sendLock = new SemaphoreSlim(1, 1); _ws.TextObservable.Subscribe(this); _ws.BytesObservable.Subscribe(this); }
public BaseTransport(SocketIOOptions options, IJsonSerializer jsonSerializer, ILogger logger) { Options = options; MessageSubject = new Subject <IMessage>(); JsonSerializer = jsonSerializer; UriConverter = new UriConverter(); _messageQueue = new Queue <IMessage>(); _logger = logger; }
public HttpTransport(HttpClient http, IHttpPollingHandler pollingHandler, SocketIOOptions options, IJsonSerializer jsonSerializer, ILogger logger) : base(options, jsonSerializer, logger) { _http = http; _httpPollingHandler = pollingHandler; _httpPollingHandler.TextObservable.Subscribe(this); _httpPollingHandler.BytesObservable.Subscribe(this); }
public FxcmSocket2(Uri uri, string key) { var options = new SocketIOOptions { Reconnection = false, Query = new Dictionary <string, string> { { "access_token", key } } }; _socketio = new SocketIO(uri, options); _socketio.OnConnected += OnConnected; _socketio.OnDisconnected += OnDisconnected; _socketio.OnError += OnError; _socketio.OnReceivedEvent += OnReceivedEvent; }
public WebSocketRouter(HttpClient httpClient, Func <IClientWebSocket> clientWebSocketProvider, SocketIOOptions options) : base(httpClient, clientWebSocketProvider, options) { }
public DefaultConnectInterval(SocketIOOptions options) { this.options = options; this.delay = options.ReconnectionDelay; }
public void Listen() { try { var options = new SocketIOOptions(); Dictionary <String, String> query = new Dictionary <String, String>(); query.Add("token", this.Token); options.Query = query; options.Reconnection = false; if (monitorURIList.Count == 0) { monitorURIList.Enqueue(VoicenterRealtimeListener.monitorURI); } socket = new SocketIO(this.currentMonitorURI, options); //await socket.ConnectAsync(); socket.OnConnected += Socket_OnConnected; socket.OnDisconnected += Socket_OnDisconnected; socket.On("loginStatus", async(data) => { await Task.Run(() => { if (this.OnEvent != null) { VoicenterRealtimeResponseArgs res = new VoicenterRealtimeResponseArgs(); res.Name = EventTypes.loginStatus; res.Data = data.GetValue <Object>(); OnEvent(this, res); } }); }); socket.On("AllExtensionsStatus", async(data) => { await Task.Run(() => { if (this.OnEvent != null) { VoicenterRealtimeResponseArgs res = new VoicenterRealtimeResponseArgs(); res.Name = EventTypes.AllExtensionsStatus; res.Data = data.GetValue <Object>(); OnEvent(this, res); } }); }); socket.On("ExtensionEvent", async(data) => { await Task.Run(() => { if (this.OnEvent != null) { VoicenterRealtimeResponseArgs res = new VoicenterRealtimeResponseArgs(); res.Name = EventTypes.ExtensionEvent; res.Data = data.GetValue <Object>(); OnEvent(this, res); } }); }); socket.On("loginSuccess", async(data) => { await Task.Run(() => { if (this.OnEvent != null) { VoicenterRealtimeResponseArgs res = new VoicenterRealtimeResponseArgs(); res.Name = EventTypes.loginSuccess; res.Data = data.GetValue <Object>(); OnEvent(this, res); } }); }); socket.On("QueueEvent", async(data) => { await Task.Run(() => { if (this.OnEvent != null) { VoicenterRealtimeResponseArgs res = new VoicenterRealtimeResponseArgs(); res.Name = EventTypes.QueueEvent; res.Data = data.GetValue <Object>(); OnEvent(this, res); } }); }); socket.On("ExtensionsUpdated", async(data) => { await Task.Run(() => { if (this.OnEvent != null) { VoicenterRealtimeResponseArgs res = new VoicenterRealtimeResponseArgs(); res.Name = EventTypes.ExtensionsUpdated; res.Data = data.GetValue <Object>(); this.Resync(false); OnEvent(this, res); } }); }); socket.On("QueuesUpdated", async(data) => { await Task.Run(() => { if (this.OnEvent != null) { VoicenterRealtimeResponseArgs res = new VoicenterRealtimeResponseArgs(); res.Name = EventTypes.QueuesUpdated; res.Data = data.GetValue <Object>(); this.Resync(false); OnEvent(this, res); } }); }); socket.On("keepaliveResponse", async(data) => { await Task.Run(() => { if (this.OnEvent != null) { VoicenterRealtimeResponseArgs res = new VoicenterRealtimeResponseArgs(); res.Name = EventTypes.keepaliveResponse; this.LastKeepAliveEvent = DateTime.UtcNow; res.Data = data.GetValue <Object>(); OnEvent(this, res); } }); }); this.Connect(); } catch (Exception ex) { VoicenterRealtimeLogger logger = new VoicenterRealtimeLogger(); logger.ex = ex; logger.message = $"in Listen() method, socket {socket?.ServerUri}"; logger.level = LogLevel.Error; Logger.log(this, logger); IsTokenNotValid = true; } }
public void Connect() { if (socket != null) { return; // already connected/ing or failed } System.Uri uri = new System.Uri("https://online-go.com/"); SocketIOOptions options = new SocketIOOptions { Query = new Dictionary <string, string> { { "token", "UNITY" } }, Transport = SocketIOClient.Transport.TransportProtocol.WebSocket, ReconnectionAttempts = 2, }; socket = new SocketIOUnity(uri, options); socket.JsonSerializer = new NewtonsoftJsonSerializer(); socket.OnConnected += (sender, e) => { Debug.Log("socket.OnConnected"); }; socket.OnPing += (sender, e) => { Debug.Log("Ping"); }; socket.OnPong += (sender, e) => { Debug.Log("Pong: " + e.TotalMilliseconds); }; socket.OnDisconnected += (sender, e) => { Debug.Log("disconnect: " + e); }; socket.OnReconnectAttempt += (sender, e) => { Debug.Log($"{System.DateTime.Now} Reconnecting: attempt = {e}"); }; socket.OnAnyInUnityThread((name, response) => { string text = response.GetValue().GetRawText(); Debug.Log("[" + name + "] : " + text); switch (name) { case "active-bots": // this response has the bots' ids as json keys // so we have to deserialize the response this way: Dictionary <int, ResponseActiveBots> bots = JsonConvert.DeserializeObject <Dictionary <int, ResponseActiveBots> >(text); // loop through the bots list: foreach (KeyValuePair <int, ResponseActiveBots> bot in bots) { //Debug.Log(bot.Value.username); } break; } }); socket.Connect(); }