Package io.openvidu.java.client
Class Session
- java.lang.Object
-
- io.openvidu.java.client.Session
-
public class Session extends Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Gracefully closes the Session: unpublishes all streams and evicts every participant.ConnectioncreateConnection()Same ascreateConnection(ConnectionProperties)but with default ConnectionProperties values.ConnectioncreateConnection(ConnectionProperties connectionProperties)Creates a new Connection object associated to Session object and configured withconnectionProperties.longcreatedAt()Timestamp when this session was created, in UTC milliseconds (ms since Jan 1, 1970, 00:00:00 UTC).booleanfetch()Updates every property of the Session with the current status it has in OpenVidu Server.voidforceDisconnect(Connection connection)Removes the Connection from the Session.voidforceDisconnect(String connectionId)Same asforceDisconnect(ConnectionProperties)but providing theconnectionIdinstead of the Connection object.voidforceUnpublish(Publisher publisher)Forces some Connection to unpublish a Stream.voidforceUnpublish(String streamId)Same asforceUnpublish(Publisher)but providing thestreamIdinstead of the Publisher object.StringgenerateToken()Deprecated.UseSession.createConnection()instead to get aConnectionobject.StringgenerateToken(TokenOptions tokenOptions)Deprecated.UseSession.createConnection(ConnectionProperties)instead to get aConnectionobject.List<Connection>getActiveConnections()Returns the list of active Connections of the Session.ConnectiongetConnection(String id)Returns a Connection of the Session.List<Connection>getConnections()Returns all the Connections of the Session.SessionPropertiesgetProperties()Returns the properties defining the session.StringgetSessionId()Gets the unique identifier of the Session.booleanisBeingBroadcasted()Returns whether the session is being broadcasted or not.booleanisBeingRecorded()Returns whether the session is being recorded or not.ConnectionupdateConnection(String connectionId, ConnectionProperties connectionProperties)PRO Updates the properties of a Connection with aConnectionPropertiesobject.
-
-
-
Method Detail
-
getSessionId
public String 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 public String generateToken() throws OpenViduJavaClientException, OpenViduHttpException
Deprecated.UseSession.createConnection()instead to get aConnectionobject.- Returns:
- The generated token String
- Throws:
OpenViduJavaClientExceptionOpenViduHttpException
-
generateToken
@Deprecated public String generateToken(TokenOptions tokenOptions) throws OpenViduJavaClientException, OpenViduHttpException
Deprecated.UseSession.createConnection(ConnectionProperties)instead to get aConnectionobject.- Returns:
- The generated token String
- Throws:
OpenViduJavaClientExceptionOpenViduHttpException
-
createConnection
public Connection createConnection() throws OpenViduJavaClientException, OpenViduHttpException
Same ascreateConnection(ConnectionProperties)but with default ConnectionProperties values.- Returns:
- The generated
Connectionobject. - Throws:
OpenViduJavaClientExceptionOpenViduHttpException
-
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
Connectionobject. - Throws:
OpenViduJavaClientExceptionOpenViduHttpException
-
close
public void close() throws OpenViduJavaClientException, OpenViduHttpExceptionGracefully closes the Session: unpublishes all streams and evicts every participant.
-
fetch
public boolean fetch() throws OpenViduJavaClientException, OpenViduHttpExceptionUpdates 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:
OpenViduHttpExceptionOpenViduJavaClientException
-
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:
OpenViduJavaClientExceptionOpenViduHttpException
-
forceDisconnect
public void forceDisconnect(String connectionId) throws OpenViduJavaClientException, OpenViduHttpException
Same asforceDisconnect(ConnectionProperties)but providing theconnectionIdinstead of the Connection object.- Parameters:
connectionId- The identifier of the Connection object to remove- Throws:
OpenViduJavaClientExceptionOpenViduHttpException
-
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 getpublisherparameter 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:
OpenViduJavaClientExceptionOpenViduHttpException
-
forceUnpublish
public void forceUnpublish(String streamId) throws OpenViduJavaClientException, OpenViduHttpException
Same asforceUnpublish(Publisher)but providing thestreamIdinstead of the Publisher object.- Parameters:
streamId- The identifier of the Publisher object to remove- Throws:
OpenViduJavaClientExceptionOpenViduHttpException
-
updateConnection
public Connection updateConnection(String connectionId, ConnectionProperties connectionProperties) throws OpenViduJavaClientException, OpenViduHttpException
PRO Updates the properties of a Connection with aConnectionPropertiesobject. 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
Connectionobject - Throws:
OpenViduJavaClientExceptionOpenViduHttpException
-
getConnection
public Connection getConnection(String id)
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
Connectionobject, ornullif no Connection is found for paramid
-
getConnections
public List<Connection> 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
public List<Connection> getActiveConnections()
Returns the list of active Connections of the Session. These are the Connections returningactivein 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
public SessionProperties getProperties()
Returns the properties defining the session.
-
-