socket.io-stream not exposing .to call - node.js

I'm building a camera streaming platform that uses navigator.getUserMedia. The clients seem to broadcast their video streams without error. The code (on clients) for doing so looks like this:
navigator.mediaDevices.getUserMedia({
audio: false, //We don't need audio at the moment
video: true
}).then(function(stream) {
ss(socket).emit("BroadcastStream", stream);
}).catch(err) {
//Code for handling error
});
However my Node.JS server handling the stream (and sending it to the other client) throws this error:
TypeError: socket_stream(...).to is not a function
It seems socket.io-stream isn't exposing the .to function. I know the argument to socket_stream (reference to the socket.io instance) is valid; and socket.io-stream's documentation seems to agree with this (there is no mention of .to)
How would I go around resolving this?
EDIT:
I am open to suggestions (even using a different method altogether; but leave that as a last resort)

Alright, nevermind (after a month later), I found A Dead Simple WebRTC Example which showed me the basics of using WebRTC (without STUN servers, which I kind of needed for this project), which I adapted to my specific needs. Great job to Shane Tully on that tutorial!

Related

capture video conference between 1:1 user and broadcast to an rtmp url

I am currently working on nodejs and socket app that is currently doing 1:1 video conference that is using webrtc. Videos are two separate element in the html and i would like to merge them together so that i can broadcast to rtmp url for public view (2:many). Is this possible
For webrtc, i followed this tutorial https://www.youtube.com/watch?v=DvlyzDZDEq4, and for broadcasting i am using ffmpeg which current does 1 video stream.
Please confirm if this is doable
Update
I was able to merge the video using
https://www.npmjs.com/package/video-stream-merger
And now the final issue
i am receiving merger.result which is merged stream and I tried to create a mediaRecorder object. Callback method for MediaRecorder ondataavailable is called only once but not every 250ms which i need to broadcast to youtube. How can i do this?
var merger = new VideoStreamMerger(v_opts);
...
...
merger.start()
myMediaRecorder = new MediaRecorder(merger.result);
myMediaRecorder.start(250);
myMediaRecorder.ondataavailable = function (e) {
console.log("DataAvailable")
//socket.emit("binarystream", e.data);
state = "start";
//chunks.push(e.data);
}
So you're looking for many peers. This is possible - please see the below links for reference.
WebRTC: https://webrtc.github.io/samples/src/content/peerconnection/multiple/
StackOverflow reference: webRTC multi-peer connection (3 clients and above)
GitHub reference: https://github.com/Dirvann/webrtc-video-conference-simple-peer
https://deepstream.io/tutorials/webrtc/webrtc-full-mesh/

Need help for audio conference using Kurento composite media element in Nodejs

