Search code examples
chromecastgoogle-cast

Disconnect sender unauthorized


I am creating an app for android to support google cast for video with interaction using CastCompanionLibrary library. On the video VideoCastManager use and for the part of the exchange of messages (data) DataManagerCast use. I want to implement a control who can connect to a particular session. My idea is that the first sender to connect on chromecast be the "owner of the session" and other senders need to ask permission to him to connect. I created a namespace for communication between the receiver and the sender session owner for the connection process occurs. If the sender is not authorized then it should disconnect. I took a look at receiver reference searching for a method to the receiver disconnect a particular sende, but it still fails. Does anyone know if it is possible to implement this my idea?


Solution

  • First, why are you using DataCastManager? VideoCastManager can add a data channel and that is all you'd need to communicate so only use the VideoCastManager.

    As far as memory serves, receiver cannot disconnect individual senders, so an alternative to your approach would be:

    • Each sender, after connecting to the receiver, will send a message to receiver to register itself.
    • Receiver looks at the number of connected devices, if that is the first one, it considers that the owner an sends back a message to the sender letting it know that it is the owner. If it is not the first one, it sends back a message to that sender, informing it that it needs to get authorization from the owner (so the new sender knows that it should wait for an authorization). At the same time, it sends a message to the owner asking for permission to allow the second one in.
    • The owner will send back a message to the receiver to allow or prohibit the new sender to connect. Receiver then sends a message to the new sender to let it know if its request was granted or not.
    • If permission was granted, then your code in your sender would allow the user to move forward in the app. If it is not granted, then the logic in your sender app can either stop the user from going forward, or can disconnect the sender, or can just limit the stuff that teh user can do.