Hub有以下方法:
public bool SendMessage(MessageModel model)
{
this.Clients.Group(model.RoomName).sendClientMessage(model);
return true;
}
并在客户端:
function hubService(connection) {
var myHub = connection.chat;
myHub.client.sendClientMessage = function (messageModel) {
return messageModel;
};
}
我想要的是允许其他以hubService
为依赖的javascript对象订阅sendClientMessage
函数,这样当服务器调用sendClientMessage
时,所有订阅者都将被发送messageModel
。这很容易在c#中定义,但不确定如何在javascript中执行此操作。