Exemplo n.º 1
0
    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);
    }