JitsiConnection class manages the XMPP connection to Jitsi Meet servers and provides the foundation for creating conferences.
Overview
JitsiConnection handles:
- XMPP connection establishment and lifecycle
- Authentication with JWT tokens or passwords
- Connection state management
- Conference creation
- Feature advertising
Creating a Connection
Connections are created using the main library API:Constructor Parameters
JitsiConnection.ts:16-34:
Connection Lifecycle
Connecting
Theconnect() method establishes the XMPP connection:
JitsiConnection.ts:105-120:
The connection can send an HTTP conference request to Jicofo before establishing the XMPP connection when both
options.name is provided and the redirect URL is configured.Attaching to Existing Connection
For optimization, you can attach to an existing connection:Disconnecting
Clean up the connection:JitsiConnection.ts:138-144:
Connection Events
All connection events are defined inJitsiConnectionEvents.ts:5-60:
CONNECTION_ESTABLISHED
Fired when the connection is successfully established:id(string) - The ID of the local endpoint/participant/peer
CONNECTION_FAILED
Fired when connection fails:errType(JitsiConnectionErrors) - The type of errorerrReason(string) - Error messagecredentials(object) - Credentials used to connecterrReasonDetails(object) - Additional error details for analytics
CONNECTION_DISCONNECTED
Fired when connection is closed:msg(string) - Message associated with disconnect (e.g., last error)
Other Connection Events
Authentication
JWT Token Authentication
Provide a JWT token during construction:Token Refresh
Renew tokens before expiration:JitsiConnection.ts:159-163:
Password Authentication
Provide credentials in the connect options:Creating Conferences
Once connected, create a conference:JitsiConnection.ts:173-179:
Room names must be lowercase. The constructor will throw an error if the name contains uppercase characters.
Feature Management
Advertise client capabilities:JitsiConnection.ts:214-227:
feature- Feature name (usually URN format)submit- If true, immediately submit the new feature list to peers
Utilities
Get Connection JID
Retrieve the participant’s JID:Connection Times
Get connection timing information for analytics:Connection Logs
Retrieve internal logs for debugging:JitsiConnection.ts:233-251:
Best Practices
Handle Connection Events
Handle Connection Events
Always listen for connection events to handle failures gracefully:
Manage Token Lifecycle
Manage Token Lifecycle
Implement token refresh before expiration:
Clean Up Resources
Clean Up Resources
Always disconnect properly to free resources:
Related Concepts
JitsiConference
Learn about conference lifecycle and room management
Architecture
Understand the overall library architecture