AddListener() public method

public AddListener ( byte messageType, NetworkConnectionListener newListener ) : void
messageType byte
newListener NetworkConnectionListener
return void
示例#1
0
        void InitializeMessageHandlers()
        {
            SharingStage sharingStage = SharingStage.Instance;

            if (sharingStage == null)
            {
                Debug.Log("Cannot Initialize CustomMessages. No SharingStage instance found.");
                return;
            }

            serverConnection = sharingStage.Manager.GetServerConnection();
            if (serverConnection == null)
            {
                Debug.Log("Cannot initialize CustomMessages. Cannot get a server connection.");
                return;
            }

            connectionAdapter = new NetworkConnectionAdapter();
            connectionAdapter.MessageReceivedCallback += OnMessageReceived;

            // Cache the local user ID
            this.localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID();
            /////////////////////////////////////////////////////////////////////////////////////////
            // for (byte index = (byte)TestMessageID.BodyData; index < (byte)TestMessageID.Max; index++)
            for (byte index = (byte)TestMessageID.StartID; index < (byte)TestMessageID.Max; index++)
            {
                if (MessageHandlers.ContainsKey((TestMessageID)index) == false)
                {
                    MessageHandlers.Add((TestMessageID)index, null);
                }

                serverConnection.AddListener(index, connectionAdapter);
            }
        }
        void Start()
        {
            if (this.PairingRole == Role.Connector)
            {
                this.pairMaker = new DirectPairConnector(this.RemoteAddress, this.RemotePort);
            }
            else
            {
                this.pairMaker = new DirectPairReceiver(this.LocalPort);
            }

            this.pairingAdapter = new PairingAdapter();
            this.pairingAdapter.SuccessEvent += OnPairingConnectionSucceeded;
            this.pairingAdapter.FailureEvent += OnPairingConnectionFailed;

            // Register to listen for disconnections, so we can reconnect automatically
            if (SharingStage.Instance != null)
            {
                this.sharingMgr = SharingStage.Instance.Manager;

                if (this.sharingMgr != null)
                {
                    this.connectionAdapter = new NetworkConnectionAdapter();
                    this.connectionAdapter.DisconnectedCallback += OnDisconnected;

                    NetworkConnection pairedConnection = this.sharingMgr.GetPairedConnection();
                    pairedConnection.AddListener((byte)MessageID.StatusOnly, this.connectionAdapter);
                }
            }

            StartPairing();
        }
        private void Connect()
        {
            ClientConfig config = new ClientConfig(ClientRole);

            config.SetIsAudioEndpoint(IsAudioEndpoint);
            config.SetLogWriter(logWriter);

            // Only set the server info is we are connecting on awake
            if (connectOnAwake)
            {
                config.SetServerAddress(ServerAddress);
                config.SetServerPort(ServerPort);
            }

            Manager = SharingManager.Create(config);

            //set up callbacks so that we know when we've connected successfully
            networkConnection        = Manager.GetServerConnection();
            networkConnectionAdapter = new NetworkConnectionAdapter();
            networkConnectionAdapter.ConnectedCallback += NetworkConnectionAdapter_ConnectedCallback;
            networkConnection.AddListener((byte)MessageID.StatusOnly, networkConnectionAdapter);

            SyncStateListener = new SyncStateListener();
            Manager.RegisterSyncListener(SyncStateListener);

            Root = new SyncRoot(Manager.GetRootSyncObject());

            SessionsTracker     = new ServerSessionsTracker(Manager.GetSessionManager());
            SessionUsersTracker = new SessionUsersTracker(SessionsTracker);

            using (XString userName = new XString(DefaultUserName))
            {
                Manager.SetUserName(userName);
            }
        }
示例#4
0
        private void Connect()
        {
            var config = new ClientConfig(ClientRole);

            config.SetIsAudioEndpoint(IsAudioEndpoint);
            config.SetLogWriter(logWriter);

            // Only set the server info is we are connecting on awake
            if (connectOnAwake)
            {
                config.SetServerAddress(ServerAddress);

                /*#if UNITY_EDITOR
                 *  config.SetServerAddress("localhost");
                 #endif*/
                config.SetServerPort(ServerPort);
            }

            Manager = SharingManager.Create(config);

            //set up callbacks so that we know when we've connected successfully
            networkConnection        = Manager.GetServerConnection();
            networkConnectionAdapter = new NetworkConnectionAdapter();
            networkConnectionAdapter.ConnectedCallback += NetworkConnectionAdapter_ConnectedCallback;
            networkConnection.AddListener((byte)MessageID.StatusOnly, networkConnectionAdapter);

            SyncStateListener = new SyncStateListener();
            Manager.RegisterSyncListener(SyncStateListener);

            Root = new SyncRoot(Manager.GetRootSyncObject());

            SessionsTracker     = new ServerSessionsTracker(Manager.GetSessionManager());
            SessionUsersTracker = new SessionUsersTracker(SessionsTracker);

            using (var userName = new XString(DefaultUserName))
            {
#if UNITY_WSA && !UNITY_EDITOR
                Manager.SetUserName(SystemInfo.deviceName);
#else
                if (!string.IsNullOrEmpty(Environment.UserName))
                {
                    Manager.SetUserName(Environment.UserName);
                }
                else
                {
                    User localUser = Manager.GetLocalUser();
                    Manager.SetUserName(userName + localUser.GetID().ToString());
                }
#endif
            }
        }
