app/ws/RadioTower.js
// Join a "chat room". See description above on how a room is defined.
Join a "chat room". See description above on how a room is defined.
Join a " chat room " . See description above on how a room is defined .
join( message, raw, senderClientId ) {
      winston.debug( ` ➕ join request from ${senderClientId} in ${process.pid}` )
      let client = ClientStore.clients.find( cl => cl.clientId === senderClientId )
      if ( !client ) { return winston.debug( `No client with id ${senderClientId} found in pid ${process.pid} (this is fine, it might be on another pid).` ) }
      if ( message.streamId && message.streamId.trim( ) !== '' ) {
        let roomName = `stream-${message.streamId}`
        DataStream.findOne( { streamId: message.streamId }, 'private canRead canWrite owner' ).lean( )
          .then( stream => {
            if ( !stream.private ) return true
            if ( !client.user._id || client.user._id === '' ) throw new Error( 'oups' )
            return PermissionCheck( { _id: client.user._id }, 'read', stream )
          } )
          .then( ( ) => {
            winston.debug( `Client ws joined ${roomName}` )
            if ( client.rooms.indexOf( roomName ) === -1 ) { client.rooms.push( roomName ) } else { client.send( 'You already joined that room.' ) }
          } )
          .catch( err => {
            winston.error( 'got an error on join: ' + err.message )
            client.send( `Failed to join room ${roomName}` )
            return winston.debug( `Error: ${err.toString()})` )
          } )
      } else if ( message.resourceId && message.resourceId.trim( ) !== '' && message.resourceType && message.resourceId.trim( ) !== '' ) {
        GetResourceByType( message.resourceType, message.resourceId )
          .then( resource => {
            if ( !resource.private ) return true
            if ( resource.private && client.authorised )
              return PermissionCheck( { _id: client.user._id }, 'read', resource )
            else {
              client.send( 'You are an anonymous client. You cannot access this resource.' )
              throw new Error( 'Anonymous room join for private resource.' )
            }
          } )
          .then( ( ) => {
            if ( client.rooms.indexOf( `${message.resourceType}-${message.resourceId}` ) === -1 ) {
              winston.debug( `${client.clientId} joined room ${message.resourceType}-${message.resourceId}.` )
              client.rooms.push( `${message.resourceType}-${message.resourceId}` )
              client.send( JSON.stringify( { message: 'Room joined.', roomName: `${message.resourceType}-${message.resourceId}` } ) )
            } else {
              client.send( 'You already joined that room.' )
            }
          } )
          .catch( err => {
            client.send( err.message )
            winston.error( `WS join room: ` + err.message )
          } )
      }
    }
join ( message , raw , senderClientId ) { winston . debug ( ` se nderClientId}  i pr ocess.p i d}` ) let client = ClientStore . clients . find ( cl => cl . clientId === senderClientId ) if ( ! client ) { return winston . debug ( ` ${ senderClientId } ${ process . pid } ` ) } if ( message . streamId && message . streamId . trim ( ) !== '' ) { let roomName = ` ${ message . streamId } ` DataStream . findOne ( { streamId : message . streamId } , 'private canRead canWrite owner' ) . lean ( ) . then ( stream => { if ( ! stream . private ) return true if ( ! client . user . _id || client . user . _id === '' ) throw new Error ( 'oups' ) return PermissionCheck ( { _id : client . user . _id } , 'read' , stream ) } ) . then ( ( ) => { winston . debug ( ` ${ roomName } ` ) if ( client . rooms . indexOf ( roomName ) === - 1 ) { client . rooms . push ( roomName ) } else { client . send ( 'You already joined that room.' ) } } ) . catch ( err => { winston . error ( 'got an error on join: ' + err . message ) client . send ( ` ${ roomName } ` ) return winston . debug ( ` ${ err . toString ( ) } ` ) } ) } else if ( message . resourceId && message . resourceId . trim ( ) !== '' && message . resourceType && message . resourceId . trim ( ) !== '' ) { GetResourceByType ( message . resourceType , message . resourceId ) . then ( resource => { if ( ! resource . private ) return true if ( resource . private && client . authorised ) return PermissionCheck ( { _id : client . user . _id } , 'read' , resource ) else { client . send ( 'You are an anonymous client. You cannot access this resource.' ) throw new Error ( 'Anonymous room join for private resource.' ) } } ) . then ( ( ) => { if ( client . rooms . indexOf ( ` ${ message . resourceType } ${ message . resourceId } ` ) === - 1 ) { winston . debug ( ` ${ client . clientId } ${ message . resourceType } ${ message . resourceId } ` ) client . rooms . push ( ` ${ message . resourceType } ${ message . resourceId } ` ) client . send ( JSON . stringify ( { message : 'Room joined.' , roomName : ` ${ message . resourceType } ${ message . resourceId } ` } ) ) } else { client . send ( 'You already joined that room.' ) } } ) . catch ( err => { client . send ( err . message ) winston . error ( ` ` + err . message ) } ) } }
Join a "chat room".
Join a " chat room " .
// If a streamId argument is present, join that specific streamId room proper // This is for backwards compatibility, as the .NET clients implement this as such // In the future, all should switch to the "else" part below