Detecting when clients have connected and disconnected
Learn how to detect when a client connects and disconnects from a session.
The Session object dispatches a connectionCreated event when a new client (including your own) connects to the session. The Session object dispatches a connectionDestroyed event when other clients leave the session. These events are defined by the ConnectionEvent class, which has a connection object, which is a Connection object for the connection (created or destroyed) related to the event:
The OTSession object dispatches a connectionCreated event when a new client (excluding your own) connects to the session. The OTSession object dispatches a connectionDestroyed event when other clients leave the session. These events are defined by the ConnectionEvent class, which has a connection object, which is a Connection object for the connection (created or destroyed) related to the event:
When you are connected to a session, the Session.ConnectionListener.onConnectionCreated(Session session, Connection connection) method is called when a new client (other than your own) connects to the session.
The Session.ConnectionListener.onConnectionDestroyed(Session session, Connection connection) method is called when a client (other than your own) leaves the session. The Connection object passed into the method defines the connection hat has left the session.
Add a listener object for these connection events by calling the setConnectionListener(Session.ConnectionListener listener) method of the Session object:
The OTSessionDelegate session(_: connectionCreated:) message is sent to the session's delegate when another client connects to the session (and for each client connected to the session when you connect).
The OTSessionDelegate session(_: connectionDestroyed:) message is sent to the session's delegate when another client disconnects from the session.
The [OTSessionDelegate session:connectionCreated:] message is sent to the session's delegate when another client connects to the session (and for each client connected to the session when you connect).
The [OTSessionDelegate session:connectionDestroyed:] message is sent to the session's delegate when another client disconnects from the session.
When you are connected to a session, the Session.ConnectionCreated event is sent when a new client (other than your own) connects to the session. The ConnectionEventArgs object passed into the event listener defines the connection hat has left the session:
The Session.ConnectionDropped event is sent when a client (other than your own) leaves the session. The ConnectionEventArgs object passed into the event listener defines the connection that has left the session.
Once you have connected to a session, the on_connection_created callback function of the otc_session_callbacks struct is called when a new client (other than your own) connects to the session. The connection parameter of that function is a pointer to an instance of an otc_connection struct corresponding to the client connecting to the session.
The on_connection_dropped callback function of the otc_session_callbacks struct is called when a client (other than your own) disconnects from the session. The connection parameter of that function is a pointer to the otc_connection struct corresponding to the client disconnecting from the session.