private async void btnDisconnect_Click(object sender, EventArgs e) { Debug.WriteLine("Disconnects from server."); await _httpSignaler.SignOut(); lstPeers.Items.Clear(); btnDisconnect.Enabled = false; btnConnect.Enabled = true; }
private void InitEvents() { _call.OnSendMessageToRemotePeer += (sender, args) => _signaler.SendToPeer(new Message { Id = "0", Content = args, PeerId = _call.PeerId.ToString() }); _call.OnSignedOut += (sender, args) => Task.Run(async() => await _signaler.SignOut()); _call.OnPeerConnectionCreated += async() => await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Frame.Navigate(typeof(CallPage), _call)); _signaler.SignedIn += (sender, args) => Debug.WriteLine("Peer signed in to server."); _signaler.ServerConnectionFailed += (sender, args) => Debug.WriteLine("Server connection failure."); _signaler.PeerConnected += Signaler_PeerConnected; _signaler.PeerDisconnected += Signaler_PeerDisconnected; _signaler.MessageFromPeer += (sender, args) => _call.MessageFromPeerTaskRun(int.Parse(args.Message.PeerId), args.Message.Content); }
private void Call_OnSignedOut(object sender, EventArgs e) { Task.Run(async() => await _signaler.SignOut()); }
private void InitView() { listMessages.ItemsSource = _messages; IsSendReady = false; btnSend.IsEnabled = false; ConnectPeer.Click += async(sender, args) => { Debug.WriteLine("Connects to server."); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => await _httpSignaler.Connect()); ConnectPeer.IsEnabled = false; //ConnectPeer.BackgroundColor = Color.DarkGray; DisconnectPeer.IsEnabled = true; //DisconnectPeer.BackgroundColor = Color.Gray; }; DisconnectPeer.Click += async(sender, args) => { Debug.WriteLine("Disconnects from server."); peersListView.Items.Clear(); await _httpSignaler.SignOut(); DisconnectPeer.IsEnabled = false; //DisconnectPeer.BackgroundColor = Color.DarkGray; ConnectPeer.IsEnabled = true; //ConnectPeer.BackgroundColor = Color.Gray; }; btnChat.Click += async(sender, args) => { if (peersListView.SelectedIndex == -1) { await new MessageDialog("Please select a peer.").ShowAsync(); return; } Peer remotePeer = peersListView.SelectedItem as Peer; if (remotePeer == null) { return; } _httpSignaler.SendToPeer(remotePeer.Id, "OpenDataChannel"); await SetupPeer(remotePeer, true); }; btnSend.Click += (sender, args) => { if (!IsSendReady) { Debug.WriteLine("Please wait, connecting..."); return; } else { Message message = new Message(OrtcController.LocalPeer, DateTime.Now, txtMessage.Text); _messages.Add(message); txtMessage.Text = string.Empty; OnSendMessageToRemotePeer(message); } }; }
async partial void DisconnectButtonClicked(NSObject sender) { await _httpSignaler.SignOut(); }
private void InitView() { peersListView.ItemsSource = HttpSignaler._peers; // Page structure Content = new StackLayout { Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.Center, Children = { new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.CenterAndExpand, Children = { ConnectPeer, DisconnectPeer } }, peersListView, btnChat } }; ConnectPeer.Clicked += async(sender, args) => { Debug.WriteLine("Connects to server."); await _httpSignaler.Connect(); ConnectPeer.IsEnabled = false; ConnectPeer.BackgroundColor = Color.DarkGray; DisconnectPeer.IsEnabled = true; DisconnectPeer.BackgroundColor = Color.Gray; }; DisconnectPeer.Clicked += async(sender, args) => { Debug.WriteLine("Disconnects from server."); await _httpSignaler.SignOut(); DisconnectPeer.IsEnabled = false; DisconnectPeer.BackgroundColor = Color.DarkGray; ConnectPeer.IsEnabled = true; ConnectPeer.BackgroundColor = Color.Gray; }; btnChat.Clicked += async(sender, args) => { Peer remotePeer = peersListView.SelectedItem as Peer; if (remotePeer == null) { return; } _httpSignaler.SendToPeer(remotePeer.Id, "OpenDataChannel"); await SetupPeer(remotePeer, true); }; }