我想向特定的DDP客户端发送任意消息。
例如,打电话"写"来自服务器:
Meteor.server.sessions[ session_id ].socket.write( { data_for_user: "something" } )
但我不确定我应该如何抓住"这条消息在客户端上。
我知道以下代码不起作用,但我想在这些方面取得一些成就:
DDP.client.onmessage( function( data ) {
// i'm guessing i would have to filter my messages
// since all DDP messages fire here?
if( data.data_for_user ) {
// Do i need to tell DDP to don't parse my custom message?
console.log( "got something for you", data )
}
} );
答案 0 :(得分:1)
您可以像这样在客户端上捕获DDP消息。
var original = Meteor.connection._livedata_data;
Meteor.connection._livedata_data = function (msg) {
console.log(msg)
return original.call(this, msg);
}