7
votes

I'm creating a relay server for my streaming app. Basically, it should work like this:

  1. Client A streams microphone audio to server through sockets
  2. Server a gets stream and maybe stores it somewhere temporarily?(not sure)
  3. Client B gets a stream from server and plays it.

Basically, I have 1st part done(sending mic audio to server):

while(isStreaming)
{
    minBufSize = recorder.read(buffer, 0, buffer.length);
    mSocket.emit("stream", Arrays.toString(buffer));
}

And 3rd part done, simply playing audio:

mediaplayer.reset();
mediaplayer.setDataSource("http://192.168.1.2:1337/stream");
mediaplayer.prepare();
mediaplayer.start();

Now I'm not sure how to bridge incoming byte array and streaming. Here is my current server code:

var ms = require('mediaserver');
// from server to Client B
exports.letsStream = function(req, res, next) {
    ms.pipe(req, res, "sample_song_music_file.mp3");
};

// from Client A to server
exports.handleSocketConnection = function(socket)
{
    console.log("connected");
    socket.on('stream', function(data)
    {
        var bytes = JSON.parse(data);
        console.log("GETTING STREAM:" + bytes);
    });
}

Any suggestions? How can I directly stream that byte array?

1
Hi, did you find the solution ? - Fayçal
@BackPacker nah, stopped looking for it long time ago. - Gintas_
Ok, thank you, I think I have to use webrtc or something like that - Fayçal
@BackPacker since you asked, did you find a solution? haha - George
@Gintas_ Did you manage to find a solution for this? I have the exact same scenario and I am struggling.. - msamhoury

1 Answers

0
votes

The mediaserver module only supports streaming an existing audio, rather than a "live" stream. This won't work.

One way to achieve the three tasks would be:

  1. https://www.npmjs.com/package/microphone to read the microphone audio as a byte stream.
  2. http://binaryjs.com/ to handle transmitting the byte stream over websockets to the server and then sending to the client. If you have two separate paths set up, one for sending the data, one for receiving. Send the data from one stream to the other.
  3. Use https://github.com/TooTallNate/node-speaker to play the incoming PCM data stream on Client B