mean-expert-official / loopback-component-realtime

The LoopBack Component that turns this great framework into a powerful real-time platform
MIT License
30 stars 17 forks source link

No events received #28

Closed jmls closed 7 years ago

jmls commented 7 years ago

so, I followed all the config options, and when I start the app, I get

@mean-expert/loopback-component-realtime: Running in a not clustered environment
@mean-expert/loopback-component-realtime: RTC authentication mechanism enabled
@mean-expert/loopback-component-realtime: IO server enabled using socket.io driver.
@mean-expert/loopback-component-realtime: PubSub server enabled using socket.io driver.
@mean-expert/loopback-component-realtime: FireLoop server enabled using socket.io driver.
@mean-expert/loopback-component-realtime: WebRTCSignaler server enabled using socket.io driver.
node server running

the server code is

  // start the web server
  return app.listen(function() {
    app.emit('started');
    app.mx.IO.emit('test', 'Hello World');
    app.mx.IO.on('test', function (message) {
      console.log('MESSAGE: ', message);
    });
    console.log("node server running")

  });

and the problem ? Well, I don't see MESSAGE: hello world

Something stupid / simple that I missed ?

jonathan-casarrubias commented 7 years ago

Hi @jmls, try publicly broadcasting the events from a bootscript as in https://github.com/mean-expert-official/fireloop.io/issues/57

jmls commented 7 years ago

ok, sure, I'll give that a bash - it's just the start function is running is after the system has booted, so not sure why that would make a difference

jmls commented 7 years ago

hmm

module.exports = function (app, cb) {

    app.mx.IO.on("test1", function(msg) {
        console.log("test1:", msg);
    });
}

gives TypeError: Cannot read property 'IO' of undefined

I am trying to use just the IO part of loopback-component-realtime, not fireloop.io as I have an existing strongloop app

jmls commented 7 years ago
    app.on('started',() => {

        app.mx.IO.on("test1", function(msg) {
            console.log("===> test1:", msg);
        });

        app.mx.IO.emit("test1","foobar");

    });

no message.

What I meant by "so not sure why that would make a difference" was that the orginal code I wrote was in the start function, after the emit("started"), so it would behave exactly like the code in the bootscript. And it does - no message :(

jonathan-casarrubias commented 7 years ago

yes I'm sorry I misunderstood, now I see in the original post you added the code within the start function within the server.js file and makes sense.

Mh ok, so what is strange is that you are not getting anything when calling the app.mx.IO.emit('test1') it should be fired...

Not sure if it would help but try updating the module to the latest RC, though not sure how much that would help, I mean the other 2 guys are successfully sending messages from the server side, though they are using the fireloop flavored version of loopback, there is no difference in terms of the real-time module, is the same.. so it should work the same

jonathan-casarrubias commented 7 years ago

Look when you use the app.mx.IO.emit() you are actually using the server instance emitting to everyone.

For everyone I mean all the clients, including the client instance, which in this case when you listen for app.mx.IO.on() it actually is a client instance, not the server instance so it really should receive the message, as well as other clients.

https://github.com/mean-expert-official/loopback-component-realtime/blob/master/src/drivers/io.driver.ts#L155

At the end the app.mx.IOobject is just a facade of the IO Driver..

https://github.com/mean-expert-official/loopback-component-realtime/blob/master/src/modules/IO.ts#L13

jonathan-casarrubias commented 7 years ago

Closing for inactivity