/// <summary> /// Sets up our dictionary and registers various callbacks. /// </summary> void InitializeMessageHandlers() { SharingStage sharingStage = SharingStage.Instance; if (sharingStage != null) { serverConnection = sharingStage.Manager.GetServerConnection(); connectionAdapter = new NetworkConnectionAdapter(); } // Register our OnMessageReceived function below with connection adapter, // so we can dispatch messages received on the network to classes that register // with our dictionary. connectionAdapter.MessageReceivedCallback += OnMessageReceived; // Cache the local user ID this.localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID(); for (byte index = (byte)TestMessageID.SpellMessage; index < (byte)TestMessageID.Max; index++) { if (MessageHandlers.ContainsKey((TestMessageID)index) == false) { // Just set up the dictionary. MessageHandlers.Add((TestMessageID)index, null); } // Add listeners for each possible message with its index. serverConnection.AddListener(index, connectionAdapter); } }
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.HeadTransform; index < (byte)TestMessageID.Max; index++) { if (MessageHandlers.ContainsKey((TestMessageID)index) == false) { MessageHandlers.Add((TestMessageID)index, null); } serverConnection.AddListener(index, connectionAdapter); } }
void InitializeMessageHandlers() { SharingStage sharingStage = SharingStage.Instance; if (sharingStage != null) { serverConnection = sharingStage.Manager.GetServerConnection(); connectionAdapter = new NetworkConnectionAdapter(); } connectionAdapter.MessageReceivedCallback += OnMessageReceived; // Cache the local user ID this.localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID(); for (byte index = (byte)HoloPaintMessageID.HeadTransform; index < (byte)HoloPaintMessageID.Max; index++) { if (MessageHandlers.ContainsKey((HoloPaintMessageID)index) == false) { MessageHandlers.Add((HoloPaintMessageID)index, null); } serverConnection.AddListener(index, connectionAdapter); } }
// 初始化消息处理器 private void InitializeMessageHandlers() { SharingStage sharingStage = SharingStage.Instance; if (sharingStage == null) { return; } // 获取当前Socket连接 serverConnection = sharingStage.Manager.GetServerConnection(); if (serverConnection == null) { return; } // 初始化消息监听 connectionAdapter = new NetworkConnectionAdapter(); connectionAdapter.MessageReceivedCallback += ConnectionAdapter_MessageReceivedCallback; // 获取当前用户在Socket服务器中生成的唯一编号 LocalUserID = sharingStage.Manager.GetLocalUser().GetID(); // 根据每个自定义消息,添加监听器 for (byte index = (byte)MessageID.UserMessageIDStart; index < (byte)CustomMessageID.Max; index++) { serverConnection.AddListener(index, connectionAdapter); } }
private IEnumerator Start() { // get permission to use the microphone yield return(Application.RequestUserAuthorization(UserAuthorization.Microphone)); if (Application.HasUserAuthorization(UserAuthorization.Microphone)) { if (this.DebugSpewOn) { UnityEngine.Debug.Log("microphone auth obtained"); } this.InitMic(); } else { if (this.DebugSpewOn) { UnityEngine.Debug.Log("microphone not auth"); } } // get the network connection information this.connection = SharingStage.Instance.Manager.GetServerConnection(); this.listener = new NetworkConnectionAdapter(); this.listener.ConnectedCallback += this.OnConnected; this.listener.DisconnectedCallback += this.OnDisconnected; this.listener.ConnectionFailedCallback += this.OnConnectedFailed; this.connection.AddListener(MicrophoneController.microphonePlaybackMessageID, this.listener); internalStart(); }
private void Start() { this.sw.Start(); //SpeakerController.Initialize(); // init the HRTF engine Time.fixedDeltaTime = 0.01f; // 10 ms FixedUpdate times try { this.connection = SharingStage.Instance.Manager.GetServerConnection(); this.listener = new NetworkConnectionAdapter(); this.listener.ConnectedCallback += OnConnected; this.listener.DisconnectedCallback += OnDisconnected; this.listener.ConnectionFailedCallback += OnConnectedFailed; this.listener.MessageReceivedCallback += OnMessageReceived; this.connection.AddListener(SpeakerController.speakerPlaybackMessageID, this.listener); UnityEngine.Debug.Log("SpeakerController Start called"); } catch (Exception ex) { UnityEngine.Debug.Log("Exception: " + ex.ToString()); } internalStart(); //internalStartSpeaker(); }
private void InitializeMessageHandlers() { SharingStage sharingStage = SharingStage.Instance; if (sharingStage == null) { return; } serverConnection = sharingStage.Manager.GetServerConnection(); if (serverConnection == null) { return; } connectionAdapter = new NetworkConnectionAdapter(); connectionAdapter.MessageReceivedCallback += ConnectionAdapter_MessageReceivedCallback; LocalUserID = sharingStage.Manager.GetLocalUser().GetID(); // 根据每一个customeMessageID 添加监听器 for (byte index = (byte)MessageID.UserMessageIDStart; index < (byte)CustomMessageID.Max; ++index) { serverConnection.AddListener(index, connectionAdapter); } }
private void Start() { if (PairingRole == Role.Connector) { pairMaker = new DirectPairConnector(RemoteAddress, RemotePort); } else { pairMaker = new DirectPairReceiver(LocalPort); } pairingAdapter = new PairingAdapter(); pairingAdapter.SuccessEvent += OnPairingConnectionSucceeded; pairingAdapter.FailureEvent += OnPairingConnectionFailed; // Register to listen for disconnections, so we can reconnect automatically if (SharingStage.IsInitialized) { sharingMgr = SharingStage.Instance.Manager; if (sharingMgr != null) { connectionAdapter = new NetworkConnectionAdapter(); connectionAdapter.DisconnectedCallback += OnDisconnected; NetworkConnection pairedConnection = sharingMgr.GetPairedConnection(); pairedConnection.AddListener((byte)MessageID.StatusOnly, connectionAdapter); } } StartPairing(); }
private void TryConnect() { try { if (listener == null) { SharingStage sharingStage = SharingStage.Instance; if (sharingStage && sharingStage.Manager != null) { NetworkConnection connection = SharingStage.Instance.Manager.GetServerConnection(); listener = new NetworkConnectionAdapter(); listener.ConnectedCallback += OnConnected; listener.DisconnectedCallback += OnDisconnected; listener.ConnectionFailedCallback += OnConnectedFailed; listener.MessageReceivedCallback += OnMessageReceived; connection.AddListener((byte)MessageID.AudioSamples, listener); Debug.Log("SpeakerController Start called"); } } } catch (Exception ex) { Debug.Log("Exception: " + ex); } }
void InitializeMessageHandlers() { SharingStage sharingStage = SharingStage.Instance; if (sharingStage != null) { serverConnection = sharingStage.Manager.GetServerConnection(); connectionAdapter = new NetworkConnectionAdapter(); } connectionAdapter.MessageReceivedCallback += OnMessageReceived; // Cache the local user ID this.localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID(); for (byte index = (byte)TestMessageID.HeadTransform; index < (byte)TestMessageID.Max; index++) { if (MessageHandlers.ContainsKey((TestMessageID)index) == false) { MessageHandlers.Add((TestMessageID)index, null); } serverConnection.AddListener(index, connectionAdapter); } //// Add the message handler for toggling highlight MessageHandlers[CustomMessages.TestMessageID.ToggleHighLight] = this.ToggleHighLightMessageReceived; MessageHandlers[CustomMessages.TestMessageID.ToggleMRI] = this.ToggleMRIMessageReceived; }
private void InitMessageHandlers() { SharingStage sharingStage = SharingStage.Instance; if (sharingStage == null) { UnityEngine.Debug.Log("Cannot Initialize CustomMessages. No SharingStage instance found."); return; } _serverConnection = sharingStage.Manager.GetServerConnection(); if (_serverConnection == null) { UnityEngine.Debug.Log("Cannot initialize CustomMessages. Cannot get a server connection."); return; } _connectionAdapter = new NetworkConnectionAdapter(); _connectionAdapter.MessageReceivedCallback += OnMessageReceived; LocalUserId = SharingStage.Instance.Manager.GetLocalUser().GetID(); foreach (var entry in _messageHandlers) { _serverConnection.AddListener((byte)entry.Key, _connectionAdapter); } if (Debug) { InvokeRepeating("SendDebugMessage", 1.0f, 5.0f); } }
/// <summary> /// 初期化 /// </summary> private void InitializeMessageHandler() { SharingStage sharingStage = SharingStage.Instance; // null check if (sharingStage == null) { Debug.Log("Cannot Initialize CustomMessages. No SharingStage instance found."); return; } serverConnection = sharingStage.Manager.GetServerConnection(); // nullcheck if (serverConnection == null) { Debug.Log("Cannot Initialize CustomMessages. Cannot get a server connection."); return; } connectionAdapter = new NetworkConnectionAdapter(); // SharingServiceからのメッセージを受信したときのハンドラを設定 connectionAdapter.MessageReceivedCallback += OnMessageReceived; // 自分のユーザIDを取得 LocalUserId = SharingStage.Instance.Manager.GetLocalUser().GetID(); // 受信メッセージハンドラのdictionaryの箱を用意しておく for (byte index = (byte)TestMessageID.HeadTransform; index < (byte)TestMessageID.Max; index++) { if (MessageHandlers.ContainsKey((TestMessageID)index) == false) { MessageHandlers.Add((TestMessageID)index, null); } serverConnection.AddListener(index, connectionAdapter); } }
private 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; var localUser = SharingStage.Instance.Manager.GetLocalUser(); LocalUserData.Id = localUser.GetID(); LocalUserData.Name = localUser.GetName(); for (byte index = (byte)CommandType.Start; index < (byte)CommandType.UpdateScore; index++) { if (MessageHandlers.ContainsKey((CommandType)index) == false) { MessageHandlers.Add((CommandType)index, null); } serverConnection.AddListener(index, connectionAdapter); } }
protected void OnDestroy() { internalDestroy(); this.connection.RemoveListener(MicrophoneController.microphonePlaybackMessageID, this.listener); this.listener.Dispose(); this.listener = null; Instance = null; }
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); }
// index all TestMessageID and create handlers for it private void InitializeMessageHandlers() { // save instance of sharing stage sharingStage = SharingStage.Instance; // if something goes wrong we stop here if (sharingStage == null || sharingStage.Manager == null) { return; } // setup connection and adapter serverConnection = sharingStage.Manager.GetServerConnection(); connectionAdapter = new NetworkConnectionAdapter(); // Cache the local user ID localUserID = SharingStage.Instance.Manager.GetLocalUser().GetID(); AddCallbacks(); Initialized = true; }
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); }