Mher Arsh
Mher Arsh

Reputation: 597

ServiceStack Server-Side Events errors

Trying to deal with the problem but can't understand why out such errors.

I get this error in cosole Google Chrome: EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection.

public class Item {
    public int Index { get; set; }
    public int Value { get; set; }
}

public class DataRetModel {        
    public List<Item> Items { get; set; }
    public Item Item { get; set; }        
}

ServerEvents.NotifySession(user.SessionId, new DataRetModel{...init...});

Thanks for help!

.........

After analyzing the requests using Fidler (thanks @mythz for the idea) I found the following: there are 2 client browser running the handlers for server events if you do logout in one browser then the other will get 2 events, one normal and the other "EventSource''s response has a MIME type"(http status=401).

Now the question arises why both clients receive all events if I send them the SessionId?

You can make so that each user receives their event?

var eventSource = new EventSource('/event-stream');

Handler on the client:

$(eventSource).handleServerEvents({
    handlers: {
       DataRetModel: function (data) {
           console.log(data);
       }
    }           
 });

Upvotes: 1

Views: 1276

Answers (1)

mythz
mythz

Reputation: 143319

Now the question arises why both clients receive all events if I send them the SessionId?

Sending notifications by SessionId will send it to all clients with the same Session Id which if you're using a browser will mean all browser tabs.

If you only want to send it to a single SSE subscription (i.e. single browser tab) you will need to send it to the clients SSE SubscriptionId which you'll need to pass in into your Service so it knows where to send the notification to. You can get the subscriptionId from the onConnect handler after the SSE client makes a connection.

Upvotes: 2

Related Questions