private void SetupService(WebSocketServer server)
        {
            server.AddWebSocketService <WsService>("/msf", (service) =>
            {
                service.IgnoreExtensions = true;
                service.SetServerSocket(this);
                var peer = new PeerWsServer(service);

                service.OnMessageEvent += (data) =>
                {
                    peer.HandleDataReceived(data, 0);
                };

                ExecuteOnUpdate(() =>
                {
                    MsfTimer.Instance.StartCoroutine(peer.SendDelayedMessages(initialSendMessageDelayTime));
                    OnClientConnectedEvent?.Invoke(peer);
                });

                peer.OnPeerDisconnectedEvent += OnClientDisconnectedEvent;

                service.OnCloseEvent += reason =>
                {
                    peer.NotifyDisconnectEvent();
                };

                service.OnErrorEvent += reason =>
                {
                    Logs.Error(reason);
                    peer.NotifyDisconnectEvent();
                };
            });

            server.AddWebSocketService <EchoService>("/echo");
        }
Ejemplo n.º 2
0
        private void SetupService(WebSocketServer server)
        {
            server.AddWebSocketService <WsService>("/w", () =>
            {
                var service = new WsService(this);
                var peer    = new PeerWsServer(service);

                service.OnMessageEvent += (data) =>
                {
                    peer.HandleDataReceived(data, 0);
                };

                ExecuteOnUpdate(() =>
                {
                    BTimer.Instance.StartCoroutine(peer.SendDelayedMessages(_initialDelay));

                    if (Connected != null)
                    {
                        Connected.Invoke(peer);
                    }
                });

                peer.Disconnected += Disconnected;

                service.OnCloseEvent += reason =>
                {
                    peer.NotifyDisconnectEvent();
                };

                service.OnErrorEvent += reason =>
                {
                    //Logs.Error(reason);
                    peer.NotifyDisconnectEvent();
                };

                return(service);
            });
        }