Esempio n. 1
0
 public void Init(SignaledPeer peer, NetworkingMenu menu)
 {
     this.peer          = peer;
     clickableName.Text = peer.UID.ToString("X4");
     peer.Connect(nameof(SignaledPeer.StatusUpdated), this, nameof(OnStatusChanged));
     OnStatusChanged(peer.CurrentState);
     clickableName.Connect("pressed", menu, nameof(NetworkingMenu.SelectItem),
                           new Godot.Collections.Array {
         this
     });
     peer.Connect(nameof(SignaledPeer.Delete), this, "queue_free");
 }
Esempio n. 2
0
    public SignaledPeer CreateSignaledPeer(int UID, SignaledPeer.ConnectionStateMachine startingState, bool _initiator)
    {
        var peer = new SignaledPeer(UID, this, startingState, PollTimer, _initiator);

        Log.Information("New Peer: {UID} state: {S}", peer.UID, startingState);
        SignaledPeers.Add(UID, peer);
        RTCMP.AddPeer(peer.PeerConnection, UID);

        peer.Connect(nameof(SignaledPeer.Delete), this, nameof(RemoveSignaledPeer),
                     new Godot.Collections.Array {
            UID
        });
        EmitSignal(nameof(PeerAdded), peer);
        return(peer);
    }
Esempio n. 3
0
    public void JoinMesh(byte[] packet)
    {
        //first you need to remove yourself from the current mesh.
        RTCMP.Close();
        SignaledPeers = new Dictionary <int, SignaledPeer>();

        SignaledPeer.Offer incomingOffer = MessagePackSerializer.Deserialize <SignaledPeer.Offer>(packet);

        RTCMP.Initialize(incomingOffer.assignedUID);

        HandshakePeer = CreateSignaledPeer(incomingOffer.UID, SignaledPeer.ConnectionStateMachine.MANUAL, false);
        HandshakePeer.Connect(nameof(SignaledPeer.StatusUpdated), this, nameof(HandshakeStatusUpdated));
        HandshakePeer.PeerConnection.SetRemoteDescription(incomingOffer.type, incomingOffer.sdp);

        foreach (SignaledPeer.BufferedCandidate c in incomingOffer.ICECandidates)
        {
            HandshakePeer.BufferIceCandidate(c);
        }

        EmitSignal(nameof(ConnectedToSession), incomingOffer.assignedUID);
    }