Documentation Index Fetch the complete documentation index at: https://mintlify.com/jitsi/lib-jitsi-meet/llms.txt
Use this file to discover all available pages before exploring further.
This guide covers how to create and manage connections to Jitsi Meet servers using the JitsiConnection class.
Overview
The JitsiConnection class provides access to the Jitsi Meet server-side video conferencing service. It handles XMPP connection establishment, authentication, and provides the foundation for creating conferences.
Creating a Connection
Initialize JitsiMeetJS
First, initialize the library with your configuration: JitsiMeetJS . init ({
disableAudioLevels: false ,
enableAnalyticsLogging: false
});
Configure connection options
Define your connection options: const options = {
serviceUrl: 'wss://your-server.com/xmpp-websocket' ,
hosts: {
domain: 'your-server.com'
},
enableWebsocketResume: true ,
websocketKeepAlive: 60000 ,
websocketKeepAliveUrl: 'https://your-server.com/about/health' ,
p2pStunServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' }
]
};
Create the connection instance
Instantiate a new connection: const connection = new JitsiMeetJS . JitsiConnection (
null , // appID (optional)
null , // JWT token (optional)
options
);
Register event handlers
Set up event listeners before connecting: connection . addEventListener (
JitsiMeetJS . events . connection . CONNECTION_ESTABLISHED ,
onConnectionSuccess
);
connection . addEventListener (
JitsiMeetJS . events . connection . CONNECTION_FAILED ,
onConnectionFailed
);
connection . addEventListener (
JitsiMeetJS . events . connection . CONNECTION_DISCONNECTED ,
onDisconnect
);
Connect to the server
Initiate the connection: connection . connect ({
id: 'user@domain.com' , // Optional: username for authentication
password: 'password' , // Optional: password for authentication
name: 'conferenceRoom' // Optional: room name for HTTP conference request
});
Connection Options
Required Options
Option Type Description serviceUrlstring WebSocket URL for XMPP connection hosts.domainstring XMPP domain name enableWebsocketResumeboolean Enable WebSocket session resumption p2pStunServersarray STUN servers for P2P connections
Optional Options
interface IConnectionOptions {
analytics ?: any ;
bridgeChannel ?: {
ignoreDomain ?: string ;
preferSctp ?: boolean ;
};
disableFocus ?: boolean ;
flags ?: Record < string , any >;
name ?: string ;
websocketKeepAlive ?: number ;
websocketKeepAliveUrl ?: string ;
xmppPing ?: any ;
}
Authentication
Anonymous Connection
Connect without credentials:
Authenticated Connection
Connect with username and password:
connection . connect ({
id: 'moderator@domain.com' ,
password: 'secure-password'
});
JWT Token Authentication
Provide a JWT token during connection creation:
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' ;
const connection = new JitsiMeetJS . JitsiConnection (
'your-app-id' ,
token ,
options
);
connection . connect ();
Event Handlers
Connection Established
Connection Failed
Connection Disconnected
function onConnectionSuccess () {
console . log ( 'Successfully connected!' );
// Now you can create a conference
const conference = connection . initJitsiConference ( 'room-name' , {});
}
Managing Connections
Disconnect
Properly close the connection:
connection . disconnect (). then (() => {
console . log ( 'Disconnected successfully' );
}). catch ( error => {
console . error ( 'Error during disconnect:' , error );
});
Refresh Authentication Token
Renew JWT tokens before expiration:
const newToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' ;
connection . refreshToken ( newToken ). then (() => {
console . log ( 'Token refreshed successfully' );
}). catch ( error => {
console . error ( 'Failed to refresh token:' , error );
});
Get Connection Info
Retrieve connection details:
// Get participant JID
const jid = connection . getJid ();
console . log ( 'My JID:' , jid );
// Get connection timing information
const times = connection . getConnectionTimes ();
console . log ( 'Connection times:' , times );
Feature Management
Advertise client capabilities:
// Add a feature
connection . addFeature ( 'urn:xmpp:jingle:apps:dtls:0' , true );
// Remove a feature
connection . removeFeature ( 'urn:xmpp:jingle:apps:dtls:0' , true );
Attaching to Existing Sessions
For optimized reconnection, attach to an existing XMPP session:
const attachOptions = {
jid: 'user@domain.com/resource' ,
sid: 'session-id' ,
rid: 'request-id'
};
connection . attach ( attachOptions );
Best Practices
Handle reconnection gracefully
Implement exponential backoff for reconnection attempts: let reconnectAttempts = 0 ;
const maxReconnectAttempts = 5 ;
function reconnect () {
if ( reconnectAttempts < maxReconnectAttempts ) {
const delay = Math . min ( 1000 * Math . pow ( 2 , reconnectAttempts ), 30000 );
setTimeout (() => {
reconnectAttempts ++ ;
connection . connect ();
}, delay );
}
}
connection . addEventListener (
JitsiMeetJS . events . connection . CONNECTION_FAILED ,
reconnect
);
Monitor connection quality
Use connection statistics to monitor quality: const logs = connection . getLogs ();
console . log ( 'Connection logs:' , logs );
Always remove event listeners when done: function cleanup () {
connection . removeEventListener (
JitsiMeetJS . events . connection . CONNECTION_ESTABLISHED ,
onConnectionSuccess
);
connection . removeEventListener (
JitsiMeetJS . events . connection . CONNECTION_FAILED ,
onConnectionFailed
);
}
Next Steps
Managing Conferences Learn how to create and manage conferences
Handling Media Tracks Work with audio and video tracks