ConnectyCube / connectycube-flutter-sdk-releases

ConnectyCube Flutter SDK Releases
7 stars 1 forks source link

Can you point me at the documentation on how to handle multiple devices with the same user? #40

Closed sowens-csd closed 3 years ago

sowens-csd commented 3 years ago

I'm trying to work out the correct flow for gracefully handling having the same user logged in on multiple devices. I tried it in the p2p_call_sample app doing the following:

  1. Open the app on three devices.
  2. On two of the devices login as user 1
  3. On the third device login as user 2
  4. Call User 1 from the third device.

The result starts as expected. The call rings on the first two devices. However, if I answer on one device the other continues to ring. If I hangup on the device that is still ringing both it and the caller hang up while the device that answered remains connected.

Is there a sample or some documentation that shows how you expect this flow to work and what API interactions can be used to handle it?

TatankaConCube commented 3 years ago

For this case, you can use System messages. Just send special signaling to yourself on other devices. After receiving this message on another device close the Call screen.

sowens-csd commented 3 years ago

This sounds good, thanks, I'll have a look.

sowens-csd commented 3 years ago

This works well, thanks.

In case anyone else is looking for this here's some code I'm using to send a message to all instances of this user and then ignore it on the sender. The result is that every instance other than the sender can handle the message.


void init() {
      _systemMessagesManager =
          CubeChatConnection.instance.systemMessagesManager;
      _systemMessagesManager.systemMessagesStream.listen(_onSystemMessage);
      _originatorId = _getUUID();
}

  /// Call this whenever the call has been handled on the local system,
  /// that could be by accepting it, rejecting it, hanging up, etc.
  void handledCall() {
    CubeMessage systemMessage = CubeMessage();
    systemMessage.recipientId = _cubeSession.userId;
    systemMessage.properties['myEventField'] = handledByMe;
    systemMessage.properties['originatorId'] = _originatorId;
    _systemMessagesManager.sendSystemMessage(systemMessage);
  }

  void _onSystemMessage(CubeMessage message) {
    if (_originatorId == message.properties['originatorId']) return;
    if (handledByMe == message.properties['myEventField'] &&
        onHandledByMe != null) {
      onHandledByMe();
    }
  }