Пример #1
0
 protected void Init(Dictionary <string, string> parameters)
 {
     _socketIo = new SocketIO(Url)
     {
         Parameters = parameters
     };
     _socketIo.OnConnected += () => _plugin.Logger.WriteLine($"Connected to {Name}");
     _socketIo.OnClosed    += OnSocketClosed;
     _socketIo.OnError     += (args) =>
     {
         _plugin.ConnectionError(Name, args.Text);
         _plugin.Logger.WriteLine(args.Text);
         _socketIo.CloseAsync();
     };
     foreach (var s in Event)
     {
         _socketIo.On(s, args =>
         {
             try
             {
                 _plugin.Logger.WriteLine("Event: " + s + ", Message: " + args.Text);
                 OnSocketMessage(s, args.Text);
             }
             catch (Exception e)
             {
                 _plugin.Logger.WriteLine(e);
             }
         });
     }
     _running = true;
     Connect();
 }
Пример #2
0
 protected void Init(Dictionary <string, string> parameters)
 {
     _socketIo = new SocketIO(Url, new SocketIOOptions
     {
         Query = parameters,
         EnabledSslProtocols = (SslProtocols)12288 | SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls
     });
     _socketIo.OnConnected    += (sender, e) => _plugin.Logger.WriteLine($"Connected to {Name}");
     _socketIo.OnDisconnected += OnSocketClosed;
     _socketIo.OnError        += (sender, args) =>
     {
         _plugin.ConnectionError(Name, args);
         _plugin.Logger.WriteLine(args);
         _socketIo.DisconnectAsync();
     };
     foreach (var s in Event)
     {
         _socketIo.On(s, args =>
         {
             try
             {
                 var jObject = args.GetValue <JObject>();
                 _plugin.Logger.WriteLine("Event: " + s + ", Message: " + jObject.ToString(Formatting.None));
                 OnSocketMessage(s, jObject);
             }
             catch (Exception e)
             {
                 _plugin.Logger.WriteLine(e);
             }
         });
     }
     _running = true;
     Connect();
 }