我试图限制来自公共消息总线的事件应该发送到服务器。允许的事件在outgoingEvents
阵列上。问题是要正确地向他们发送我需要事件名称的服务器。
var Events = new EventEmitter();
var outgoingEvents = [
'messageSubmit'
];
var outgoingMessages = Observable.fromArray(outgoingEvents)
.flatMap(function(eventName) {
return Observable.fromEvent(Events, eventName);
}).subscribe(function() {
// need event name here to properly encode message:
// var eventName = ... should be 'messageSubmit'
// var args = [].slice.call(arguments, 1);
// var encoded = JSON.stringify({ name: eventName, args: args });
// socket.send(encoded);
});
Events.emit('messageSubmit', { message: 'Submitted!' }, {flags: 'ABC'});