GetStream/stream-video-flutter

Align `connectUser` method between video and chat

Nash0x7E2 opened this issue · 1 comments

Background

The default connectUser method for video expects a tokenProvider by default where as on chat, connectUser accepts a hardcoded token.

For chat, a token provided is provided by the method connectUserWithProvider.

Problem

As a developer integrating both products, it is not clear which methods to use and when. If the video documentation is the starting point of integration, it is natural to also want to use connectUser on chat. The opposite is also true for customers who may already be using chat and looking to integrate video.

From our dogfooding:

  Future<void> loginWithUserInfo(UserInfo user) async {
...
      await StreamVideo.instance.connectUser(
      user,
      tokenProvider: TokenProvider.dynamic(_tokenLoader, (token) async {
        _logger.d(() => '[onTokenUpdated] token: $token');

        await chatClient?.connectUser(User(id: chatUID), token);
      }),
    );
  }

Solution

  1. Rename video's connectUser method to connectUserWithProvider
  2. Migrate the current connectUser API to use a static token by default

In this case, both chat and video can benefit from using the same token fetching logic while also being very explicit in how and what the method expects.

  Future<void> loginWithUserInfo(UserInfo user) async {

     await StreamVideo.instance.connectUserWithProvider(
      user,
      tokenProvider: TokenProvider.dynamic(_tokenLoader, (token) async {
        _logger.d(() => '[onTokenUpdated] token: $token');
      }),
    );

   await chatClient?.connectUserWithProvider(User(id: chatUID), _tokenLoader);
}

Closing with #367