/// <summary> /// Callback on Send button from text chat clicker. /// If connected, this sends the text message to the remote peer using /// the previously opened data channel. /// </summary> /// <param name="sender">The object which invoked the event.</param> /// <param name="e">Event arguments.</param> private void ChatSendButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(chatInputBox.Text)) { return; } ChatChannelModel chat = SessionModel.ChatChannels.SelectedItem; if (chat == null) { return; } // Send the message through the data channel byte[] chatMessage = System.Text.Encoding.UTF8.GetBytes(chatInputBox.Text); chat.DataChannel.SendMessage(chatMessage); // Save and display in the UI var newLine = $"[local] {chatInputBox.Text}\n"; chat.AppendText(newLine); chatScrollViewer.ChangeView(chatScrollViewer.HorizontalOffset, chatScrollViewer.ScrollableHeight, chatScrollViewer.ZoomFactor); // scroll to end chatInputBox.Text = string.Empty; }
private void OnDataChannelAdded(DataChannel channel) { Logger.Log($"Added data channel '{channel.Label}' (#{channel.ID})."); ThreadHelper.RunOnMainThread(() => { var chat = new ChatChannelModel(channel); ChatChannels.Add(chat); }); }