Skip to content

Integrate Socket Stream with Socket.IO #2228

Answered by Romakita
LefanTan asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @LefanTan
Actually, you can use that manually, by using the $onConnection hook:

@SocketService("/room")
@SocketUseBefore(AuthSocketMiddleware)
@SocketUseAfter(ErrorHandlerSocketMiddleware)
export class RoomWS {
  // tslint:disable-next-line: no-unused-variable
  constructor(@IO private io: Server) {}

  $onConnection(socket: IOSocket, nsp: Namespace) {
    ss(socket).on('profile-image', this.handleStream.bind(this));
  }
  
  handleStream(stream, data) {
      var filename = path.basename(data.name);
      stream.pipe(fs.createWriteStream(filename));
  }
}

See you
Romain

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by LefanTan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants