Autobahn-JS 不接收在同一页面上发布的订阅(示例)

Autobahn-JS doesn't receive subscription for publish on same page (sample)

我有一个 crossbar.io 服务器设置,我正在 https://github.com/crossbario/autobahn-js

上的浏览​​器 (chrome 81.x) 中尝试示例代码
    // 1) subscribe to a topic
   function onevent(args) {
      console.log("Event:", args[0]);
   }
   session.subscribe('com.myapp.hello', onevent);

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

我没有看到订阅消息。从那以后,我开发了自己的应用程序,我也看到了同样的事情。发布事件的网页没有调用它的订阅。换句话说,如果我在 2 windows 中打开相同的页面并让页面 A 发布消息,页面 B 获取订阅事件,但页面 A 没有。

不确定这是 autobahn-js 还是 crossbar.io 的问题。

我之前有一个支持此功能的 WAMP v1 实现(带有自定义路由器)。确保页面看到自己的发布消息对我来说很重要。如果这不可能,我需要做很多工作来转换我的代码。

找到答案了。它在文档中,具体取决于 Google 为您找到的版本。

https://github.com/crossbario/autobahn-js/blob/master/doc/programming.md

By default, a publisher will not receive an event it publishes even when the publisher is itself subscribed to the topic subscribed to. This behavior can be overridden by passing exclude_me: False in the options.

session.publish('com.myapp.complex', [1, 2, 3], {foo: "bar"}, {exclude_me: false});