@@ -53,7 +53,6 @@ class WebConnection extends EventTarget {
53
53
54
54
// Add tracks to the local video element
55
55
this . #pc. ontrack = ( e ) => {
56
- this . #log( "track!" ) ;
57
56
this . #stream = new MediaStream ( ) ;
58
57
this . #stream. addTrack ( e . track ) ;
59
58
@@ -69,31 +68,32 @@ class WebConnection extends EventTarget {
69
68
// Note: We don't actually do this anymore
70
69
// this.#createDataChannelForCanvas();
71
70
72
- // Offer the connection
73
- const sdpConstraints = {
74
- offerToReceiveAudio : false ,
75
- offerToReceiveVideo : true
76
- } ;
77
- const sdp = await this . #pc. createOffer ( sdpConstraints ) ;
78
- await this . #pc. setLocalDescription ( sdp ) ;
79
- this . #sendToWebSocket( "offer" , sdp ) ;
71
+ // Offer the connection as a host
72
+ // A client joining will just recieve the offer via the cache in the server
73
+ // TODO: Support multiple clients
74
+ if ( this . #isHost) {
75
+ const sdpConstraints = {
76
+ offerToReceiveAudio : false ,
77
+ offerToReceiveVideo : true
78
+ } ;
79
+ const sdp = await this . #pc. createOffer ( sdpConstraints ) ;
80
+ await this . #pc. setLocalDescription ( sdp ) ;
81
+ this . #sendToWebSocket( "offer" , sdp ) ;
82
+ }
80
83
}
81
84
82
85
async onOffer ( from , offer ) {
83
- this . #log( "onOffer" ) ;
84
86
await this . #pc. setRemoteDescription ( new RTCSessionDescription ( offer ) ) ;
85
87
const sdp = await this . #pc. createAnswer ( ) ;
86
88
await this . #pc. setLocalDescription ( sdp ) ;
87
89
this . #sendToWebSocket( "answer" , sdp ) ;
88
90
}
89
91
90
92
async onIceCandidate ( from , candidate ) {
91
- this . #log( "onIceCandidate" ) ;
92
93
await this . #pc. addIceCandidate ( new RTCIceCandidate ( candidate ) ) ;
93
94
}
94
95
95
96
async onAnswer ( from , answer ) {
96
- this . #log( "onAnswer" ) ;
97
97
await this . #pc. setRemoteDescription ( new RTCSessionDescription ( answer ) ) ;
98
98
}
99
99
0 commit comments