Пример #1
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;
        }
Пример #2
0
    /// <summary>
    /// Open room button pressed.
    ///
    /// Opens a room / starts a server
    /// </summary>
    public void OpenRoomButtonPressed()
    {
        Setup();
        EnsureLength();
        mNetwork.StartServer(uRoomName.text);

        Debug.Log("StartServer " + uRoomName.text);
    }
Пример #3
0
 public void CreateChannel()
 {
     Setup();
     if (mNetwork != null)
     {
         mNetwork.StartServer(channel);
         Debug.Log("StartServer: " + channel);
     }
 }
Пример #4
0
 // ================================================
 // NETWORK API
 // ================================================
 /// <summary>
 /// Starts the server with a given server name on this node
 /// </summary>
 /// <param name="name">The name of the server to be started</param>
 /// <param name="callback">Callback for whether the server could start</param>
 /// <returns>If a server can be started</returns>
 public bool StartServer(string name, Action <bool> callback)
 {
     if (m_Network == null)
     {
         return(false);
     }
     m_StartServerCallback = callback;
     m_Network.StartServer(name);
     return(true);
 }
Пример #5
0
        public override void Connect()
        {
            _webrtcNetwork = WebRtcNetworkFactory.Instance.CreateDefault(
                _network.SignallingServer,
                _network.IceServers.Select(a => a.BynIce).ToArray()
                );
            _webrtcNetwork.StartServer(_sessionId);

            Log.Debug("Hosting WebRTC Session: {0}", _sessionId);

            base.Connect();
        }
Пример #6
0
    public void OpenRoom()
    {
        if (mNetwork is WebRtcNetwork)
        {
            ((WebRtcNetwork)mNetwork).StartServer(uRoomName.text);
        }
        else
        {
            mNetwork.StartServer();
        }

        Debug.Log("StartServer " + uRoomName.text);
    }
Пример #7
0
 // Crea una sala de streaming...
 public void InitStreaming()
 {
     // Si no hay servidor creado....
     if (!mIsServer)
     {
         // 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) });
         // Crea una sala cuyo nombre será el del jugador...
         mNetwork.StartServer(GetComponent <PlayerCode>().GetName().ToString());
         // Inicializa la textura y el componente de audio para recibir los datos...
         CreateImageAndVoice();
     }
 }
Пример #8
0
    public P2PServer(string signalingServer, string roomName)
    {
        this.roomName       = roomName;
        lastTimeGotAnything = DateTime.Now;
        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.StartServer(roomName);
    }
Пример #9
0
    // Update is called once per frame
    public void UpdateServer()
    {
        frameCount++;

        if (!mIsServer && frameCount % 50000 == 0)
        {
            mNetwork.StartServer(roomName);
        }

        // It has been 40 seconds since got any messages, reset server before it decides to die
        if ((DateTime.Now - lastTimeGotAnything).TotalSeconds > 40)
        {
            PrintDebug("Server timeout after 40 seconds, restarting server");
            if (mIsServer)
            {
                mNetwork.StopServer();
            }
            mIsServer = false;
            mNetwork.StartServer(roomName);
            lastTimeGotAnything = DateTime.Now;
        }

        HandleNetwork();
    }
Пример #10
0
    public void OnCreateRoomClicked()
    {
        Setup();
        // All players will connect to the same room for now TODO
        const string chars = "abcdefghijklmnopqrstuvwxyz0123456789";

        System.Random rand     = new System.Random();
        string        roomName = "";

        for (int i = 0; i < 6; i++)
        {
            roomName += chars[rand.Next(chars.Length)];
        }
        mNetwork.StartServer(roomName);
        Debug.Log("StartServer " + roomName);
    }
Пример #11
0
 public void Create(string name)
 {
     Init();
     network.StartServer(name);
 }
Пример #12
0
 /// <summary>
 /// Starts a server for the given address
 /// </summary>
 /// <param name="addr">Address at which the server will run</param>
 public void StartServer(string addr) => network.StartServer(addr);