MCPcopy
hub / github.com/webrtc/samples / createConnection

Function createConnection

src/content/datachannel/datatransfer/js/main.js:55–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53});
54
55async function createConnection() {
56 sendButton.disabled = true;
57 megsToSend.disabled = true;
58
59 const servers = null;
60
61 const number = Number.parseInt(megsToSend.value);
62 bytesToSend = number * 1024 * 1024;
63
64 pc1 = new RTCPeerConnection(servers);
65
66 // Let's make a data channel!
67 const dataChannelParams = {ordered: false};
68 if (orderedCheckbox.checked) {
69 dataChannelParams.ordered = true;
70 }
71 sendChannel = pc1.createDataChannel('sendDataChannel', dataChannelParams);
72 sendChannel.addEventListener('open', onSendChannelOpen);
73 sendChannel.addEventListener('close', onSendChannelClosed);
74 console.log('Created send data channel: ', sendChannel);
75
76 console.log('Created local peer connection object pc1: ', pc1);
77
78 pc1.addEventListener('icecandidate', e => onIceCandidate(pc1, e));
79
80 pc2 = new RTCPeerConnection(servers);
81 pc2.addEventListener('icecandidate', e => onIceCandidate(pc2, e));
82 pc2.addEventListener('datachannel', receiveChannelCallback);
83
84 try {
85 const localOffer = await pc1.createOffer();
86 await handleLocalDescription(localOffer);
87 } catch (e) {
88 console.error('Failed to create session description: ', e);
89 }
90
91 transferStatus.innerHTML = 'Peer connection setup complete.';
92}
93
94function sendData() {
95 // Stop scheduled timer if any (part of the workaround introduced below)

Callers

nothing calls this directly

Calls 4

handleLocalDescriptionFunction · 0.85
createOfferMethod · 0.80
errorMethod · 0.80
onIceCandidateFunction · 0.70

Tested by

no test coverage detected