How Do I know MasterClient is Change ? Like OnMasterClientSwitched()

Hi Photon Team,

I read https://doc.photonengine.com/en-us/realtime/current/reference/hostmigration

1. What is the API name to switch master client?
2. What is the call back function or what listener can let me know master client is switched?

Thank you for your help!

Comments

  • Hi @Owen.

    1.
    Switching the master client status through the API is not currently supported in the C++ clients.
    If you need this, then you could implement it by extending LoadBalancing-cpp accordingly to your requirements, as the master client is a feature that is entirely implemented on the Client side, so that no server side modifications are necessary.

    2.
    There is no callback for a master client switch. However the master client only is switched when the previous master client leaves the room.
    In case that any client leaves the room the other clients get informed about that in their Listener::leaveRoomeventAction() callbacks.
    So inside you implementation of that callback you could just read out the return value of LoadBalancing::Client::getCurrentlyJoinedRoom()::getMasterClientID() to get the up to date master client ID. If you have stored a previous return value of that function from the same room then you can compare it with the new value to find out if the ID has changed or is still the same. If it has changed, then the master client has switched to the client, to which that new ID belongs, otherwise that client already has been the master client before and still is it.