1
1
class WebConnection extends EventTarget {
2
2
/** @type {RTCPeerConnection } */
3
- #local ;
3
+ #pc ;
4
4
/** @type {RTCDataChannel } */
5
5
#dataChannel;
6
6
/** @type {MediaStream } */
@@ -25,7 +25,7 @@ class WebConnection extends EventTarget {
25
25
this . #isHost = asHost ;
26
26
27
27
const rtc = RTCPeerConnection ?? webkitRTCPeerConnection ;
28
- this . #local = new rtc ( webRTCConfig , webRTCConnection ) ;
28
+ this . #pc = new rtc ( webRTCConfig , webRTCConnection ) ;
29
29
30
30
// Host will select a window to share
31
31
if ( this . #isHost) {
@@ -37,12 +37,12 @@ class WebConnection extends EventTarget {
37
37
} ) ;
38
38
39
39
for ( const track of this . #stream. getTracks ( ) ) {
40
- this . #local . addTrack ( track , this . #stream) ;
40
+ this . #pc . addTrack ( track , this . #stream) ;
41
41
}
42
42
}
43
43
44
44
// Forward any ice candidates to the server
45
- this . #local . onicecandidate = ( e ) => {
45
+ this . #pc . onicecandidate = ( e ) => {
46
46
if ( ! e || ! e . candidate ) {
47
47
return ;
48
48
}
@@ -52,7 +52,7 @@ class WebConnection extends EventTarget {
52
52
}
53
53
54
54
// Add tracks to the local video element
55
- this . #local . ontrack = ( e ) => {
55
+ this . #pc . ontrack = ( e ) => {
56
56
this . #log( "track!" ) ;
57
57
this . #stream = new MediaStream ( ) ;
58
58
this . #stream. addTrack ( e . track ) ;
@@ -74,34 +74,34 @@ class WebConnection extends EventTarget {
74
74
offerToReceiveAudio : false ,
75
75
offerToReceiveVideo : true
76
76
} ;
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 ) ;
79
79
this . #sendToWebSocket( "offer" , sdp ) ;
80
80
}
81
81
82
82
async onOffer ( from , offer ) {
83
83
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 ) ;
87
87
this . #sendToWebSocket( "answer" , sdp ) ;
88
88
}
89
89
90
90
async onIceCandidate ( from , candidate ) {
91
91
this . #log( "onIceCandidate" ) ;
92
- await this . #local . addIceCandidate ( new RTCIceCandidate ( candidate ) ) ;
92
+ await this . #pc . addIceCandidate ( new RTCIceCandidate ( candidate ) ) ;
93
93
}
94
94
95
95
async onAnswer ( from , answer ) {
96
96
this . #log( "onAnswer" ) ;
97
- await this . #local . setRemoteDescription ( new RTCSessionDescription ( answer ) ) ;
97
+ await this . #pc . setRemoteDescription ( new RTCSessionDescription ( answer ) ) ;
98
98
}
99
99
100
100
#createDataChannelForCanvas( ) {
101
101
// Only the host uses the datachannel right now
102
102
if ( this . #isHost) {
103
103
// Listen for data sent from the client
104
- this . #local . ondatachannel = ( e ) => {
104
+ this . #pc . ondatachannel = ( e ) => {
105
105
e . channel . onmessage = ( e ) => {
106
106
// Display any canvas data on the host screen
107
107
this . display ( e ) ;
@@ -110,7 +110,7 @@ class WebConnection extends EventTarget {
110
110
}
111
111
112
112
// Create and open the channel
113
- this . #dataChannel = this . #local . createDataChannel ( "datachannel" , { reliable : true } ) ;
113
+ this . #dataChannel = this . #pc . createDataChannel ( "datachannel" , { reliable : true } ) ;
114
114
115
115
// Only the host actually listens for the datachannel
116
116
if ( this . #isHost) {
0 commit comments