示例#5
0
        private void Connect()
        {
            ClientConfig config = new ClientConfig(ClientRole);

            config.SetIsAudioEndpoint(IsAudioEndpoint);
            config.SetLogWriter(logWriter);
            config.SetServerAddress(ServerAddress);
            config.SetServerPort(ServerPort);
            config.SetProfilerEnabled(false);

            sharingMgr = SharingManager.Create(config);

            //set up callbacks so that we know when we've connected successfully
            networkConnection        = sharingMgr.GetServerConnection();
            networkConnectionAdapter = new NetworkConnectionAdapter();
            networkConnectionAdapter.ConnectedCallback += NetworkConnectionAdapter_ConnectedCallback;
            networkConnection.AddListener((byte)MessageID.StatusOnly, networkConnectionAdapter);
        }
示例#6
0
        public XToolsApp(string[] args = null)
        {
            parsedArguments = ParseCommandLine(args);
            this.logWriter = new ConsoleLogWriter();

            ClientConfig config = new ClientConfig(ClientRole.Primary);
            config.SetServerAddress(GetArgumentOrDefault("sessionserver", "localhost"));
            config.SetLogWriter(this.logWriter);

            this.Manager = SharingManager.Create(config);
            this.syncListener = new ConsoleSyncReporter();

            this.viewerConnection = this.Manager.GetPairedConnection();
            this.serverConnection = this.Manager.GetServerConnection();
            this.SessionManager = this.Manager.GetSessionManager();

            BeginPairing();

            ViewerListener = new NetworkConnectionAdapter();
            ViewerListener.ConnectedCallback += this.OnViewerConnected;
            ViewerListener.ConnectionFailedCallback += this.OnViewerConnectionFailed;
            ViewerListener.DisconnectedCallback += this.OnViewerDisconnected;
            viewerConnection.AddListener((byte)MessageID.StatusOnly, ViewerListener);

            ServerListener = new NetworkConnectionAdapter();
            ServerListener.ConnectedCallback += this.OnSessionConnected;
            ServerListener.ConnectionFailedCallback += this.OnSessionConnectionFailed;
            ServerListener.DisconnectedCallback += this.OnSessionDisconnected;
            serverConnection.AddListener((byte)MessageID.StatusOnly, ServerListener);

            this.rootObject = this.Manager.GetRootSyncObject();
            this.rootObject.AddListener(this.syncListener);

            // Listen for new sessions
            SessionManagerListener = new XToolsSessionManagerListener();
            this.SessionManager.AddListener(SessionManagerListener);
        }
示例#7
0
        public void Connect(string server, string userName = "******", int port = 20602, ClientRole clientRole = ClientRole.Primary)
        {
            ClientConfig config = new ClientConfig(clientRole);
            config.SetServerAddress(server);
            config.SetServerPort(port);
            config.SetLogWriter(LogWriter);

            this.SharingManager = SharingManager.Create(config);
            this.SharingManager.SetUserName(userName);
            
            this.viewerConnection = this.SharingManager.GetPairedConnection();
            this.serverConnection = this.SharingManager.GetServerConnection();
            this.SessionManager = this.SharingManager.GetSessionManager();
            
            BeginPairing();

            ViewerListener = new NetworkConnectionAdapter();
            ViewerListener.ConnectedCallback += this.OnViewerConnected;
            ViewerListener.ConnectionFailedCallback += this.OnViewerConnectionFailed;
            ViewerListener.DisconnectedCallback += this.OnViewerDisconnected;
            viewerConnection.AddListener((byte)MessageID.StatusOnly, ViewerListener);

            ServerListener = new NetworkConnectionAdapter();
            ServerListener.ConnectedCallback += this.OnSessionConnected;
            ServerListener.ConnectionFailedCallback += this.OnSessionConnectionFailed;
            ServerListener.DisconnectedCallback += this.OnSessionDisconnected;
            serverConnection.AddListener((byte)MessageID.StatusOnly, ServerListener);

            this.syncListener = new ConsoleSyncReporter();
            this.rootObject = this.SharingManager.GetRootSyncObject();
            this.rootObject.AddListener(this.syncListener);

            SessionManagerListener = new XToolsSessionManagerListener(this.LogWriter);
            this.SessionManager.AddListener(SessionManagerListener);
            networkMessageLoop = new Timer(new TimerCallback((a) => Update()), null, 0, 1000);
        }