mafintosh / signalhub

Simple signalling server that can be used to coordinate handshaking with webrtc or other fun stuff.
MIT License
667 stars 97 forks source link

Server broadcast not working? #5

Closed kevzettler closed 9 years ago

kevzettler commented 9 years ago

I have the following client server setup. I'm trying to broadcast a heartbeat from the server on an interval. The client never receives any messages from the server broadcast. The server does receive the new_client broadcast

// Browser Client
var signalhub = require('signalhub'); 
var hub = signalhub('world-test', ['http://localhost:5000']);

hub.broadcast('new_client', {id: "yourmom"});
hub.subscribe('heartbeat', function(data){
    console.log("heartbeat", data);
});
// Node Server
var SignalServer = require('signalhub/server');
var hub = require('signalhub');

SignalServer().listen(5000, function () {
  console.log("SignalServer listening on 5000");
  var c = hub('world-test', ['http://localhost:5000']);

  setInterval(function(){
    c.broadcast('heartbeat', {derp: true});
  }, 1000);

  c.subscribe('new_client').on('data', function(data){
     console.log("new client!", data.id);
 });
});
mafintosh commented 9 years ago

Your heartbeat subscription is a stream as well. Should look like this

hub.subscribe('heartbeat').on('data', function(data) {
  console.log('heartbeat', data)
})
kevzettler commented 9 years ago

oh man thanks for spot checking that for me :+1: