phoboslab / jsmpeg

MPEG1 Video Decoder in JavaScript
MIT License
6.35k stars 1.43k forks source link

How to build my own Websocket source/socket file? #357

Open mzyax opened 3 years ago

mzyax commented 3 years ago

I am trying to send multiple streams to a single WebSocket and trying to find a way to 'categorize" each stream in the socket transfer. I sort of found an answer to my question with issue #338 .

However, I'm lost with this proper way of setting this up.

This is my method for starting a stream here via server:

  startStream(cam) {
    const wss = new WebSocket.Server({ port: cam.port });
    this.child = child_process.spawn("ffmpeg", this.setOptions(cam.url));
    this.child.stdout.on("data", (data) => {
      wss.clients.forEach((client) => {
        client.send(data);
      });
      return this.emit("data", data);
    });
  }

I'd like to only use one port (using multiple ports is the only way I have this working right now) and send an object, for example:

[{ "id": "ddw3wqer1", data: "..." }, { "id": "dqfw3wqer1", data: "..." }]

How can I send obj.data to jsmpeg? An example would really be helpful, thank you!