c# - In ServiceStack, how do I broadcast messages from the Server? -
is there simple tutorial showing how use server events servicestack? specifically, i'm looking way have server generate messages broadcast clients.
i've been reading servicestack documentation , playing sample chat application neither source informative. documentation has gaps , chat application bloated , shows how send messages triggered client, not server , can't figure out how adapt code.
the server events docs shows different apis available publishing server events:
public interface iserverevents : idisposable { // external api's void notifyall(string selector, object message); void notifychannel(string channel, string selector, object message); void notifysubscription(string subscriptionid, string selector, object message, string channel = null); void notifyuserid(string userid, string selector, object message, string channel = null); void notifyusername(string username, string selector, object message, string channel = null); void notifysession(string sspid, string selector, object message, string channel = null); //.. }
so can use notifyall
api send message subscribers, e.g:
public class myservices : service { public iserverevents serverevents { get; set; } public object any(request request) { serverevents.notifyall("cmd.mybroadcast", request); ... } }
which since it's using cmd.*
selector, can handled in javascript clients with:
$(source).handleserverevents({ handlers: { mybroadcast: function(msg,e) { ... } } });
however should rare want send message subscribers instead of subscribers in channel.
server event examples
all javascript server event handlers in servicestack's reference chat app captured in 40 lines of javascript , 2 servicestack services on server , showcases of features in javascript server events.
if chat app isn't clear have @ other server event examples, e.g. real-time networked time traveller goes through , explains how uses server events remote control apps watching users app.
Comments
Post a Comment