Hi there,
I am working on a video conference project that uses lib-jitsi-meet to create my own UI while using Jitsi Meet’s services.
It has been working perfectly so far but recently, not due to any changes I have made, I have run into a couple issues when trying to connect. I believe this is related to token passing and generation, previously I was calling JitsiConnection while setting the token to null.
Now I’m trying to pass a token, following the guidelines documented here: lib-jitsi-meet/tokens.md at master · jitsi/lib-jitsi-meet · GitHub However, I am still getting the following error messages:
WebSocket connection to ‘wss://meet.jit.si/xmpp-websocket?room=seeloved1&token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImppdHNpL2N1c3RvbV9rZXlfbmFtZSJ9.eyJjb250ZXh0Ijp7InVzZXIiOnsiYXZhdGFyIjoiaHR0cHM6L2dyYXZhdGFyLmNvbS9hdmF0YXIvYWJjMTIzIiwibmFtZSI6IkpvaG4gRG9lIiwiZW1haWwiOiJqZG9lQGV4YW1wbGUuY29tIiwiaWQiOiJhYmNkOmExYjJjMy1kNGU1ZjYtMGFiYzEtMjNkZS1hYmNkZWYwMWZlZGNiYSJ9LCJncm91cCI6ImExMjMtMTIzLTQ1Ni03ODkifSwiYXVkIjoiaml0c2kiLCJpc3MiOiJjbGllbnQiLCJzdWIiOiIqIiwicm9vbSI6IioiLCJpYXQiOjE2MTMxNjM5MDB9.jww3GbhVwcaL-aypjbgOP5fjKzUUgwqtFjV5uuQeirxOrr3fMocpx4fLTrR-SeU00Fxyc3GMnnjdrSZ3QxrNXQ’ failed: Error during WebSocket handshake: Unexpected response code: 403
2021-02-12T21:05:00.646Z [modules/xmpp/strophe.util.js] <Object.r.Strophe.log>: Strophe: Websocket error [object Event]
Any suggestions on how to get a successful connection with the websocket? Also, because I’m using lib-jitsi-meet, I did not use Prosody for token generation, rather I am generating my own using JWT. I am using the RS256 algorithm to encode the token as requested in the lib-jitsi-meet documentation.
Here is my onConnect method which is now creating a token (temporarily with a non-real user for testing purposes). I have included my onDisconnect method as well.
onConnect = () => {
const { roomId, serverURL } = this.state;
this.setState({
status: “Joining…”,
});
const header = {
kid: 'jitsi/custom_key_name',
typ: "JWT"
};
const payload =
{
context: {
user: {
avatar: "https:/gravatar.com/avatar/abc123",
name: "John Doe",
email: "jdoe@example.com",
id: "abcd:a1b2c3-d4e5f6-0abc1-23de-abcdef01fedcba"
},
group: "a123-123-456-789"
},
aud: "jitsi",
iss: "client",
sub: "*",
room: "*"
};
//RSA encoding of private key
const key = new NodeRSA({b: 512});
const formattedKey = key.exportKey('pkcs1');
const token = jwt.sign(payload, formattedKey, {algorithm: 'RS256', header: header});
if (!token) throw Error('Couldnt sign the token');
window.seeloved1.activeConnection = new window.JitsiMeetJS.JitsiConnection(
null,
token,
{
hosts: {
domain: serverURL,
muc: `conference.${serverURL}`, // FIXME: use XEP-0030
},
serviceUrl: `wss://${serverURL}/xmpp-websocket?room=${roomId}`,
clientNode: `https://${serverURL}`,
}
);
window.seeloved1.activeConnection.addEventListener(
window.JitsiMeetJS.events.connection.CONNECTION_ESTABLISHED,
this.onConnectionSuccess
);
window.seeloved1.activeConnection.addEventListener(
window.JitsiMeetJS.events.connection.CONNECTION_FAILED,
this.onConnectionFailed
);
window.seeloved1.activeConnection.addEventListener(
window.JitsiMeetJS.events.connection.CONNECTION_DISCONNECTED,
this.onConnectionDisconnect
);
window.seeloved1.activeConnection.connect();
};
onDisconnect = () => {
if (window.seeloved1.activeRoom) {
this.setState({
status: “Leaving…”,
});
try {
window.seeloved1.activeRoom.leave().then(() => {
if (window.seeloved1.activeConnection) {
window.seeloved1.activeConnection.disconnect();
}
this.setState({
status: “closed”,
remoteTracks: ,
activeRoomId: null,
});
});
} catch (error) {
this.setState({
status: “closed”,
lastError: error.message,
});
}
}
};