我是使用 SignalR 的新手(从今天开始),向所有连接的客户端发送消息非常简单,但现在我只想发送给一个组。我找不到有关如何在客户端加入的简单文档。如果有人可以提供帮助,我怎么能简单地加入 javascript 方面的组。谢谢你的帮助。
public class EventHub : Hub
{
public void SendNewMedia(MediaInfoViewModel model,Guid eventId)
{
Clients.Group(eventId.ToString()).setupmedia(model);
}
}
//Controller that is sending client new data
var eventHub = GlobalHost.ConnectionManager.GetHubContext<EventHub>();
var result = eventHub.Clients.Group(eventId.ToString()).setupmedia(eventViewer);
//Finally the javascript. Not sure how to setup just for a group
$(function () {
var event = $.connection.eventHub;
event.client.setupmedia = function (newMedia) {
$('#photolist').prepend('<li><img src="' + newMedia.MediaUrl + '" class="img-polaroid span2"/></li>');
};
$.connection.hub.start(function() {
event.server.create(eventID);//I know this is wrong but not sure how to connect
}).done(function () {
alert('conntected. Ready to retrieve data!');
});
});