Skip to content

Commit

Permalink
feat: add reconnection flag to login message
Browse files Browse the repository at this point in the history
  • Loading branch information
farhat-ha committed Sep 17, 2024
1 parent 7f55ef9 commit 0a5ac46
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/js/src/Modules/Verto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Call from './webrtc/Call';
import { TIME_CALL_INVITE } from './util/constants';
import VertoHandler from './webrtc/VertoHandler';
import { isValidOptions } from './util/helpers';
import { getReconnectToken } from './util/reconnect';

export const VERTO_PROTOCOL = 'verto-protocol';

Expand Down Expand Up @@ -69,12 +70,14 @@ export default class Verto extends BrowserSession {
userVariables,
autoReconnect = true,
} = this.options;

const msg = new Login(
login,
password || passwd,
login_token,
this.sessionid,
userVariables
userVariables,
!!getReconnectToken()
);
const response = await this.execute(msg).catch(this._handleLoginError);
if (response) {
Expand Down
4 changes: 3 additions & 1 deletion packages/js/src/Modules/Verto/messages/verto/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Login extends BaseRequest {
passwd: string,
login_token: string,
sessionid: string,
userVariables: Object = {}
userVariables: Object = {},
reconnection: boolean
) {
super();

Expand All @@ -19,6 +20,7 @@ class Login extends BaseRequest {
passwd,
login_token,
userVariables,
reconnection,
loginParams: {},
'User-Agent': {
sdkVersion: pkg.version,
Expand Down
21 changes: 16 additions & 5 deletions packages/js/src/Modules/Verto/tests/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ describe('Messages', function () {
'login',
'password',
'dskbksdjbfkjsdf234y67234kjrwe98',
null!
null!,
{},
false
).request;
const res = JSON.parse(
`{"jsonrpc":"2.0","id":"${message.id}","method":"login","params":{"User-Agent": ${userAgent},"login":"login","passwd":"password","login_token": "dskbksdjbfkjsdf234y67234kjrwe98","loginParams":{},"userVariables":{}}}`
`{"jsonrpc":"2.0","id":"${message.id}","method":"login","params":{"User-Agent": ${userAgent},"login":"login","passwd":"password", "reconnection": false,"login_token": "dskbksdjbfkjsdf234y67234kjrwe98","loginParams":{},"userVariables":{}}}`
);
expect(message).toEqual(res);
});
Expand All @@ -34,16 +36,25 @@ describe('Messages', function () {
'login',
'password',
'dskbksdjbfkjsdf234y67234kjrwe98',
'123456789'
'123456789',
{},
false
).request;
const res = JSON.parse(
`{"jsonrpc":"2.0","id":"${message.id}","method":"login","params":{"User-Agent": ${userAgent},"login":"login","passwd":"password","login_token": "dskbksdjbfkjsdf234y67234kjrwe98","sessid":"123456789","loginParams":{},"userVariables":{}}}`
`{"jsonrpc":"2.0","id":"${message.id}","method":"login","params":{"User-Agent": ${userAgent},"login":"login","passwd":"password","reconnection": false, "login_token": "dskbksdjbfkjsdf234y67234kjrwe98","sessid":"123456789","loginParams":{},"userVariables":{}}}`
);
expect(message).toEqual(res);
});

it('Should pass User-Agent to the backend', () => {
const req = new Login('login', 'password', 'token', 'session').request;
const req = new Login(
'login',
'password',
'token',
'session',
{},
false
).request;
expect(req).toEqual(
expect.objectContaining({
params: expect.objectContaining({
Expand Down

0 comments on commit 0a5ac46

Please sign in to comment.