public ConnectionStatus ConnectToSignalingServer(ConnectionOwner connectionOwner)
        {
            try
            {
                SignaledPeerData.Reset();
                SignalingStatus.Reset();
                SignaledRelayMessages.Reset();

                var socket = new StreamSocket();
                socket.EnableTransferOwnership(Guid.Parse(connectionOwner.OwnerId),
                                               SocketActivityConnectedStandbyAction.Wake);
                socket.ConnectAsync(new HostName(SignalingSettings.SignalingServerHost),
                                    SignalingSettings.SignalingServerPort, SocketProtectionLevel.PlainSocket)
                .AsTask()
                .Wait();
                socket.TransferOwnership(SignalingSocketOperation.SignalingSocketId);
                return(new ConnectionStatus
                {
                    IsConnected = true
                });
            }
            catch (Exception exception)
            {
                Debug.Write("Failed to connect to signalling server: ex: " + exception.Message);
                return(new ConnectionStatus
                {
                    IsConnected = false
                });
            }
        }
 public void DisconnectSignalingServer()
 {
     SocketOperation.Disconnect();
     SignaledPeerData.Reset();
     SignalingStatus.Reset();
     SignaledRelayMessages.Reset();
 }
 public IAsyncAction DisconnectSignalingServerAsync()
 {
     return(Task.Run(async() =>
     {
         SocketOperation.Disconnect();
         SignaledPeerData.Reset();
         SignalingStatus.Reset();
         await SignaledInstantMessages.ResetAsync();
     }).AsAsyncAction());
 }
Beispiel #4
0
 public void DisconnectSignalingServer()
 {
     SignaledPeerData.Reset();
     SignalingStatus.Reset();
     SignaledRelayMessages.Reset();
     if (_streamSocket != null)
     {
         _streamSocket.Dispose();
     }
     _streamSocket = null;
     _isConnected  = false;
 }
Beispiel #5
0
        public ConnectionStatus ConnectToSignalingServer(ConnectionOwner connectionOwner)
        {
            SignaledPeerData.Reset();
            SignalingStatus.Reset();
            SignaledRelayMessages.Reset();
            _streamSocket = new StreamSocket();
            _streamSocket.ConnectAsync(new HostName(SignalingSettings.SignalingServerHost),
                                       SignalingSettings.SignalingServerPort, SocketProtectionLevel.PlainSocket)
            .AsTask()
            .Wait();

            _isConnected = true;

            _signalingClient = _unityContainer.Resolve <SignalingClient>();

            StartReading();

            return(new ConnectionStatus
            {
                IsConnected = _isConnected
            });
        }
        public IAsyncOperation <ConnectionStatus> ConnectToSignalingServerAsync(ConnectionOwner connectionOwner)
        {
            return(Task.Run(async() =>
            {
                try
                {
                    SignaledPeerData.Reset();
                    SignalingStatus.Reset();
                    await SignaledInstantMessages.ResetAsync();

                    var socket = new StreamSocket();
                    socket.EnableTransferOwnership(Guid.Parse(connectionOwner.OwnerId),
                                                   SocketActivityConnectedStandbyAction.Wake);

                    var connectCancellationTokenSource = new CancellationTokenSource(2000);
                    var connectAsync = socket.ConnectAsync(new HostName(SignalingSettings.SignalingServerHost),
                                                           SignalingSettings.SignalingServerPort, SocketProtectionLevel.PlainSocket);
                    var connectTask = connectAsync.AsTask(connectCancellationTokenSource.Token);
                    await connectTask;

                    socket.TransferOwnership(SignalingSocketOperation.SignalingSocketId);
                    return new ConnectionStatus
                    {
                        IsConnected = true
                    };
                }
                catch (Exception exception)
                {
                    Debug.WriteLine("Failed to connect to signalling server: ex: " + exception.Message);
                    return new ConnectionStatus
                    {
                        IsConnected = false
                    };
                }
            }).AsAsyncOperation());
        }