Class MediaSession

  • All Implemented Interfaces:
    buzz.getcoco.media.Network.MessagingListener

    public class MediaSession
    extends java.lang.Object
    implements buzz.getcoco.media.Network.MessagingListener
    Creates a call session. Use MediaSession.Builder to get the instance of the session configured. calling start() would start/join the network according to the configuration.
    • Method Detail

      • onNodeConnectionStatusChanged

        public void onNodeConnectionStatusChanged​(long nodeId,
                                                  boolean isOnline)
        Specified by:
        onNodeConnectionStatusChanged in interface buzz.getcoco.media.Network.MessagingListener
      • onNewMessageReceived

        public void onNewMessageReceived​(java.lang.String message,
                                         long nodeId)
        Specified by:
        onNewMessageReceived in interface buzz.getcoco.media.Network.MessagingListener
      • onContentInfoMessageReceived

        public void onContentInfoMessageReceived​(java.lang.String message,
                                                 long nodeId,
                                                 int contentTime)
        Specified by:
        onContentInfoMessageReceived in interface buzz.getcoco.media.Network.MessagingListener
      • getAuthListener

        public androidx.lifecycle.LiveData<java.lang.String> getAuthListener()
      • setAuthTokens

        public void setAuthTokens​(java.lang.String tokenJson)
        set the accessToken for the sdk to use.
        Parameters:
        tokenJson - The tokens which is obtained from server.
        Throws:
        java.lang.IllegalArgumentException - if the tokens are not valid.
      • getLowLatencyPlayer

        @NonNull
        public static com.google.android.exoplayer2.ExoPlayer getLowLatencyPlayer​(@NonNull
                                                                                  android.content.Context context)
        Creates a low latency ExoPlayer instance.
        Parameters:
        context - The context which will be used to start.
        Returns:
        player instance.
      • setMessageReceivedListener

        public void setMessageReceivedListener​(MediaSession.MessageReceivedListener messageReceivedListener)
        set the messaging listener to this session. NOTE: This will be cleared in stop() and callbacks will be on a background thread.
        Parameters:
        messageReceivedListener - The listener which will be triggered on receiving a new message.
      • setContentInfoReceivedListener

        public void setContentInfoReceivedListener​(MediaSession.ContentInfoReceivedListener contentInfoReceivedListener)
        set the content info listener to this session. NOTE: This will be cleared in stop() and callbacks will be on a background thread.
        Parameters:
        contentInfoReceivedListener - The listener which will be triggered on receiving a new content info message.
      • setNodeStatusListener

        public void setNodeStatusListener​(MediaSession.NodeStatusListener nodeStatusListener)
        set the content info listener to this session. NOTE: This will be cleared in stop() and callbacks will be on a background thread.
        Parameters:
        nodeStatusListener - The listener which will be triggered when a nodes comes online or goes offline.
      • stop

        public void stop()
        Terminate the connection and this session.
      • getHandle

        public androidx.lifecycle.LiveData<MediaSession.Response<MediaSession.SessionHandle>> getHandle()
        Id of the network, will be resolved once the network is created. null if creation fails.
        Returns:
        LiveData to observe the id
      • delete

        public androidx.lifecycle.LiveData<MediaSession.Response<java.lang.Void>> delete()
        Deletes this session. MUST be called before stop.
      • sendMessage

        public void sendMessage​(java.lang.String message,
                                long... nodeIds)
        Send the message to the following nodes.
        Parameters:
        message - The message to be sent
        nodeIds - The nodes which will receive the message
      • sendContentInfoMessage

        public void sendContentInfoMessage​(java.lang.String message,
                                           int contentTimeMillis,
                                           long... nodeIds)
        Send the content info message to the following nodes.
        Parameters:
        message - The message to be sent
        contentTimeMillis - The milliseconds time at which the content has to be paused, played etc..,
        nodeIds - The nodes which will receive the message
      • getAllSessions

        public androidx.lifecycle.LiveData<MediaSession.Response<com.google.common.collect.ImmutableList<MediaSession.SessionHandle>>> getAllSessions()
        Retrieves all previously creates/invited sessions.
        Returns:
        LiveData which returns back with session info
      • getUsers

        public androidx.lifecycle.LiveData<MediaSession.Response<com.google.common.collect.ImmutableList<buzz.getcoco.media.User>>> getUsers()
        get users of this Session.
        Returns:
        LiveData which returns the users of this session
      • removeUser

        public androidx.lifecycle.LiveData<MediaSession.Response<java.lang.Void>> removeUser​(@NonNull
                                                                                             java.lang.String userId)
        Remove a user from this session.
        Parameters:
        userId - The userId returned by getUsers() and User.getUserId()
        Returns:
        LiveData which returns the status of removal
      • inviteUser

        public androidx.lifecycle.LiveData<MediaSession.Response<java.lang.Void>> inviteUser​(@NonNull
                                                                                             java.lang.String username,
                                                                                             @NonNull
                                                                                             buzz.getcoco.media.Network.Role role,
                                                                                             @NonNull
                                                                                             buzz.getcoco.media.Network.AccessType accessType)
        Invite a user to this session.
        Parameters:
        username - The username of the given user
        role - The role which the invitee will assume
        accessType - The accessType which the invitee will take
        Returns:
        LiveData which returns the status of invitation
      • inviteExternalUser

        public androidx.lifecycle.LiveData<MediaSession.Response<java.lang.Void>> inviteExternalUser​(java.lang.String externalUserId)
        invite external user into this session.
        Parameters:
        externalUserId - The userId which will be invited into this session.
        Returns:
        LiveData which returns the status of invitation
      • getConnectionStatus

        public androidx.lifecycle.LiveData<MediaSession.State> getConnectionStatus()
        Get the status of the current session.
        Returns:
        LiveData which returns the status of the session.