Chore: Migrate methods/callJitsi to typescript (#3660)

* chore: migrate callJitsi to typescript

* change fixed string to type

* wip

* wip

* back to old times :)

* back to typescript
This commit is contained in:
Gleidson Daniel Silva 2022-02-17 15:45:21 -03:00 committed by GitHub
parent 5ac4700d51
commit eb38761a37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 10 deletions

View File

@ -1,9 +1,11 @@
import { store as reduxStore } from '../auxStore'; import { ISubscription } from '../../definitions';
import Navigation from '../Navigation';
import { events, logEvent } from '../../utils/log'; import { events, logEvent } from '../../utils/log';
import { store } from '../auxStore';
import Navigation from '../Navigation';
import sdk from '../rocketchat';
async function jitsiURL({ room }) { async function jitsiURL({ room }: { room: ISubscription }) {
const { settings } = reduxStore.getState(); const { settings } = store.getState();
const { Jitsi_Enabled } = settings; const { Jitsi_Enabled } = settings;
if (!Jitsi_Enabled) { if (!Jitsi_Enabled) {
@ -19,7 +21,7 @@ async function jitsiURL({ room }) {
let queryString = ''; let queryString = '';
if (Jitsi_Enabled_TokenAuth) { if (Jitsi_Enabled_TokenAuth) {
try { try {
const accessToken = await this.methodCallWrapper('jitsi:generateAccessToken', room?.rid); const accessToken = await sdk.methodCallWrapper('jitsi:generateAccessToken', room?.rid);
queryString = `?jwt=${accessToken}`; queryString = `?jwt=${accessToken}`;
} catch { } catch {
logEvent(events.RA_JITSI_F); logEvent(events.RA_JITSI_F);
@ -30,23 +32,23 @@ async function jitsiURL({ room }) {
if (Jitsi_URL_Room_Hash) { if (Jitsi_URL_Room_Hash) {
rname = uniqueID + room?.rid; rname = uniqueID + room?.rid;
} else { } else {
rname = encodeURIComponent(room.t === 'd' ? room?.usernames?.join?.(' x ') : room?.name); rname = encodeURIComponent(room.t === 'd' ? (room?.usernames?.join?.(' x ') as string) : room?.name);
} }
return `${protocol}${domain}${prefix}${rname}${queryString}`; return `${protocol}${domain}${prefix}${rname}${queryString}`;
} }
export function callJitsiWithoutServer(path) { export function callJitsiWithoutServer(path: string): void {
logEvent(events.RA_JITSI_VIDEO); logEvent(events.RA_JITSI_VIDEO);
const { Jitsi_SSL } = reduxStore.getState().settings; const { Jitsi_SSL } = store.getState().settings;
const protocol = Jitsi_SSL ? 'https://' : 'http://'; const protocol = Jitsi_SSL ? 'https://' : 'http://';
const url = `${protocol}${path}`; const url = `${protocol}${path}`;
Navigation.navigate('JitsiMeetView', { url, onlyAudio: false }); Navigation.navigate('JitsiMeetView', { url, onlyAudio: false });
} }
async function callJitsi(room, onlyAudio = false) { async function callJitsi(room: ISubscription, onlyAudio = false): Promise<void> {
logEvent(onlyAudio ? events.RA_JITSI_AUDIO : events.RA_JITSI_VIDEO); logEvent(onlyAudio ? events.RA_JITSI_AUDIO : events.RA_JITSI_VIDEO);
const url = await jitsiURL.call(this, { room }); const url = await jitsiURL({ room });
Navigation.navigate('JitsiMeetView', { url, onlyAudio, rid: room?.rid }); Navigation.navigate('JitsiMeetView', { url, onlyAudio, rid: room?.rid });
} }