+ };
+
+ const remoteStream = new MediaStream();
+ peerConnection.ontrack = (event) => {
+ remoteStream.addTrack(event.track);
+ const remoteAudioElement = new Audio();
+ remoteAudioElement.srcObject = remoteStream;
+ remoteAudioElement.play();
+ };
+
+ peerConnection.onnegotiationneeded = async () => {
+ if (shouldCreateOffer) {
+ console.debug("Creating RTC offer to ", peerId);
+ const offer = await peerConnection.createOffer();
+ await peerConnection.setLocalDescription(offer);
+
+ onOffer({ peerId, offer });