Domanda

I have multiple senders connecting to my receiver simultaneously via Chrome. When one of the senders disconnects (closes browser window, refreshes the page, loses connection... etc) I want the "onSenderDisconnected" event to fire on the receiver.

So far, this only seems to happen when connection is lost for whatever reason. If the sender simply refreshes, for example, the sender is never dropped and a new sender is created. That means I might have 2 senders "connected" from the same source.

Is there any way I can either drop the old sender when one reconnects or is there a way to keep the same senderID on reconnect?

I also want to give each sender the option of disconnecting from the session manually (with a button). The only way to do this currently is to stop casting to the device, but that ends the session for all users. How might I go about this?

È stato utile?

Soluzione 2

For the first item (i.e. adding more senders upon each reload), I have opened an internal issue to investigate that. For the second one, currently you cannot just disconnect your chrome sender without stopping the application; you can either (a) Stop application + disconnect (if you use the cast extension) or (b) close the tab which is like "nothing has happened". We are considering bringing that closer to the APIs on the other two platforms.

Altri suggerimenti

For the first issue, I am handling it by keeping track of my "Senders" manually.

Each sender has an "id". Something like 2:client:23522. The first number before the colon (2) seems to stay the same no matter how many times that specific client reconnects to the session. The 2nd number (23522) changes each time.

By checking the first number of a connecting client you can determine whether it is a new client or an existing client that reconnected. That way, when sending messages back and forth between the client/sender you can keep an array of the "active" clients and forget about the old unused client id's.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top