@@ -66,8 +66,9 @@ export default class CallHandler {
6666 data : peers ,
6767 } ;
6868
69+ let _send = this . _send ;
6970 this . clients . forEach ( function ( client ) {
70- client . send ( JSON . stringify ( msg ) ) ;
71+ _send ( client , JSON . stringify ( msg ) ) ;
7172 } ) ;
7273 }
7374
@@ -89,16 +90,20 @@ export default class CallHandler {
8990 data : client_self . id ,
9091 } ;
9192
93+ let _send = this . _send ;
9294 this . clients . forEach ( function ( client ) {
9395 if ( client != client_self )
94- client . send ( JSON . stringify ( msg ) ) ;
96+ _send ( client , JSON . stringify ( msg ) ) ;
9597 } ) ;
9698
9799 this . updatePeers ( ) ;
98100 }
99101
100102 onConnection = ( client_self , socket ) => {
101103 console . log ( 'connection' ) ;
104+
105+ let _send = this . _send ;
106+
102107 this . clients . add ( client_self ) ;
103108
104109 client_self . on ( "close" , ( data ) => {
@@ -139,7 +144,7 @@ export default class CallHandler {
139144 error : "Invalid session " + message . session_id ,
140145 } ,
141146 } ;
142- client_self . send ( JSON . stringify ( msg ) ) ;
147+ _send ( client_self , JSON . stringify ( msg ) ) ;
143148 return ;
144149 }
145150
@@ -155,7 +160,7 @@ export default class CallHandler {
155160 to : ( client . id == session . from ? session . to : session . from ) ,
156161 } ,
157162 } ;
158- client . send ( JSON . stringify ( msg ) ) ;
163+ _send ( client , JSON . stringify ( msg ) ) ;
159164 } catch ( e ) {
160165 console . log ( "onUserJoin:" + e . message ) ;
161166 }
@@ -184,8 +189,8 @@ export default class CallHandler {
184189 description : message . description ,
185190 }
186191 }
187- peer . send ( JSON . stringify ( msg ) ) ;
188-
192+ _send ( peer , JSON . stringify ( msg ) ) ;
193+
189194 peer . session_id = message . session_id ;
190195 client_self . session_id = message . session_id ;
191196
@@ -213,7 +218,7 @@ export default class CallHandler {
213218 this . clients . forEach ( function ( client ) {
214219 if ( client . id === "" + message . to && client . session_id === message . session_id ) {
215220 try {
216- client . send ( JSON . stringify ( msg ) ) ;
221+ _send ( client , JSON . stringify ( msg ) ) ;
217222 } catch ( e ) {
218223 console . log ( "onUserJoin:" + e . message ) ;
219224 }
@@ -235,7 +240,7 @@ export default class CallHandler {
235240 this . clients . forEach ( function ( client ) {
236241 if ( client . id === "" + message . to && client . session_id === message . session_id ) {
237242 try {
238- client . send ( JSON . stringify ( msg ) ) ;
243+ _send ( client , JSON . stringify ( msg ) ) ;
239244 } catch ( e ) {
240245 console . log ( "onUserJoin:" + e . message ) ;
241246 }
@@ -244,13 +249,21 @@ export default class CallHandler {
244249 }
245250 break ;
246251 case 'keepalive' :
247- client_self . send ( JSON . stringify ( { type :'keepalive' , data :{ } } ) ) ;
252+ _send ( client_self , JSON . stringify ( { type :'keepalive' , data :{ } } ) ) ;
248253 break ;
249254 default :
250255 console . log ( "Unhandled message: " + message . type ) ;
251256 }
252257 } ) ;
253258 }
259+
260+ _send = ( client , message ) => {
261+ try {
262+ client . send ( message ) ;
263+ } catch ( e ) {
264+ console . e ( "Send failure !: " + e ) ;
265+ }
266+ }
254267}
255268
256269let callHandler = new CallHandler ( ) ;
0 commit comments