Skip to content

Commit 81bd60e

Browse files
authored
Merge pull request #1722 from fippo/peerconnection-naming
Refactor: Rename peer connection variables
2 parents 8e831af + c616dc7 commit 81bd60e

File tree

18 files changed

+168
-170
lines changed

18 files changed

+168
-170
lines changed

src/content/capture/canvas-pc/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h1>
5050
<p>View the browser console to see logging.</p>
5151

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

5656
<p>For more demos and information about <code>captureStream()</code>, see <a

src/content/datachannel/basic/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h2>Receive</h2>
5656

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

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

6262
<p>For more information about RTCDataChannel, see <a

src/content/datachannel/basic/js/main.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
'use strict';
1010

11-
let localConnection;
12-
let remoteConnection;
11+
let pc1;
12+
let pc2;
1313
let sendChannel;
1414
let receiveChannel;
1515
const dataChannelSend = document.querySelector('textarea#dataChannelSend');
@@ -33,27 +33,27 @@ function disableSendButton() {
3333
function createConnection() {
3434
dataChannelSend.placeholder = '';
3535
const servers = null;
36-
window.localConnection = localConnection = new RTCPeerConnection(servers);
37-
console.log('Created local peer connection object localConnection');
36+
pc1 = new RTCPeerConnection(servers);
37+
console.log('Created local peer connection object pc1');
3838

39-
sendChannel = localConnection.createDataChannel('sendDataChannel');
39+
sendChannel = pc1.createDataChannel('sendDataChannel');
4040
console.log('Created send data channel');
4141

42-
localConnection.onicecandidate = e => {
43-
onIceCandidate(localConnection, e);
42+
pc1.onicecandidate = e => {
43+
onIceCandidate(pc1, e);
4444
};
4545
sendChannel.onopen = onSendChannelStateChange;
4646
sendChannel.onclose = onSendChannelStateChange;
4747

48-
window.remoteConnection = remoteConnection = new RTCPeerConnection(servers);
49-
console.log('Created remote peer connection object remoteConnection');
48+
pc2 = new RTCPeerConnection(servers);
49+
console.log('Created remote peer connection object pc2');
5050

51-
remoteConnection.onicecandidate = e => {
52-
onIceCandidate(remoteConnection, e);
51+
pc2.onicecandidate = e => {
52+
onIceCandidate(pc2, e);
5353
};
54-
remoteConnection.ondatachannel = receiveChannelCallback;
54+
pc2.ondatachannel = receiveChannelCallback;
5555

56-
localConnection.createOffer().then(
56+
pc1.createOffer().then(
5757
gotDescription1,
5858
onCreateSessionDescriptionError
5959
);
@@ -77,10 +77,10 @@ function closeDataChannels() {
7777
console.log('Closed data channel with label: ' + sendChannel.label);
7878
receiveChannel.close();
7979
console.log('Closed data channel with label: ' + receiveChannel.label);
80-
localConnection.close();
81-
remoteConnection.close();
82-
localConnection = null;
83-
remoteConnection = null;
80+
pc1.close();
81+
pc2.close();
82+
pc1 = null;
83+
pc2 = null;
8484
console.log('Closed peer connections');
8585
startButton.disabled = false;
8686
sendButton.disabled = true;
@@ -93,27 +93,27 @@ function closeDataChannels() {
9393
}
9494

9595
function gotDescription1(desc) {
96-
localConnection.setLocalDescription(desc);
97-
console.log(`Offer from localConnection\n${desc.sdp}`);
98-
remoteConnection.setRemoteDescription(desc);
99-
remoteConnection.createAnswer().then(
96+
pc1.setLocalDescription(desc);
97+
console.log(`Offer from pc1\n${desc.sdp}`);
98+
pc2.setRemoteDescription(desc);
99+
pc2.createAnswer().then(
100100
gotDescription2,
101101
onCreateSessionDescriptionError
102102
);
103103
}
104104

105105
function gotDescription2(desc) {
106-
remoteConnection.setLocalDescription(desc);
107-
console.log(`Answer from remoteConnection\n${desc.sdp}`);
108-
localConnection.setRemoteDescription(desc);
106+
pc2.setLocalDescription(desc);
107+
console.log(`Answer from pc2\n${desc.sdp}`);
108+
pc1.setRemoteDescription(desc);
109109
}
110110

111111
function getOtherPc(pc) {
112-
return (pc === localConnection) ? remoteConnection : localConnection;
112+
return (pc === pc1) ? pc2 : pc1;
113113
}
114114

115115
function getName(pc) {
116-
return (pc === localConnection) ? 'localPeerConnection' : 'remotePeerConnection';
116+
return (pc === pc1) ? 'pc1' : 'pc2';
117117
}
118118

119119
function onIceCandidate(pc, event) {

src/content/datachannel/basic/js/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ describe('datachannel basic', () => {
3030

3131
await Promise.all([
3232
driver.wait(() => driver.executeScript(() => {
33-
return localConnection && localConnection.connectionState === 'connected'; // eslint-disable-line no-undef
33+
return pc1 && pc1.connectionState === 'connected'; // eslint-disable-line no-undef
3434
})),
3535
await driver.wait(() => driver.executeScript(() => {
36-
return remoteConnection && remoteConnection.connectionState === 'connected'; // eslint-disable-line no-undef
36+
return pc2 && pc2.connectionState === 'connected'; // eslint-disable-line no-undef
3737
})),
3838
]);
3939
await driver.wait(() => driver.findElement(webdriver.By.id('sendButton')).isEnabled());

src/content/datachannel/datatransfer/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h1><a href="https://webrtc.github.io/samples/" title="WebRTC samples homepage">
7777
<section>
7878
<p>View the console to see logging.</p>
7979

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

8383
<p>For more information about RTCDataChannel, see <a

src/content/datachannel/datatransfer/js/main.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
'use strict';
1010
const MAX_CHUNK_SIZE = 262144;
1111

12-
let localConnection;
13-
let remoteConnection;
12+
let pc1;
13+
let pc2;
1414
let sendChannel;
1515
let receiveChannel;
1616
let chunkSize;
@@ -61,28 +61,28 @@ async function createConnection() {
6161
const number = Number.parseInt(megsToSend.value);
6262
bytesToSend = number * 1024 * 1024;
6363

64-
localConnection = new RTCPeerConnection(servers);
64+
pc1 = new RTCPeerConnection(servers);
6565

6666
// Let's make a data channel!
6767
const dataChannelParams = {ordered: false};
6868
if (orderedCheckbox.checked) {
6969
dataChannelParams.ordered = true;
7070
}
71-
sendChannel = localConnection.createDataChannel('sendDataChannel', dataChannelParams);
71+
sendChannel = pc1.createDataChannel('sendDataChannel', dataChannelParams);
7272
sendChannel.addEventListener('open', onSendChannelOpen);
7373
sendChannel.addEventListener('close', onSendChannelClosed);
7474
console.log('Created send data channel: ', sendChannel);
7575

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

78-
localConnection.addEventListener('icecandidate', e => onIceCandidate(localConnection, e));
78+
pc1.addEventListener('icecandidate', e => onIceCandidate(pc1, e));
7979

80-
remoteConnection = new RTCPeerConnection(servers);
81-
remoteConnection.addEventListener('icecandidate', e => onIceCandidate(remoteConnection, e));
82-
remoteConnection.addEventListener('datachannel', receiveChannelCallback);
80+
pc2 = new RTCPeerConnection(servers);
81+
pc2.addEventListener('icecandidate', e => onIceCandidate(pc2, e));
82+
pc2.addEventListener('datachannel', receiveChannelCallback);
8383

8484
try {
85-
const localOffer = await localConnection.createOffer();
85+
const localOffer = await pc1.createOffer();
8686
await handleLocalDescription(localOffer);
8787
} catch (e) {
8888
console.error('Failed to create session description: ', e);
@@ -143,32 +143,32 @@ function startSendingData() {
143143
}
144144

145145
function maybeReset() {
146-
if (localConnection === null && remoteConnection === null) {
146+
if (pc1 === null && pc2 === null) {
147147
sendButton.disabled = false;
148148
megsToSend.disabled = false;
149149
}
150150
}
151151

152152
async function handleLocalDescription(desc) {
153-
localConnection.setLocalDescription(desc);
154-
console.log('Offer from localConnection:\n', desc.sdp);
155-
remoteConnection.setRemoteDescription(desc);
153+
pc1.setLocalDescription(desc);
154+
console.log('Offer from pc1:\n', desc.sdp);
155+
pc2.setRemoteDescription(desc);
156156
try {
157-
const remoteAnswer = await remoteConnection.createAnswer();
157+
const remoteAnswer = await pc2.createAnswer();
158158
handleRemoteAnswer(remoteAnswer);
159159
} catch (e) {
160160
console.error('Error when creating remote answer: ', e);
161161
}
162162
}
163163

164164
function handleRemoteAnswer(desc) {
165-
remoteConnection.setLocalDescription(desc);
166-
console.log('Answer from remoteConnection:\n', desc.sdp);
167-
localConnection.setRemoteDescription(desc);
165+
pc2.setLocalDescription(desc);
166+
console.log('Answer from pc2:\n', desc.sdp);
167+
pc1.setRemoteDescription(desc);
168168
}
169169

170170
function getOtherPc(pc) {
171-
return (pc === localConnection) ? remoteConnection : localConnection;
171+
return (pc === pc1) ? pc2 : pc1;
172172
}
173173

174174
async function onIceCandidate(pc, event) {
@@ -209,7 +209,7 @@ function onReceiveMessageCallback(event) {
209209
function onSendChannelOpen() {
210210
console.log('Send channel is open');
211211

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

228228
function onSendChannelClosed() {
229229
console.log('Send channel is closed');
230-
localConnection.close();
231-
localConnection = null;
230+
pc1.close();
231+
pc1 = null;
232232
console.log('Closed local peer connection');
233233
maybeReset();
234234
console.log('Average time spent in send() (ms): ' +
@@ -241,8 +241,8 @@ function onSendChannelClosed() {
241241

242242
function onReceiveChannelClosed() {
243243
console.log('Receive channel is closed');
244-
remoteConnection.close();
245-
remoteConnection = null;
244+
pc2.close();
245+
pc2 = null;
246246
console.log('Closed remote peer connection');
247247
maybeReset();
248248
}

src/content/datachannel/datatransfer/js/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ describe('datachannel datatransfer', () => {
3838

3939
await Promise.all([
4040
driver.wait(() => driver.executeScript(() => {
41-
return localConnection && localConnection.connectionState === 'connected'; // eslint-disable-line no-undef
41+
return pc1 && pc1.connectionState === 'connected'; // eslint-disable-line no-undef
4242
})),
4343
await driver.wait(() => driver.executeScript(() => {
44-
return remoteConnection && remoteConnection.connectionState === 'connected'; // eslint-disable-line no-undef
44+
return pc2 && pc2.connectionState === 'connected'; // eslint-disable-line no-undef
4545
})),
4646
]);
4747

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

5353
const transferred = await driver.findElement(webdriver.By.id('receiveProgress')).getAttribute('value');

src/content/datachannel/filetransfer/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h1><a href="https://webrtc.github.io/samples/" title="WebRTC samples homepage">
7676
<section>
7777
<p>View the console to see logging.</p>
7878

79-
<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>
79+
<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>
8080

8181
<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>
8282
</section>

0 commit comments

Comments
 (0)