I am refereeing the code from GitHub for audio AND video conference using Kurento composite media element, It work's fine for audio AND video streaming over WebRTC.
But I need only audio conference using WebRTC, I have added changes in above GitHub code and new code is uploaded on GitHub Repository.
I have added below changes in static/js/index.js file
var constraints = {
audio: true, video: false
};
var options = {
localVideo: undefined,
remoteVideo: video,
onicecandidate : onIceCandidate,
mediaConstraints: constraints
}
webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function(error) {
When I am running this code, no error for node server as well as on chrome console. But audio stream does not get start. It only showing spinner for long time. Chrome console log is here.
As per reply for my previous stack overflow question, We need to specify MediaType.AUDIO in java code like below
webrtc.connect(hubport, MediaType.AUDIO);
hubport.connect(webrtc, MediaType.AUDIO);
But I want to implementing it in Nodejs using kurento-client.js, I did not get any reference to set MediaType.AUDIO to connect with hubPort and webRtcEndpoint in Nodeja API.
Please someone can help me to do code changes for same in Nodejs or suggest me any reference so I can implement only audio conference using composite media element and Nodejs.
This should do
function connectOnlyAudio(source, sink, callback) {
source.connect(sink, "AUDIO" , function(error) {
if (error) {
return callback(error);
}
return callback(null);
});
}
We are in the process of improving the documentation of the project. I hope that this will all be made more clear in the new docs.
EDIT 1
It is important to make sure that you are indeed sending something, and that the connection between your client and the media server is negotiated correctly. Going through your bower.json, I've found that you are setting the adapter dependency as whatever, so to speak. In the latest releases, they've done some refactoring that makes the kurento-utils-js library fail. We haven't yet adapted to the new changes, so you need to fix the dependency of adapter.js like so
"adapter.js": "v0.2.9"

Is there any way to use our own server for storage of data generated using PUBNUB api? [duplicate]

I'm looking to develop a chat application with Pubnub where I want to make sure all the chat messages that are send is been stored in the database and also want to send messages in chat.
I found out that I can use the Parse with pubnub to provide storage options, But I'm not sure how to setup those two in a way where the messages and images send in the chat are been stored in the database.
Anyone have done this before with pubnub and parse? Are there any other easy options available to use with pubnub instead of using parse?
Sutha,
What you are seeking is not a trivial solution unless you are talking about a limited number of end users. So I wouldn't say there are no "easy" solutions, but there are solutions.
The reason is your server would need to listen (subscribe) to every chat channel that is active and store the messages being sent into your database. Imagine your app scaling to 1 million users (doesn't even need to get that big, but that number should help you realize how this can get tricky to scale where several server instances are listening to channels in a non-overlapping manner or with overlap but using a server queue implementation and de-duping messages).
That said, yes, there are PubNub customers that have implemented such a solution - Parse not being the key to making this happen, by the way.
You have three basic options for implementing this:
Implement a solution that will allow many instances of your server to subscribe to all of the channels as they become active and store the messages as they come in. There are a lot of details to making this happen so if you are not up to this then this is not likely where you want to go.
There is a way to monitor all channels that become active or inactive with PubNub Presence webhooks (enable Presence on your keys). You would use this to keep a list of all channels that your server would use to pull history (enable Storage & Playback on your keys) from in an on-demand (not completely realtime) fashion.
For every channel that goes active or inactive, your server will receive these events via the REST call (and endpoint that you implement on your server - your Parse server in this case):
channel active: record "start chat" timetoken in your Parse db
channel inactive: record "end chat" timetoken in your Parse db
the inactive event is the kickoff for a process that uses start/end timetokens that you recorded for that channel to get history from for channel from PubNub: pubnub.history({channel: channelName, start:startTT, end:endTT})
you will need to iterate on this history call until you receive < 100 messages (100 is the max number of messages you can retrieve at a time)
as you retrieve these messages you will save them to your Parse db
New Presence Webhooks have been added:
We now have webhooks for all presence events: join, leave, timeout, state-change.
Finally, you could just save each message to Parse db on success of every pubnub.publish call. I am not a Parse expert and barely know all of its capabilities but I believe they have some sort or store local then sync to cloud db option (like StackMob when that was a product), but even if not, you will save msg to Parse cloud db directly.
The code would look something like this (not complete, likely errors, figure it out or ask PubNub support for details) in your JavaScript client (on the browser).
var pubnub = PUBNUB({
publish_key : your_pub_key,
subscribe_key : your_sub_key
});
var msg = ... // get the message form your UI text box or whatever
pubnub.publish({
// this is some variable you set up when you enter a chat room
channel: chat_channel,
message: msg
callback: function(event){
// DISCLAIMER: code pulled from [Parse example][4]
// but there are some object creation details
// left out here and msg object is not
// fully fleshed out in this sample code
var ChatMessage = Parse.Object.extend("ChatMessage");
var chatMsg = new ChatMessage();
chatMsg.set("message", msg);
chatMsg.set("user", uuid);
chatMsg.set("channel", chat_channel);
chatMsg.set("timetoken", event[2]);
// this ChatMessage object can be
// whatever you want it to be
chatMsg.save();
}
error: function (error) {
// Handle error here, like retry until success, for example
console.log(JSON.stringify(error));
}
});
You might even just store the entire set of publishes (on both ends of the conversation) based on time interval, number of publishes or size of total data but be careful because either user could exit the chat and the browser without notice and you will fail to save. So the per publish save is probably best practice if a bit noisy.
I hope you find one of these techniques as a means to get started in the right direction. There are details left out so I expect you will have follow up questions.
Just some other links that might be helpful:
http://blog.parse.com/learn/building-a-killer-webrtc-video-chat-app-using-pubnub-parse/
http://www.pubnub.com/blog/realtime-collaboration-sync-parse-api-pubnub/
https://www.pubnub.com/knowledge-base/discussion/293/how-do-i-publish-a-message-from-parse
And we have a PubNub Parse SDK, too. :)

How to work with PubNub and MtGox api without using PubNub libraries?

I'm writing an app in Dart, which PubNub has no libraries for. My question is, would it be possible to interact with MtGox api (which is, as far as I understand, built on PubNub) using Websockets? How does PubNub relate to Websockets? Their documentation mostly advertises their SDK libraries. I'm rather confused where to start.
PubNub Dart Subscribe to Mt.Gox Bitcoin Feed
The question ask about how to use the PubNub Real-Time Network without an SLA officially supported SDK provided by PubNub. We do not recommend this and instead have provided the recommended method which includes using the standard import 'dart:js' library interop. Details follow but if you still want to continue with a non-library method, the docs for the HTTP REST Push API interface will be a general starting point. But now we are going onward with the recommended method below! Please continue reading.
Subscribing to the Mt.Gox Bitcoin Real-Time feed using Google Dart is rather simple, though a bit confusing at first. Start by setting up your HTML file with the following script tags; and don't forget the PubNub <div>!
PubNub Dart HTML File Example
<h1>PubNub Dart JavaScript SDK Usage Example</h1>
<div id="pubnub" sub-key="sub-c-50d56e1e-2fd9-11e3-a041-02ee2ddab7fe"></div>
<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
<script type="application/dart" src="pubnub_sample.dart"></script>
<script src="packages/browser/dart.js"></script>
<script src="packages/browser/interop.js"></script>
NOTE: The PubNub <div> includes the Mt.Gox Subscribe Key paramater.
PubNub Dart Source File and SDK Usage Subscribe Callback Example
Next your Dart app source code will simply open the TCP Socket to the live stream. Note the channel ID is d5f06780-30a8-4a48-a2f8-7ed181b4a13f. This is one of many channel streams provided by Mt.Gox which allow you to receive Trade/Depth/Ticker signals.
PubNub Dart Source File
import 'dart:js';
void main() {
context['PUBNUB'].callMethod( 'subscribe', [new JsObject.jsify({
"channel" : "d5f06780-30a8-4a48-a2f8-7ed181b4a13f",
"message" : ( message, env, channel, age ) => print(message)
})] );
}
That's it! You can start receiving live Real-Time signals from Mt.Gox using this method. Also you'll want to add or change the channel for different types of events.
NOTE: You can find more Mt.Gox Channels by requesting the channel listing API call: PubNub Mt.Gox Channel Stream Feed Listing for Ticker/Trade/Depth Signals

Play Audio from receiver website

I'm trying to get my receiver to play an mp3 file hosted on the server with the following function
playSound_: function(mp3_file) {
var snd = new Audio("audio/" + mp3_file);
snd.play();
},
However, most of the time it doesn't play and when it does play, it's delayed. When I load the receiver in my local browser, however, it works fine.
What's the correct way to play audio on the receiver?
You can use either a MediaElement tag or Web Audio API. Simplest is probably a MediaElement.

Resources