Package buzz.getcoco.media
Class MediaSession
- java.lang.Object
-
- buzz.getcoco.media.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. UseMediaSession.Builder
to get the instance of the session configured. callingstart()
would start/join the network according to the configuration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MediaSession.Builder<T extends MediaSession.Builder<T>>
A builder forMediaSession
.static class
MediaSession.ChannelBuilder
A data class holding info on what channel should be created after network creation.static class
MediaSession.ChannelNodesContainer
A data class with the channelName, metadata and node information.static interface
MediaSession.ContentInfoReceivedListener
Add a content info listener for messages sent by other nodes.static class
MediaSession.CreateBuilder
A builder class for creating the network specified.static class
MediaSession.DoNothingBuilder
A builder class for deleting the network specified.static class
MediaSession.JoinBuilder
A builder class for joining the network specified.static interface
MediaSession.MediaSink
The interface between aTxStream
andMediaSession.StreamHandler
.static interface
MediaSession.MediaSource
The interface between aRxStream
and consumer.static interface
MediaSession.MessageReceivedListener
Add a listener to listen for message sent by other nodes.static interface
MediaSession.NodeStatusListener
Add a node status listener for listening status of other nodes.static class
MediaSession.Response<T>
A data class with error and value for each command.static class
MediaSession.SessionHandle
A data informing about previously created and invited sessions.static class
MediaSession.State
Enum representing the status of a givenMediaSession
retrieved usinggetConnectionStatus()
.static interface
MediaSession.StreamHandler
A virtual handle thatMediaSession.StreamHandler.start()
s andMediaSession.StreamHandler.stop()
s without essentially stopping theStream
underneath.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends MediaSession.StreamHandler>
androidx.lifecycle.LiveData<T>addStream(MediaSession.StreamHandler.Builder<T> builder)
Adds a stream into the channel specified byMediaSession.StreamHandler.Builder.getChannelName()
.androidx.lifecycle.LiveData<MediaSession.Response<java.lang.Void>>
delete()
Deletes this session.androidx.lifecycle.LiveData<MediaSession.Response<com.google.common.collect.ImmutableList<MediaSession.SessionHandle>>>
getAllSessions()
Retrieves all previously creates/invited sessions.androidx.lifecycle.LiveData<java.lang.String>
getAuthListener()
androidx.lifecycle.LiveData<MediaSession.State>
getConnectionStatus()
Get the status of the current session.androidx.lifecycle.LiveData<MediaSession.Response<MediaSession.SessionHandle>>
getHandle()
Id of the network, will be resolved once the network is created.static com.google.android.exoplayer2.ExoPlayer
getLowLatencyPlayer(android.content.Context context)
Creates a low latency ExoPlayer instance.androidx.lifecycle.LiveData<MediaSession.Response<com.google.common.collect.ImmutableList<buzz.getcoco.media.User>>>
getUsers()
get users of this Session.androidx.lifecycle.LiveData<MediaSession.Response<java.lang.Void>>
inviteExternalUser(java.lang.String externalUserId)
invite external user into this session.androidx.lifecycle.LiveData<MediaSession.Response<java.lang.Void>>
inviteUser(java.lang.String username, buzz.getcoco.media.Network.Role role, buzz.getcoco.media.Network.AccessType accessType)
Invite a user to this session.void
onContentInfoMessageReceived(java.lang.String message, long nodeId, int contentTime)
void
onNewMessageReceived(java.lang.String message, long nodeId)
void
onNodeConnectionStatusChanged(long nodeId, boolean isOnline)
androidx.lifecycle.LiveData<MediaSession.Response<java.lang.Void>>
removeUser(java.lang.String userId)
Remove a user from this session.void
sendContentInfoMessage(java.lang.String message, int contentTimeMillis, long... nodeIds)
Send the content info message to the following nodes.void
sendMessage(java.lang.String message, long... nodeIds)
Send the message to the following nodes.void
setAuthTokens(java.lang.String tokenJson)
set the accessToken for the sdk to use.void
setContentInfoReceivedListener(MediaSession.ContentInfoReceivedListener contentInfoReceivedListener)
set the content info listener to this session.void
setMessageReceivedListener(MediaSession.MessageReceivedListener messageReceivedListener)
set the messaging listener to this session.void
setNodeStatusListener(MediaSession.NodeStatusListener nodeStatusListener)
set the content info listener to this session.androidx.lifecycle.LiveData<MediaSession.Response<com.google.common.collect.ImmutableList<MediaSession.ChannelNodesContainer>>>
start()
Creates the network and channels specified whenMediaSession.CreateBuilder
is used.void
stop()
Terminate the connection and this session.
-
-
-
Method Detail
-
onNodeConnectionStatusChanged
public void onNodeConnectionStatusChanged(long nodeId, boolean isOnline)
- Specified by:
onNodeConnectionStatusChanged
in interfacebuzz.getcoco.media.Network.MessagingListener
-
onNewMessageReceived
public void onNewMessageReceived(java.lang.String message, long nodeId)
- Specified by:
onNewMessageReceived
in interfacebuzz.getcoco.media.Network.MessagingListener
-
onContentInfoMessageReceived
public void onContentInfoMessageReceived(java.lang.String message, long nodeId, int contentTime)
- Specified by:
onContentInfoMessageReceived
in interfacebuzz.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.
-
addStream
@NonNull public <T extends MediaSession.StreamHandler> androidx.lifecycle.LiveData<T> addStream(@NonNull MediaSession.StreamHandler.Builder<T> builder)
Adds a stream into the channel specified byMediaSession.StreamHandler.Builder.getChannelName()
.- Parameters:
builder
- The builder which will used to start the stream- Returns:
- The Observable which will be triggered after successfully creating the stream
-
setMessageReceivedListener
public void setMessageReceivedListener(MediaSession.MessageReceivedListener messageReceivedListener)
set the messaging listener to this session. NOTE: This will be cleared instop()
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 instop()
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 instop()
and callbacks will be on a background thread.- Parameters:
nodeStatusListener
- The listener which will be triggered when a nodes comes online or goes offline.
-
start
@NonNull public androidx.lifecycle.LiveData<MediaSession.Response<com.google.common.collect.ImmutableList<MediaSession.ChannelNodesContainer>>> start()
Creates the network and channels specified whenMediaSession.CreateBuilder
is used. Joins the network and channels whenMediaSession.JoinBuilder
is used.- Returns:
- Observable which can be used to get the status and Node info of the current connection
-
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 sentnodeIds
- 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 sentcontentTimeMillis
- 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 bygetUsers()
andUser.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 userrole
- The role which the invitee will assumeaccessType
- 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.
-
-