I subscribe to triggers on the client side in a dynamic way where triggers constantly change, just want to know if there is a way to clear all triggers on the client without keeping track of all triggers by name. Similiar to a method like => Client.ClearAllTriggers()
Also, is there a way to prevent subscribing to the same trigger twice to prevent an event firing twice.
Because you can have multiple handlers registered to the same event, calling RemoveListener wont be able to know which handler to remove.
I’ve added additional APIs that should help in this commit:
client.RemoveListeners(eventName); // remove all handlers registered to this event
client.HasListener(eventName,handler); // is this handler already registered
client.HasListeners(eventName); // are any handlers registered for this event
This change is now on MyGet, if you already have v5.0.3 installed you’ll need to clear your NuGet cache with:
Currently, when using a trigger say client.AddListener(“customEvent”, msg => { … });
When I shut down the server and keep the client open. After restarting the server and then sending an event trigger the trigger fires twice on the client. Checked it with 2 different implementations 1 mobile + 1 uwp. Therefor the SSE client connects again but seems like it adds another trigger without me doing anything I’m just letting SSE automatically reconnect.
Anything I am missing that I should be doing to prevent a double fire of events.
Are you saying your custom "customEvent" trigger event is fired when the Server Events reconnects? Because that’s unlikely since the SSE client doesn’t persist events and only triggers them as it receives it, i.e. it couldn’t do resend a past event even if it wanted to.
So all I can think of is that you’re seeing the result of double-registering for the event or in some hypothetical scenario since event triggers are synchronous that your handler is blocking the client from firing the other events and during that time the server event client reconnects, your handler then unblocks and continues firing the previous events, although that seems very unlikely but I don’t otherwise see how its possible.
If you can put together a small stand-alone example i can run locally to reproduce the issue I will be able to find out what’s really happening.
"Are you saying your custom “customEvent” trigger event is fired when the Server Events reconnects? "
No, I initiate another api call to fire the event again after the client reconnected with
this.ServerEvents.NotifyChannel(“Home”, “trigger.customEvent” , new obj(){})
Afther this rest call I then receive 2 fires on the client side.
Therefor, if I restarted the server say 5 times, I will receive 5 events being fired. I am simply initiating 1 api call to fire.
Then sounds like you have multiple registrations? If you’re dynamically registering them, are you clearing out any previous handlers registered before-hand?
Not to worry. I assumed the OnConnect will be fired once and thereafter the OnReconnect event. looks like the onconnect event also gets fires after reconnection and this is where i put in some listeners.
Been using the SSE listener in UWP without any problems. When using triggers in XF android the solution build in debug mode, but gives me the following error when running:
Also, changing droid project to release mode results in:
I cleared cache as per your docs and also delete bin/obj folders twice, same result. Running SS in .net standard class library in XF as opposed to main solution in UWP.
BTW I can see ServerEventsClient.HasListeners() in the .NET 4.5 and .NET Standard 2.0 builds of the ServiceStack.Client and ServiceStack.Client.Core packages, so you’re likely referencing an old version somewhere.