public PeerWsServer(WsService session)
        {
            _session = session;

            _session.OnOpenEvent  += () => { _isConnected = true; };
            _session.OnCloseEvent += (msg) => { _isConnected = false; };
            _session.OnErrorEvent += (msg) => { _isConnected = false; };

            _delayedMessages = new Queue <byte[]>();

            // When we're creating a peer in server, it's considered that there's
            // already a connection for which we're making it.
            _isConnected = true;
        }
Пример #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);
            });
        }