Skip to content

Commit f5b0e54

Browse files
Rename peerConnection
1 parent 76f5063 commit f5b0e54

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/public/scripts/webConnection.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class WebConnection extends EventTarget {
22
/** @type {RTCPeerConnection} */
3-
#local;
3+
#pc;
44
/** @type {RTCDataChannel} */
55
#dataChannel;
66
/** @type {MediaStream} */
@@ -25,7 +25,7 @@ class WebConnection extends EventTarget {
2525
this.#isHost = asHost;
2626

2727
const rtc = RTCPeerConnection ?? webkitRTCPeerConnection;
28-
this.#local = new rtc(webRTCConfig, webRTCConnection);
28+
this.#pc = new rtc(webRTCConfig, webRTCConnection);
2929

3030
// Host will select a window to share
3131
if (this.#isHost) {
@@ -37,12 +37,12 @@ class WebConnection extends EventTarget {
3737
});
3838

3939
for (const track of this.#stream.getTracks()) {
40-
this.#local.addTrack(track, this.#stream);
40+
this.#pc.addTrack(track, this.#stream);
4141
}
4242
}
4343

4444
// Forward any ice candidates to the server
45-
this.#local.onicecandidate = (e) => {
45+
this.#pc.onicecandidate = (e) => {
4646
if (!e || !e.candidate) {
4747
return;
4848
}
@@ -52,7 +52,7 @@ class WebConnection extends EventTarget {
5252
}
5353

5454
// Add tracks to the local video element
55-
this.#local.ontrack = (e) => {
55+
this.#pc.ontrack = (e) => {
5656
this.#log("track!");
5757
this.#stream = new MediaStream();
5858
this.#stream.addTrack(e.track);
@@ -74,34 +74,34 @@ class WebConnection extends EventTarget {
7474
offerToReceiveAudio: false,
7575
offerToReceiveVideo: true
7676
};
77-
const sdp = await this.#local.createOffer(sdpConstraints);
78-
await this.#local.setLocalDescription(sdp);
77+
const sdp = await this.#pc.createOffer(sdpConstraints);
78+
await this.#pc.setLocalDescription(sdp);
7979
this.#sendToWebSocket("offer", sdp);
8080
}
8181

8282
async onOffer(from, offer) {
8383
this.#log("onOffer");
84-
await this.#local.setRemoteDescription(new RTCSessionDescription(offer));
85-
const sdp = await this.#local.createAnswer();
86-
await this.#local.setLocalDescription(sdp);
84+
await this.#pc.setRemoteDescription(new RTCSessionDescription(offer));
85+
const sdp = await this.#pc.createAnswer();
86+
await this.#pc.setLocalDescription(sdp);
8787
this.#sendToWebSocket("answer", sdp);
8888
}
8989

9090
async onIceCandidate(from, candidate) {
9191
this.#log("onIceCandidate");
92-
await this.#local.addIceCandidate(new RTCIceCandidate(candidate));
92+
await this.#pc.addIceCandidate(new RTCIceCandidate(candidate));
9393
}
9494

9595
async onAnswer(from, answer) {
9696
this.#log("onAnswer");
97-
await this.#local.setRemoteDescription(new RTCSessionDescription(answer));
97+
await this.#pc.setRemoteDescription(new RTCSessionDescription(answer));
9898
}
9999

100100
#createDataChannelForCanvas() {
101101
// Only the host uses the datachannel right now
102102
if (this.#isHost) {
103103
// Listen for data sent from the client
104-
this.#local.ondatachannel = (e) => {
104+
this.#pc.ondatachannel = (e) => {
105105
e.channel.onmessage = (e) => {
106106
// Display any canvas data on the host screen
107107
this.display(e);
@@ -110,7 +110,7 @@ class WebConnection extends EventTarget {
110110
}
111111

112112
// Create and open the channel
113-
this.#dataChannel = this.#local.createDataChannel("datachannel", { reliable: true });
113+
this.#dataChannel = this.#pc.createDataChannel("datachannel", { reliable: true });
114114

115115
// Only the host actually listens for the datachannel
116116
if (this.#isHost) {

0 commit comments

Comments
 (0)