Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/content/capture/canvas-pc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h1>
<p>View the browser console to see logging.</p>

<p>Several variables are in global scope, so you can inspect them from the console: <code>canvas</code>,
<code>video</code>, <code>localPeerConnection</code>, <code>remotePeerConnection</code> and <code>stream</code>.
<code>video</code>, <code>pc1</code>, <code>pc2</code> and <code>stream</code>.
</p>

<p>For more demos and information about <code>captureStream()</code>, see <a
Expand Down
2 changes: 1 addition & 1 deletion src/content/datachannel/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2>Receive</h2>

<p>View the console to see logging.</p>

<p>The <code>RTCPeerConnection</code> objects <code>localConnection</code> and <code>remoteConnection</code> are in
<p>The <code>RTCPeerConnection</code> objects <code>pc1</code> and <code>pc2</code> are in
global scope, so you can inspect them in the console as well.</p>

<p>For more information about RTCDataChannel, see <a
Expand Down
52 changes: 26 additions & 26 deletions src/content/datachannel/basic/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

'use strict';

let localConnection;
let remoteConnection;
let pc1;
let pc2;
let sendChannel;
let receiveChannel;
const dataChannelSend = document.querySelector('textarea#dataChannelSend');
Expand All @@ -33,27 +33,27 @@ function disableSendButton() {
function createConnection() {
dataChannelSend.placeholder = '';
const servers = null;
window.localConnection = localConnection = new RTCPeerConnection(servers);
console.log('Created local peer connection object localConnection');
pc1 = new RTCPeerConnection(servers);
console.log('Created local peer connection object pc1');

sendChannel = localConnection.createDataChannel('sendDataChannel');
sendChannel = pc1.createDataChannel('sendDataChannel');
console.log('Created send data channel');

localConnection.onicecandidate = e => {
onIceCandidate(localConnection, e);
pc1.onicecandidate = e => {
onIceCandidate(pc1, e);
};
sendChannel.onopen = onSendChannelStateChange;
sendChannel.onclose = onSendChannelStateChange;

window.remoteConnection = remoteConnection = new RTCPeerConnection(servers);
console.log('Created remote peer connection object remoteConnection');
pc2 = new RTCPeerConnection(servers);
console.log('Created remote peer connection object pc2');

remoteConnection.onicecandidate = e => {
onIceCandidate(remoteConnection, e);
pc2.onicecandidate = e => {
onIceCandidate(pc2, e);
};
remoteConnection.ondatachannel = receiveChannelCallback;
pc2.ondatachannel = receiveChannelCallback;

localConnection.createOffer().then(
pc1.createOffer().then(
gotDescription1,
onCreateSessionDescriptionError
);
Expand All @@ -77,10 +77,10 @@ function closeDataChannels() {
console.log('Closed data channel with label: ' + sendChannel.label);
receiveChannel.close();
console.log('Closed data channel with label: ' + receiveChannel.label);
localConnection.close();
remoteConnection.close();
localConnection = null;
remoteConnection = null;
pc1.close();
pc2.close();
pc1 = null;
pc2 = null;
console.log('Closed peer connections');
startButton.disabled = false;
sendButton.disabled = true;
Expand All @@ -93,27 +93,27 @@ function closeDataChannels() {
}

function gotDescription1(desc) {
localConnection.setLocalDescription(desc);
console.log(`Offer from localConnection\n${desc.sdp}`);
remoteConnection.setRemoteDescription(desc);
remoteConnection.createAnswer().then(
pc1.setLocalDescription(desc);
console.log(`Offer from pc1\n${desc.sdp}`);
pc2.setRemoteDescription(desc);
pc2.createAnswer().then(
gotDescription2,
onCreateSessionDescriptionError
);
}

function gotDescription2(desc) {
remoteConnection.setLocalDescription(desc);
console.log(`Answer from remoteConnection\n${desc.sdp}`);
localConnection.setRemoteDescription(desc);
pc2.setLocalDescription(desc);
console.log(`Answer from pc2\n${desc.sdp}`);
pc1.setRemoteDescription(desc);
}

function getOtherPc(pc) {
return (pc === localConnection) ? remoteConnection : localConnection;
return (pc === pc1) ? pc2 : pc1;
}

function getName(pc) {
return (pc === localConnection) ? 'localPeerConnection' : 'remotePeerConnection';
return (pc === pc1) ? 'pc1' : 'pc2';
}

function onIceCandidate(pc, event) {
Expand Down
4 changes: 2 additions & 2 deletions src/content/datachannel/basic/js/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ describe('datachannel basic', () => {

await Promise.all([
driver.wait(() => driver.executeScript(() => {
return localConnection && localConnection.connectionState === 'connected'; // eslint-disable-line no-undef
return pc1 && pc1.connectionState === 'connected'; // eslint-disable-line no-undef
})),
await driver.wait(() => driver.executeScript(() => {
return remoteConnection && remoteConnection.connectionState === 'connected'; // eslint-disable-line no-undef
return pc2 && pc2.connectionState === 'connected'; // eslint-disable-line no-undef
})),
]);
await driver.wait(() => driver.findElement(webdriver.By.id('sendButton')).isEnabled());
Expand Down
2 changes: 1 addition & 1 deletion src/content/datachannel/datatransfer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h1><a href="https://webrtc.github.io/samples/" title="WebRTC samples homepage">
<section>
<p>View the console to see logging.</p>

<p>The <code>RTCPeerConnection</code> objects <code>localConnection</code> and <code>remoteConnection</code> are
<p>The <code>RTCPeerConnection</code> objects <code>pc1</code> and <code>pc2</code> are
in global scope, so you can inspect them in the console as well.</p>

<p>For more information about RTCDataChannel, see <a
Expand Down
48 changes: 24 additions & 24 deletions src/content/datachannel/datatransfer/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
'use strict';
const MAX_CHUNK_SIZE = 262144;

let localConnection;
let remoteConnection;
let pc1;
let pc2;
let sendChannel;
let receiveChannel;
let chunkSize;
Expand Down Expand Up @@ -61,28 +61,28 @@ async function createConnection() {
const number = Number.parseInt(megsToSend.value);
bytesToSend = number * 1024 * 1024;

localConnection = new RTCPeerConnection(servers);
pc1 = new RTCPeerConnection(servers);

// Let's make a data channel!
const dataChannelParams = {ordered: false};
if (orderedCheckbox.checked) {
dataChannelParams.ordered = true;
}
sendChannel = localConnection.createDataChannel('sendDataChannel', dataChannelParams);
sendChannel = pc1.createDataChannel('sendDataChannel', dataChannelParams);
sendChannel.addEventListener('open', onSendChannelOpen);
sendChannel.addEventListener('close', onSendChannelClosed);
console.log('Created send data channel: ', sendChannel);

console.log('Created local peer connection object localConnection: ', localConnection);
console.log('Created local peer connection object pc1: ', pc1);

localConnection.addEventListener('icecandidate', e => onIceCandidate(localConnection, e));
pc1.addEventListener('icecandidate', e => onIceCandidate(pc1, e));

remoteConnection = new RTCPeerConnection(servers);
remoteConnection.addEventListener('icecandidate', e => onIceCandidate(remoteConnection, e));
remoteConnection.addEventListener('datachannel', receiveChannelCallback);
pc2 = new RTCPeerConnection(servers);
pc2.addEventListener('icecandidate', e => onIceCandidate(pc2, e));
pc2.addEventListener('datachannel', receiveChannelCallback);

try {
const localOffer = await localConnection.createOffer();
const localOffer = await pc1.createOffer();
await handleLocalDescription(localOffer);
} catch (e) {
console.error('Failed to create session description: ', e);
Expand Down Expand Up @@ -143,32 +143,32 @@ function startSendingData() {
}

function maybeReset() {
if (localConnection === null && remoteConnection === null) {
if (pc1 === null && pc2 === null) {
sendButton.disabled = false;
megsToSend.disabled = false;
}
}

async function handleLocalDescription(desc) {
localConnection.setLocalDescription(desc);
console.log('Offer from localConnection:\n', desc.sdp);
remoteConnection.setRemoteDescription(desc);
pc1.setLocalDescription(desc);
console.log('Offer from pc1:\n', desc.sdp);
pc2.setRemoteDescription(desc);
try {
const remoteAnswer = await remoteConnection.createAnswer();
const remoteAnswer = await pc2.createAnswer();
handleRemoteAnswer(remoteAnswer);
} catch (e) {
console.error('Error when creating remote answer: ', e);
}
}

function handleRemoteAnswer(desc) {
remoteConnection.setLocalDescription(desc);
console.log('Answer from remoteConnection:\n', desc.sdp);
localConnection.setRemoteDescription(desc);
pc2.setLocalDescription(desc);
console.log('Answer from pc2:\n', desc.sdp);
pc1.setRemoteDescription(desc);
}

function getOtherPc(pc) {
return (pc === localConnection) ? remoteConnection : localConnection;
return (pc === pc1) ? pc2 : pc1;
}

async function onIceCandidate(pc, event) {
Expand Down Expand Up @@ -209,7 +209,7 @@ function onReceiveMessageCallback(event) {
function onSendChannelOpen() {
console.log('Send channel is open');

chunkSize = Math.min(localConnection.sctp.maxMessageSize, MAX_CHUNK_SIZE);
chunkSize = Math.min(pc1.sctp.maxMessageSize, MAX_CHUNK_SIZE);
console.log('Determined chunk size: ', chunkSize);
dataString = new Array(chunkSize).fill('X').join('');
lowWaterMark = chunkSize; // A single chunk
Expand All @@ -227,8 +227,8 @@ function onSendChannelOpen() {

function onSendChannelClosed() {
console.log('Send channel is closed');
localConnection.close();
localConnection = null;
pc1.close();
pc1 = null;
console.log('Closed local peer connection');
maybeReset();
console.log('Average time spent in send() (ms): ' +
Expand All @@ -241,8 +241,8 @@ function onSendChannelClosed() {

function onReceiveChannelClosed() {
console.log('Receive channel is closed');
remoteConnection.close();
remoteConnection = null;
pc2.close();
pc2 = null;
console.log('Closed remote peer connection');
maybeReset();
}
6 changes: 3 additions & 3 deletions src/content/datachannel/datatransfer/js/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ describe('datachannel datatransfer', () => {

await Promise.all([
driver.wait(() => driver.executeScript(() => {
return localConnection && localConnection.connectionState === 'connected'; // eslint-disable-line no-undef
return pc1 && pc1.connectionState === 'connected'; // eslint-disable-line no-undef
})),
await driver.wait(() => driver.executeScript(() => {
return remoteConnection && remoteConnection.connectionState === 'connected'; // eslint-disable-line no-undef
return pc2 && pc2.connectionState === 'connected'; // eslint-disable-line no-undef
})),
]);

// the remote connection gets closed when it is done.
await driver.wait(() => driver.executeScript(() => {
return remoteConnection === null; // eslint-disable-line no-undef
return pc2 === null; // eslint-disable-line no-undef
}));

const transferred = await driver.findElement(webdriver.By.id('receiveProgress')).getAttribute('value');
Expand Down
2 changes: 1 addition & 1 deletion src/content/datachannel/filetransfer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1><a href="https://webrtc.github.io/samples/" title="WebRTC samples homepage">
<section>
<p>View the console to see logging.</p>

<p>The <code>RTCPeerConnection</code> objects <code>localConnection</code> and <code>remoteConnection</code> are in global scope, so you can inspect them in the console as well.</p>
<p>The <code>RTCPeerConnection</code> objects <code>pc1</code> and <code>pc2</code> are in global scope, so you can inspect them in the console as well.</p>

<p>For more information about RTCDataChannel, see <a href="http://www.html5rocks.com/en/tutorials/webrtc/basics/#toc-rtcdatachannel" title="RTCDataChannel section of HTML5 Rocks article about WebRTC">Getting Started With WebRTC</a>.</p>
</section>
Expand Down
Loading