예제 #1
0
파일: P2PClient.cs 프로젝트: grigb/UnityP2P
    public void UpdateClient()
    {
        frameCount++;

        if (peers.Count == 0 && frameCount % 10000 == 0)
        {
            mNetwork.Connect(roomName);
        }


        HandleNetwork();
    }
예제 #2
0
        public override void Connect()
        {
            _webrtcNetwork = WebRtcNetworkFactory.Instance.CreateDefault(
                _network.SignallingServer,
                _network.IceServers.Select(a => a.BynIce).ToArray()
                );

            // Connect to the master peer
            if (_network.IsServer)
            {
                Log.Debug("Connecting to WebRTC Session: {0} (loopback)", _sessionId);
                Connected();
            }
            else
            {
                Log.Debug("Connecting to WebRTC Session: {0}", _sessionId);
                _serverConnectionId = _webrtcNetwork.Connect(_sessionId);
            }

            // Start a server to listen for direct p2p connections using `SessionID:PlayerName` as the session name
            var mySession = UniquePlayerSessionId(_network.PlayerName);

            _webrtcNetwork.StartServer(mySession);
            Log.Debug("Hosting WebRTC Session: {0}", mySession);

            PlayerJoined += OnPlayerJoined;
        }
예제 #3
0
    // Función para entrar a una sala....
    public void OnClickJoinStreaming(Text dir)
    {
        // Si no se encuentra añadidado ya a otra sala...
        if (!isConnectedAsClient)
        {
            // Se crea una instancia del tipo WebRtcNetworkFactory, la cual tiene las direcciones especificadas al principio del script...
            mNetwork = WebRtcNetworkFactory.Instance.CreateDefault(uSignalingUrl, new IceServer[] { new IceServer(uIceServer), new IceServer(uIceServer2) });
            // Se conecta a la sala cuyo nombre se haya extraido del botón presionado en la lista de streaming abiertos...
            mNetwork.Connect(dir.text.ToString());
            // Si la cámara o el micrófono están activos...
            if (IsRecording || isSpeaking)
            {
                // Está transimiendo...
                isTransmitter = true;
            }

            // Inicializa la textura y el componente de audio para recibir los datos...
            CreateImageAndVoice();
            Debug.Log("Entrando al streaming...");
        }
        else
        {
            Debug.Log("Ya eres miembro de una sala de streaming, no puedes abrir más conexiones");
        }
    }
예제 #4
0
 /// <summary>
 /// Connects the inner client to a server identified by the name
 /// </summary>
 /// <param name="name">The name of the server to be connected to</param>
 /// <param name="callback">Whether the connection was successful</param>
 /// <returns>If the inner client can connect to a server</returns>
 public bool Connect(string name, Action <ConnectionId> callback)
 {
     if (m_Network == null)
     {
         return(false);
     }
     m_ConnectCallback = callback;
     m_Network.Connect(name);
     return(true);
 }
예제 #5
0
 public void ConnectToChannel()
 {
     Setup();
     if (mNetwork != null)
     {
         //ConnectionId connect = mNetwork.Connect(channel);
         mNetwork.Connect(channel);
         Debug.Log("ConnectToServer: " + channel);
     }
 }
예제 #6
0
파일: P2PClient.cs 프로젝트: grigb/UnityP2P
    public P2PClient(string signalingServer, string roomName)
    {
        this.roomName = roomName;
        peers         = new Dictionary <string, ConnectionId>();
        //mNetwork = WebRtcNetworkFactory.Instance.CreateDefault("wss://nameless-scrubland-88927.herokuapp.com", new IceServer[] { new IceServer("stun:stun.l.google.com:19302") });
        mNetwork = WebRtcNetworkFactory.Instance.CreateDefault(signalingServer, new IceServer[] { new IceServer("stun:stun.l.google.com:19302") });
        if (mNetwork == null)
        {
            PrintDebug("failed to setup network");
            return;
        }

        mNetwork.Connect(roomName);
    }
예제 #7
0
        private void OnPlayerJoined(string name, CodecSettings _)
        {
            if (name == _network.PlayerName)
            {
                return;
            }

            // Try to connect directly to this peer if their ID comes after yours
            // This ensures that connections are only established in one direction between any two given peers.
            if (_peerHandshake != null && string.Compare(name, _network.PlayerName, StringComparison.Ordinal) > 0)
            {
                var s = UniquePlayerSessionId(name);
                Log.Debug("Trying to establish p2p connection to `{0}`", s);
                _webrtcNetwork.Connect(s);
            }
        }
예제 #8
0
 /// <summary>
 /// Join button pressed. Tries to join a room.
 /// </summary>
 public void JoinRoomButtonPressed()
 {
     Setup();
     mNetwork.Connect(uRoomName.text);
     Append("Connecting to " + uRoomName.text + " ...");
 }
예제 #9
0
 public void Join()
 {
     mNetwork.Connect(uRoomName.text);
     Append("Connect to " + uRoomName.text);
 }
예제 #10
0
 public void Connect(string name)
 {
     Init();
     network.Connect(name);
 }
예제 #11
0
 /// <summary>
 /// Connects to a server using the address
 /// </summary>
 /// <param name="address">Address of the server to connect to</param>
 public void Connect(string address) => network.Connect(address);
예제 #12
0
 private void JoinRoom(string address)
 {
     Setup();
     mNetwork.Connect(address);
     Debug.Log("Connecting to " + address + " ...");
 }