public async Task <ConnectionStatus> Connect(IYield yield, ICoroutinesExecutor coroutinesExecutor, ServerConnectionInformation serverConnectionInformation)
        {
            var serverType = serverConnectionInformation.ServerType;

            if (IsConnected())
            {
                throw new ServerConnectionFailed($"A connection already exists with a {serverType} server.");
            }

            ConnectionInformation = serverConnectionInformation;

            var ip   = ConnectionInformation.PeerConnectionInformation.Ip;
            var port = ConnectionInformation.PeerConnectionInformation.Port;

            LogUtils.Log($"Connecting to a {serverType} server. IP: {ip} Port: {port}");

            var serverConnector      = new PhotonServerConnector(() => coroutinesExecutor);
            var networkConfiguration = NetworkConfiguration.GetInstance();
            var connectionDetails    = new ConnectionDetails(networkConfiguration.ConnectionProtocol, networkConfiguration.DebugLevel);

            ServerPeer = await serverConnector.ConnectAsync(yield, ConnectionInformation.PeerConnectionInformation, connectionDetails);

            if (ServerPeer == null)
            {
                return(ConnectionStatus.Failed);
            }

            SubscribeToDisconnectionNotifier();

            LogUtils.Log($"A {serverType} server has been connected: {ip}:{port}");

            serviceConnectionNotifier.Connection();
            return(ConnectionStatus.Succeed);
        }
 public CoroutinesManager(ICoroutinesExecutor executor)
 {
     this.executor = executor;
 }
        public PhotonPeer(PeerConnectionInformation serverConnectionInformation,
                          ConnectionProtocol connectionProtocol, DebugLevel debugLevel, ICoroutinesExecutor coroutinesExecuter)
        {
            NetworkTrafficState = NetworkTrafficState.Flowing;

            this.serverConnectionInformation = serverConnectionInformation;

            RawPeer = new ExitGames.Client.Photon.PhotonPeer(this, connectionProtocol)
            {
                ChannelCount = 4
            };

            #if UNITY_WEBGL || UNITY_XBOXONE || WEBSOCKET
            if (connectionProtocol == ConnectionProtocol.WebSocket ||
                connectionProtocol == ConnectionProtocol.WebSocketSecure)
            {
                var websocketType = typeof(SocketWebTcpCoroutine);
                RawPeer.SocketImplementationConfig[ConnectionProtocol.WebSocket] = websocketType;
            }
            #endif

            RawPeer.DebugOut = debugLevel;

            coroutinesExecuter.StartCoroutine(UpdateEngine());

            eventsBuffer             = new Queue <RawMessageData>(10);
            operationResponsesBuffer = new Queue <Tuple <RawMessageResponseData, short> >(10);
            optionsBuffer            = new Queue <BufferOption>(10);
        }