Пример #1
0
        public void Prepare()
        {
            _socket?.Disconnect();
            onSocketRestartEvent?.Invoke(this, EventArgs.Empty);
            try
            {
                var initObject = new InitObject
                {
                    LatLon           = new[] { _userLatLon.Longitude, _userLatLon.Latitude },
                    DistanceTreshold = DistanceTreshold,
                    DeviceType       = ".NET CLIENT",
                    Directions       = DirectionsArray ?? new int[] { }
                };

                var json = JObject.FromObject(initObject);
                _socket = IO.Socket(_liveDataUrl);
                _socket.On(Socket.EVENT_CONNECT, () =>
                {
                    _socket.Emit(STROKE_INIT, json);
                    _socket.Emit(LOGS_INIT, "");
                    ShowBadge?.Invoke(this, new BadgeEventArgs(BadgeEventArgs.BadgeType.CONNECTED));
                    PushToLog(this,
                              new BlitzEventArgs("Kapcsolódva Socket.IO-hoz", "Socket.IO-hozzáférés",
                                                 BlitzEventArgs.EventMood.OK));
                });

                _socket.On(Socket.EVENT_ERROR, OnSocketIoError);
                _socket.On(Socket.EVENT_CONNECT_ERROR, OnSocketIoError);
                _socket.On(Socket.EVENT_CONNECT_TIMEOUT, OnSocketIoError);
                _socket.On(STROKES, OnReceiveSingleStroke);
                _socket.On(STROKE_INIT, OnReceiveMultipleStrokes);
                _socket.On(LOGS, OnReceiveLogs);
                _socket.On(LOGS_INIT, OnReceiveLogsInit);
                _socket.On(ALERTS, OnReceiveAlerts);
            }

            catch (Exception e)
            {
                PushToLog?.Invoke(this,
                                  new BlitzEventArgs("Kapcsolódás Socket.IO-hoz sikertelen", "Socket.IO-hozzáférés",
                                                     BlitzEventArgs.EventMood.ERR));
            }
        }
Пример #2
0
 private void OnSocketIoError(object obj)
 {
     ShowBadge?.Invoke(this, new BadgeEventArgs(BadgeEventArgs.BadgeType.CONNECTION_ERROR));
     PushToLog?.Invoke(this,
                       new BlitzEventArgs("Socket.IO kapcsolati hiba", "Socket.IO-hozzáférés", BlitzEventArgs.EventMood.ERR));
 }