June 2024
Beginner to intermediate
268 pages
6h 26m
English
With all of that in place, we can get down to work on the data-channel logic. Let’s use a symmetric data channel, meaning that both peers will open the data channel as part of joining the call:
| | /** |
| | * User-Media and Data-Channel Functions |
| | */ |
| | |
| | function addChatChannel(peer) { |
| | peer.chatChannel = |
| | peer.connection.createDataChannel('text chat', |
| | { negotiated: true, id: 100 }); |
| | peer.chatChannel.onmessage = function(event) { |
| | appendMessage('peer', '#chat-log', event.data); |
| | }; |
| | |
| | peer.chatChannel.onclose = function() { |
| | console.log('Chat channel closed.'); |
| | }; |
| | } |
Everything here should look at least a little familiar from the video-filters example: ...
Read now
Unlock full access