void ToggleInit() { isInit = !isInit; if (isInit) { logger = new RemoteLogger(); MainLog.AddAppender(GetWebRtcAppender()); logger.Connect("log"); disposable = new CompositeDisposable(); logger.remote.OnEvent .Where(_ => _.Type == NetEventType.Disconnected) .Subscribe(_ => { ToggleInit(); ToggleInit(); }) .AddTo(disposable); logger.remote.OnEvent .Where(_ => _.Type == NetEventType.NewConnection) .Subscribe(_ => view.startButton .GetComponentInChildren <Text>().text = "Stop client") .AddTo(disposable); } else { MainLog.RemoveAppender(GetWebRtcAppender()); logger.Disconnect(); disposable.Dispose(); } view.Toggle(isInit); }
void ToggleInit() { isInit = !isInit; if (isInit) { logger = new RemoteLogger(); logger.Create("log"); disposable = new CompositeDisposable(); logger.remote.OnEvent.Subscribe(_ => { if (_.Type != NetEventType.ReliableMessageReceived && _.Type != NetEventType.UnreliableMessageReceived ) { return; } string message = Encoding.UTF8.GetString( _.MessageData.Buffer, 0, _.MessageData.ContentLength); view.SpawnText(_.ConnectionId + ". " + message); }).AddTo(disposable); logger.remote.OnEvent .Where(_ => _.Type == NetEventType.ServerInitialized) .Subscribe(_ => view.startButton .GetComponentInChildren <Text>().text = "Stop server") .AddTo(disposable); } else { logger.Disconnect(); disposable.Dispose(); } view.Toggle(isInit); }