@@ -211,21 +211,32 @@ export class EchoServer {
211211 this . server . io . on ( 'connection' , socket => {
212212 this . channel . joinRoot ( socket ) //Auth Root Channel '/'
213213 . then ( auth => {
214- if ( auth === false )
215- return IoUtils . disconnect (
216- socket ,
217- this . log ,
218- 'Laravel Auth Failed for user id:' + auth . channel_data . user_id ,
219- ) ;
214+ if ( auth === false ) {
215+ const msg = `Auth: Failed for user:${ auth . channel_data . user_id } , channel:root` ;
216+ return IoUtils . disconnect ( socket , this . log , msg ) ;
217+ }
218+
219+ if ( ! auth . hasOwnProperty ( 'channel_data' ) ) {
220+ let msg_err = 'Error: on Connect Echo-Server response' ;
221+ msg_err += ' do not have channel_data property' ;
222+ this . log . error ( msg_err ) ;
223+ Log . error ( msg_err ) ;
224+
225+ return IoUtils . disconnect ( socket , this . log , msg_err ) ;
226+ } else if ( ! auth . channel_data . hasOwnProperty ( 'user_id' ) ) {
227+ let msg_err = 'Error: on Connect Echo-Server response' ;
228+ msg_err += ' do not have channel_data.user_id property' ;
229+ this . log . error ( msg_err ) ;
230+ Log . error ( msg_err ) ;
231+
232+ return IoUtils . disconnect ( socket , this . log , msg_err ) ;
233+ }
220234
221- //console.log(socket.adapter.nsp.sockets)
222235 socket . user_id = auth . channel_data . user_id ;
223236 const ip = IoUtils . getIp ( socket , this . options ) ;
224237
225238 Log . success ( `LOG Success on Server: ${ this . server . getServerId ( ) } ` ) ;
226- //IoUtils.setActiveUserOnServer(this.server.getServerId(),
227- // {user_id: auth.channel_data.user_id, socket_id: socket.id})
228- // collection echo_users, {user_id:1, socket_id:2ff, server_id: foo1 })
239+
229240 this . db . setUserInServer ( 'echo_users' , {
230241 user_id : auth . channel_data . user_id ,
231242 socket_id : socket . id ,
@@ -250,17 +261,24 @@ export class EchoServer {
250261 IoUtils . getAllActiveSocketsInThisIoServer ( this . server . io )
251262 ) ;
252263
253- Log . success ( `AUTH Success ON NSP / User Id:${ socket . user_id } SocketID: ${ socket . id } with IP:${ ip } ` ) ;
254- this . log . info ( `Auth Success ON NSP / User Id:${ socket . user_id } with Socket:${ socket . id } with IP:${ ip } ` ) ;
264+ const msg_sucess = [
265+ `Auth Success ON NSP /` ,
266+ `User Id:${ socket . user_id } ` ,
267+ `with Socket:${ socket . id } with IP:${ ip } `
268+ ] . join ( ' ' ) ;
269+
270+ Log . success ( msg_sucess ) ;
271+ this . log . info ( msg_sucess ) ;
272+
255273 return this . startSubscribers ( socket ) ;
256274
257275 } )
258276 . catch ( e => {
259- Log . error ( ` Socket:${ socket . id } join Root Auth Error, reason:${ e . reason } `) ;
260- this . log
261- . error ( `Socket: ${ socket . id } join Root Auth Error, reason: ${ e . reason } ` ) ;
277+ const msg_error = `Auth: Socket:${ socket . id } join Root Auth Error, reason:${ e . reason } `
278+ Log . error ( msg_error ) ;
279+ this . log . error ( msg_error ) ;
262280
263- IoUtils . disconnect ( socket , this . log , e . reason )
281+ IoUtils . disconnect ( socket , this . log , msg_error )
264282 } )
265283 } ) ;
266284 }
0 commit comments