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); }
private async Task Connect(IYield yield, PeerConnectionInformation connectionInformation) { isConnecting = true; try { outboundServerPeer = await serverConnectorProvider.GetServerConnector().Connect(yield, connectionInformation); } catch (CouldNotConnectToPeerException exception) { if (exception.Message != string.Empty && !exception.Message.Equals(exceptionMessage)) { LogUtils.Log($"Failed connect to {connectionInformation.Ip}:{connectionInformation.Port}. Details: {exception.Message}"); exceptionMessage = exception.Message; } } finally { if (IsConnected()) { SetNetworkTrafficState(NetworkTrafficState.Flowing); connectContinuously?.Dispose(); onConnected?.Invoke(outboundServerPeer); } } isConnecting = false; }
public void Connect(string serverName, Action onAuthorized, PeerConnectionInformation peerConnectionInformation) { this.serverName = serverName; this.onAuthorized = onAuthorized; var serverConnectionInformation = GetServerConnectionInformation(ServerType.Game, peerConnectionInformation); CoroutinesExecutor.StartTask((yield) => Connect(yield, serverConnectionInformation)); }
private IEnumerator <IYieldInstruction> ConnectContinuously(PeerConnectionInformation connectionInformation) { const int DELAY_TIME = 10; outboundServerPeer = null; while (true) { yield return(new WaitForSeconds(DELAY_TIME)); if (!isConnecting && !IsConnected()) { coroutinesManager.StartTask((yield) => Connect(yield, connectionInformation)); } } }
public async Task <IServerPeer> ConnectAsync(IYield yield, PeerConnectionInformation connectionInformation, ConnectionDetails connectionDetails) { var coroutinesExecuter = coroutinesExecuterProvider.Invoke(); var photonPeer = new PhotonPeer(connectionInformation, connectionDetails.ConnectionProtocol, connectionDetails.DebugLevel, coroutinesExecuter); photonPeer.Connect(); var statusCode = await WaitForStatusCodeChange(yield, photonPeer); if (statusCode == StatusCode.Connect) { return(photonPeer); } LogUtils.Log($"Connecting to {connectionInformation.Ip}:{connectionInformation.Port} failed. Status Code: {statusCode}"); return(null); }
protected ServerConnectionInformation GetServerConnectionInformation(ServerType serverType, PeerConnectionInformation peerConnectionInformation) { return(new ServerConnectionInformation(serverType, peerConnectionInformation)); }
public ServerConnectionInformation(ServerType serverType, PeerConnectionInformation peerConnectionInformation) { ServerType = serverType; PeerConnectionInformation = peerConnectionInformation; }
public void Connect(PeerConnectionInformation connectionInformation) { connectContinuously = coroutinesManager.StartCoroutine(ConnectContinuously(connectionInformation)); }