Excuse me Demis, what I’ ve to do in order to serve the ss-utils.js on an ASP.Net MVC application? have I to register an axd or something like this? Thanks
You don’t have to do anything. ss-utils.js is embedded in ServiceStack.dll and always accessible from /js/ss-utils.js from where ServiceStack is mounted which when using SS with MVC is typically at /api/js/ss-utils.js, e.g: http://bootstrapapi.servicestack.net/api/js/ss-utils.js
paolo ponzano:
Thanks a lot for your reply… I was missing the use of @Url.Content("~/api/…")… another question regarding the message receive… I need to notificate the client in order to wake up some widget after a NotifyWidgets action has been invoked… since only the widget of the current session needs to be notified I’ve used this method on my Controller
public ActionResult NofityWidgets()
{
IServerEvents ServerEvents = AppHost.Instance.TryResolve<IServerEvents>();
ServerEvents.NotifySession(UserSession.Id, “test”);
return new EmptyResult();
}
and in my _Layout.cshtml I’ve
<script>
$(document).ready(function (e) {
var source = new EventSource("@Url.Content("~/api/event-stream?channel=channel&t=’+ new Date().getTime())")");
$(source).handleServerEvents({
handlers: {
onConnect: function (subscription) {
activeSub = subscription;
console.log(“connected”);
},
onJoin: function (user) {
console.log(“joined”);
},
onLeave: function (user) {
console.log(“leave”);
},
//… Register custom handlers
},
receivers: {
//… Register any receivers
},
success: function (selector, msg, json) { // fired after every message
console.log(selector, msg, json);
},
});
})
</script>
How do I process the received message? I don’t see any event fired when I receive a message
Thanks
Hi Paolo, if your question has code please post it on http://stackoverflow.com and paste a link to it here as it’s unreadable otherwise.
If you want to notify a SessionId you have to send the Permanent Session Id (ss-pid) which happens when the user authenticates with RememberMe=true
. You can check if it’s the same by comparing UserSession.Id
with the users ss-pid
cookie. Because of this it’s more reliable notifying the user with the UserAuthId. You can also make use of a unique channel name to filter what messages a User listens to/receives.
paolo ponzano:
Hello Demis, my problem is related on the javascript part… how do I read the message I’ve sent from server?
Thanks
Please see the docs, here’s the section on handling msgs with the default selector: https://github.com/ServiceStack/ServiceStack/wiki/JavaScript-Server-Events-Client#handling-messages-with-the-default-selector