PrimarySession


@RequiresApi(value = 26) interface PrimarySession


When a Session becomes shared with one or more devices, this interface represents the Primary device (the Session owner).

Summary

Public functions

suspend Unit

Enqueues bytes to be sent to all connected secondaries on their associated SessionRemoteConnection.

ListenableFuture<Void?>

Java-compatible version of broadcastToSecondaries.

suspend Unit

Ends the shared experience that this PrimarySession is currently leading.

ListenableFuture<Void?>

Java-compatible version of destroyPrimarySessionAndStopSharing.

Unit

Disallows new participants to find and join the session.

Unit

Enables new participants to find and join the session.

SessionRemoteConnection

Returns the SessionRemoteConnection for secondary.

List<SessionRemoteConnection>

Returns a list containing the SessionRemoteConnection instances for all secondaries related to this session.

Boolean

Checks whether session discovery is currently enabled.

suspend Unit

Removes the given participant from this session.

ListenableFuture<Void?>

Java-compatible version of removeSecondaryFromSession.

Public properties

SessionId

The SessionId this PrimarySession belongs to.

Public functions

broadcastToSecondaries

suspend fun broadcastToSecondaries(bytes: ByteArray): Unit

Enqueues bytes to be sent to all connected secondaries on their associated SessionRemoteConnection.

Parameters
bytes: ByteArray

The bytes to be sent across the SessionRemoteConnection.

Throws
com.google.ambient.crossdevice.sessions.SessionException: com.google.ambient.crossdevice.sessions.SessionException

if this PrimarySession is no longer valid.

broadcastToSecondariesFuture

fun broadcastToSecondariesFuture(bytes: ByteArray): ListenableFuture<Void?>

Java-compatible version of broadcastToSecondaries.

destroyPrimarySessionAndStopSharing

suspend fun destroyPrimarySessionAndStopSharing(): Unit

Ends the shared experience that this PrimarySession is currently leading. Once destroyPrimarySessionAndStopSharing is called, all other methods will throw SessionException when called.

On the secondary side, each secondary will be notified with SecondarySessionStateCallback.onSecondarySessionCleanup.

Throws
com.google.ambient.crossdevice.sessions.SessionException: com.google.ambient.crossdevice.sessions.SessionException

This PrimarySession is no longer valid.

destroyPrimarySessionAndStopSharingFuture

fun destroyPrimarySessionAndStopSharingFuture(): ListenableFuture<Void?>

Java-compatible version of destroyPrimarySessionAndStopSharing.

disableSessionDiscovery

fun disableSessionDiscovery(): Unit

Disallows new participants to find and join the session.

Throws
com.google.ambient.crossdevice.sessions.SessionException: com.google.ambient.crossdevice.sessions.SessionException

This PrimarySession is no longer valid.

enableSessionDiscovery

fun enableSessionDiscovery(): Unit

Enables new participants to find and join the session. This PrimarySession is notified of new participants joining the session via PrimarySessionStateCallback.onParticipantJoined. New participants are disabled by default.

Throws
com.google.ambient.crossdevice.sessions.SessionException: com.google.ambient.crossdevice.sessions.SessionException

This PrimarySession is no longer valid.

getSecondaryRemoteConnectionForParticipant

fun getSecondaryRemoteConnectionForParticipant(
    secondary: SessionParticipant
): SessionRemoteConnection

Returns the SessionRemoteConnection for secondary.

Throws
com.google.ambient.crossdevice.sessions.SessionException: com.google.ambient.crossdevice.sessions.SessionException

if this PrimarySession is no longer valid or the secondary is not connected.

getSecondaryRemoteConnections

fun getSecondaryRemoteConnections(): List<SessionRemoteConnection>

Returns a list containing the SessionRemoteConnection instances for all secondaries related to this session.

Throws
com.google.ambient.crossdevice.sessions.SessionException: com.google.ambient.crossdevice.sessions.SessionException

if this PrimarySession is no longer valid.

isSessionDiscoveryEnabled

fun isSessionDiscoveryEnabled(): Boolean

Checks whether session discovery is currently enabled.

Throws
com.google.ambient.crossdevice.sessions.SessionException: com.google.ambient.crossdevice.sessions.SessionException

This PrimarySession is no longer valid.

removeSecondaryFromSession

suspend fun removeSecondaryFromSession(secondary: SessionParticipant): Unit

Removes the given participant from this session. On the secondary side, the secondary will be notified with SecondarySessionStateCallback.onSecondarySessionCleanup.

Parameters
secondary: SessionParticipant

The participant to remove.

Throws
com.google.ambient.crossdevice.sessions.SessionException: com.google.ambient.crossdevice.sessions.SessionException

This PrimarySession is no longer valid.

removeSecondaryFromSessionFuture

fun removeSecondaryFromSessionFuture(secondary: SessionParticipant): ListenableFuture<Void?>

Java-compatible version of removeSecondaryFromSession.

Public properties

sessionId

val sessionIdSessionId

The SessionId this PrimarySession belongs to.