Faye取消订阅不会在服务器上触发任何内容

时间:2014-04-11 16:06:41

标签: node.js faye

我有一个非常简单的在node.js中运行的Faye服务器,如下所示:

faye.on('subscribe', function(message, channel) {
    console.log('subscribed', channel);
}
faye.on('unsubscribe', function(message, channel) {
    console.log('unsubscribed',channel);
}

在我的客户中,我正在做以下事情:

f = new Faye.Client(url);
var s = f.subscribe('/test'); // The server hits the subscribe event
s.cancel();  // Nothing happens on the server
f.unsubscribe('/test');  // Nothing happens here either

我的理解是,执行这些取消订阅方法中的任何一个都应该触发/ meta / unsubscribe的消息,服务器应该看到'unsubscribe'事件,但似乎并非如此。我甚至尝试在服务器上添加一个传入的扩展,甚至还没有,我从来没有看到任何传入的消息,其中message.channel ==='/ meta / unsubscribe'

任何人都可以解释为什么我没有看到unsub事件发生火灾?

1 个答案:

答案 0 :(得分:1)

这是一个有效的faye服务器示例(请注意bayeux):

'use strict'

var server = function(port, pathOptional){
    var http = require('http'),
        faye = require('faye');

    var server = http.createServer();
    var path = '';
    if (pathOptional){
        path += pathOptional;
    }
    var bayeux = new faye.NodeAdapter({mount: '/'+path});

    bayeux.on('subscribe', function(message, channel) {
        console.log('subscribed', channel, message);
    });
    bayeux.on('unsubscribe', function(message, channel) {
        console.log('unsubscribed',channel);
    });
    bayeux.attach(server);
    server.listen(port);
    console.log('server listening on port '+port.toString() );

}


server(8002);