Package io.openvidu.java.client
Class Session
java.lang.Object
io.openvidu.java.client.Session
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Gracefully closes the Session: unpublishes all streams and evicts every participant.Same ascreateConnection(ConnectionProperties)
but with default ConnectionProperties values.createConnection
(ConnectionProperties connectionProperties) Creates a new Connection object associated to Session object and configured withconnectionProperties
.long
Timestamp when this session was created, in UTC milliseconds (ms since Jan 1, 1970, 00:00:00 UTC).boolean
fetch()
Updates every property of the Session with the current status it has in OpenVidu Server.void
forceDisconnect
(Connection connection) Removes the Connection from the Session.void
forceDisconnect
(String connectionId) Same asforceDisconnect(ConnectionProperties)
but providing theconnectionId
instead of the Connection object.void
forceUnpublish
(Publisher publisher) Forces some Connection to unpublish a Stream.void
forceUnpublish
(String streamId) Same asforceUnpublish(Publisher)
but providing thestreamId
instead of the Publisher object.Deprecated.generateToken
(TokenOptions tokenOptions) Deprecated.UseSession.createConnection(ConnectionProperties)
instead to get aConnection
object.Returns the list of active Connections of the Session.getConnection
(String id) Returns a Connection of the Session.Returns all the Connections of the Session.Returns the properties defining the session.Gets the unique identifier of the Session.boolean
Returns whether the session is being broadcasted or not.boolean
Returns whether the session is being recorded or not.updateConnection
(String connectionId, ConnectionProperties connectionProperties) PRO Updates the properties of a Connection with aConnectionProperties
object.
-
Method Details
-
getSessionId
Gets the unique identifier of the Session.- Returns:
- The sessionId
-
createdAt
public long createdAt()Timestamp when this session was created, in UTC milliseconds (ms since Jan 1, 1970, 00:00:00 UTC). -
generateToken
Deprecated.UseSession.createConnection()
instead to get aConnection
object.- Returns:
- The generated token String
- Throws:
OpenViduJavaClientException
OpenViduHttpException
-
generateToken
@Deprecated public String generateToken(TokenOptions tokenOptions) throws OpenViduJavaClientException, OpenViduHttpException Deprecated.UseSession.createConnection(ConnectionProperties)
instead to get aConnection
object.- Returns:
- The generated token String
- Throws:
OpenViduJavaClientException
OpenViduHttpException
-
createConnection
Same ascreateConnection(ConnectionProperties)
but with default ConnectionProperties values.- Returns:
- The generated
Connection
object. - Throws:
OpenViduJavaClientException
OpenViduHttpException
-
createConnection
public Connection createConnection(ConnectionProperties connectionProperties) throws OpenViduJavaClientException, OpenViduHttpException Creates a new Connection object associated to Session object and configured withconnectionProperties
. Each user connecting to the Session requires a Connection. The token string value to send to the client side can be retrieved withConnection.getToken()
.- Returns:
- The generated
Connection
object. - Throws:
OpenViduJavaClientException
OpenViduHttpException
-
close
Gracefully closes the Session: unpublishes all streams and evicts every participant. -
fetch
Updates every property of the Session with the current status it has in OpenVidu Server. This is especially useful for getting the list of active connections to the Session (getActiveConnections()
) and use those values to callforceDisconnect(Connection)
,forceUnpublish(Publisher)
orupdateConnection(String, ConnectionProperties)
.
To update all Session objects owned by OpenVidu object at once, callOpenVidu.fetch()
.- Returns:
- true if the Session status has changed with respect to the server, false if not. This applies to any property or sub-property of the object.
- Throws:
OpenViduHttpException
OpenViduJavaClientException
-
forceDisconnect
public void forceDisconnect(Connection connection) throws OpenViduJavaClientException, OpenViduHttpException Removes the Connection from the Session. This can translate into a forced eviction of a user from the Session if the Connection had statusactive
, or into a token invalidation if no user had taken the Connection yet (statuspending
).
In the first case, OpenVidu Browser will trigger the proper events on the client-side (streamDestroyed
,connectionDestroyed
,sessionDisconnected
) with reason set to"forceDisconnectByServer"
.
In the second case, the token of the Connection will be invalidated and no user will be able to connect to the session with it.
This method automatically updates the properties of the local affected objects. This means that there is no need to callSession.fetch()
orOpenVidu.fetch()
to see the changes consequence of the execution of this method applied in the local objects.- Parameters:
connection
- The Connection to remove- Throws:
OpenViduJavaClientException
OpenViduHttpException
-
forceDisconnect
public void forceDisconnect(String connectionId) throws OpenViduJavaClientException, OpenViduHttpException Same asforceDisconnect(ConnectionProperties)
but providing theconnectionId
instead of the Connection object.- Parameters:
connectionId
- The identifier of the Connection object to remove- Throws:
OpenViduJavaClientException
OpenViduHttpException
-
forceUnpublish
public void forceUnpublish(Publisher publisher) throws OpenViduJavaClientException, OpenViduHttpException Forces some Connection to unpublish a Stream. OpenVidu Browser will trigger the proper events in the client-side (streamDestroyed
) with reason set to"forceUnpublishByServer"
.
You can getpublisher
parameter withgetActiveConnections()
and then for each Connection you can callConnection.getPublishers()
. Remember to callfetch()
before to fetch the current actual properties of the Session from OpenVidu Server.
This method automatically updates the properties of the local affected objects. This means that there is no need to callSession.fetch()
orOpenVidu.fetch()
to see the changes consequence of the execution of this method applied in the local objects.- Parameters:
publisher
- The Publisher object to unpublish- Throws:
OpenViduJavaClientException
OpenViduHttpException
-
forceUnpublish
public void forceUnpublish(String streamId) throws OpenViduJavaClientException, OpenViduHttpException Same asforceUnpublish(Publisher)
but providing thestreamId
instead of the Publisher object.- Parameters:
streamId
- The identifier of the Publisher object to remove- Throws:
OpenViduJavaClientException
OpenViduHttpException
-
updateConnection
public Connection updateConnection(String connectionId, ConnectionProperties connectionProperties) throws OpenViduJavaClientException, OpenViduHttpException PRO Updates the properties of a Connection with aConnectionProperties
object. Only these properties can be updated:
This method automatically updates the properties of the local affected objects. This means that there is no need to callSession.fetch()
orOpenVidu.fetch()
to see the changes consequence of the execution of this method applied in the local objects.
The affected client will trigger one ConnectionPropertyChangedEvent for each modified property.- Parameters:
connectionId
- The Connection to modifyconnectionProperties
- A ConnectionProperties object with the new values to apply- Returns:
- The updated
Connection
object - Throws:
OpenViduJavaClientException
OpenViduHttpException
-
getConnection
Returns a Connection of the Session. This method only returns the local available object and does not query OpenVidu Server. To get the current actual value you must call firstSession.fetch()
orOpenVidu.fetch()
.- Parameters:
id
- The Connection to get- Returns:
- The
Connection
object, ornull
if no Connection is found for paramid
-
getConnections
Returns all the Connections of the Session. This method only returns the local available objects and does not query OpenVidu Server. To get the current actual value you must call firstSession.fetch()
orOpenVidu.fetch()
. The list of Connections will remain unchanged since the last time methodSession.fetch()
orOpenVidu.fetch()
was called. Exceptions to this rule are:- Calling
createConnection(ConnectionProperties)
automatically adds the new Connection object to the local collection. - Calling
forceUnpublish(String)
automatically updates each affected local Connection object. - Calling
forceDisconnect(String)
automatically updates each affected local Connection object. - Calling
updateConnection(String, ConnectionProperties)
automatically updates the attributes of the affected local Connection object.
To get the list of connections with their current actual value, you must call firstSession.fetch()
orOpenVidu.fetch()
. - Calling
-
getActiveConnections
Returns the list of active Connections of the Session. These are the Connections returningactive
in response toConnection.getStatus()
. This method only returns the local available objects and does not query OpenVidu Server. The list of active Connections will remain unchanged since the last time methodSession.fetch()
orOpenVidu.fetch()
was called. Exceptions to this rule are:- Calling
createConnection(ConnectionProperties)
automatically adds the new Connection object to the local collection. - Calling
forceUnpublish(String)
automatically updates each affected local Connection object. - Calling
forceDisconnect(String)
automatically updates each affected local Connection object. - Calling
updateConnection(String, ConnectionProperties)
automatically updates the attributes of the affected local Connection object.
To get the list of active connections with their current actual value, you must call firstSession.fetch()
orOpenVidu.fetch()
. - Calling
-
isBeingRecorded
public boolean isBeingRecorded()Returns whether the session is being recorded or not. -
isBeingBroadcasted
public boolean isBeingBroadcasted()Returns whether the session is being broadcasted or not. -
getProperties
Returns the properties defining the session.
-
Session.createConnection()
instead to get aConnection
object.