crossbario / autobahn-js

WAMP in JavaScript for Browsers and NodeJS
http://crossbar.io/autobahn
MIT License
1.43k stars 228 forks source link

Subscribe does not fire when something is published #573

Closed mStirner closed 1 year ago

mStirner commented 1 year ago

I was using your example from the README, but the example does not work as expected. The onevent call back is not executed.

It does only get called when the event is published from a other session. E.g.:

try {
    // for Node.js
    var autobahn = require('autobahn');
} catch (e) {
    // for browsers (where AutobahnJS is available globally)
}

var connection1 = new autobahn.Connection({
    url: 'ws://127.0.0.1:8000/',
    realm: 'com.example.inge'
});

var connection2 = new autobahn.Connection({
    url: 'ws://127.0.0.1:8000/',
    realm: 'com.example.inge'
});

connection1.onopen = function (session) {

    // 1) subscribe to a topic
    function onevent(args) {
        console.log("Event:", args[0]);
    }
    session.subscribe('com.myapp.hello', onevent);

    // 3) register a procedure for remoting
    function add2(args) {
        return args[0] + args[1];
    }

    session.register('com.myapp.add2', add2);

};

connection2.onopen = function (session) {

    // 2) publish an event
    session.publish('com.myapp.hello', ['Hello, world!']);

    // 4) call a remote procedure
    session.call('com.myapp.add2', [2, 3]).then(
        function (res) {
            console.log("Result:", res);
        }
    );

};

connection1.open();
connection2.open();

The example from the readme does not work. Is this "as it should be" or a issue with autobhan.js?

But why does call work in a single session, but not publish?