@@ -134,13 +134,13 @@ export default class WSSignaling {
134
134
let newOffer = new Offer ( message . sdp , Date . now ( ) , false ) ;
135
135
136
136
if ( this . isPrivate ) {
137
- const pair = connectionPair . get ( connectionId ) ;
138
- const otherSessionWs = pair [ 0 ] == ws ? pair [ 1 ] : pair [ 0 ] ;
139
- if ( otherSessionWs ) {
140
- newOffer . polite = true ;
141
- otherSessionWs . send ( JSON . stringify ( { from : connectionId , to : "" , type : "offer" , data : newOffer } ) ) ;
142
- } else {
143
- ws . send ( JSON . stringify ( { type : "error" , message : ` ${ connectionId } : This connection id is not ready other session.` } ) ) ;
137
+ if ( connectionPair . has ( connectionId ) ) {
138
+ const pair = connectionPair . get ( connectionId ) ;
139
+ const otherSessionWs = pair [ 0 ] == ws ? pair [ 1 ] : pair [ 0 ] ;
140
+ if ( otherSessionWs ) {
141
+ newOffer . polite = true ;
142
+ otherSessionWs . send ( JSON . stringify ( { from : connectionId , to : "" , type : "offer" , data : newOffer } ) ) ;
143
+ }
144
144
}
145
145
return ;
146
146
}
@@ -160,39 +160,31 @@ export default class WSSignaling {
160
160
connectionIds . add ( connectionId ) ;
161
161
const newAnswer = new Answer ( message . sdp , Date . now ( ) ) ;
162
162
163
- let otherSessionWs = null ;
164
-
165
- if ( this . isPrivate ) {
166
- const pair = connectionPair . get ( connectionId ) ;
167
- otherSessionWs = pair [ 0 ] == ws ? pair [ 1 ] : pair [ 0 ] ;
168
- } else {
169
- const pair = connectionPair . get ( connectionId ) ;
170
- otherSessionWs = pair [ 0 ] ;
171
- connectionPair . set ( connectionId , [ otherSessionWs , ws ] ) ;
163
+ if ( ! connectionPair . has ( connectionId ) ) {
164
+ return ;
172
165
}
173
166
174
- if ( this . isPrivate ) {
175
- otherSessionWs . send ( JSON . stringify ( { from : connectionId , to : "" , type : "answer" , data : newAnswer } ) ) ;
176
- return ;
167
+ const pair = connectionPair . get ( connectionId ) ;
168
+ const otherSessionWs = pair [ 0 ] == ws ? pair [ 1 ] : pair [ 0 ] ;
169
+
170
+ if ( ! this . isPrivate ) {
171
+ connectionPair . set ( connectionId , [ otherSessionWs , ws ] ) ;
177
172
}
178
173
179
- clients . forEach ( ( _v , k ) => {
180
- if ( k == ws ) {
181
- return ;
182
- }
183
- k . send ( JSON . stringify ( { from : connectionId , to : "" , type : "answer" , data : newAnswer } ) ) ;
184
- } ) ;
174
+ otherSessionWs . send ( JSON . stringify ( { from : connectionId , to : "" , type : "answer" , data : newAnswer } ) ) ;
185
175
}
186
176
187
177
private onCandidate ( ws : WebSocket , message : any ) {
188
178
const connectionId = message . connectionId ;
189
179
const candidate = new Candidate ( message . candidate , message . sdpMLineIndex , message . sdpMid , Date . now ( ) ) ;
190
180
191
181
if ( this . isPrivate ) {
192
- const pair = connectionPair . get ( connectionId ) ;
193
- const otherSessionWs = pair [ 0 ] == ws ? pair [ 1 ] : pair [ 0 ] ;
194
- if ( otherSessionWs ) {
195
- otherSessionWs . send ( JSON . stringify ( { from : connectionId , to : "" , type : "candidate" , data : candidate } ) ) ;
182
+ if ( connectionPair . has ( connectionId ) ) {
183
+ const pair = connectionPair . get ( connectionId ) ;
184
+ const otherSessionWs = pair [ 0 ] == ws ? pair [ 1 ] : pair [ 0 ] ;
185
+ if ( otherSessionWs ) {
186
+ otherSessionWs . send ( JSON . stringify ( { from : connectionId , to : "" , type : "candidate" , data : candidate } ) ) ;
187
+ }
196
188
}
197
189
return ;
198
190
}
0 commit comments