2023-03-08 13:04:10 +01:00
|
|
|
import monkeyPatchMediaDevices from './utils/media-devices.js';
|
|
|
|
|
2022-03-16 12:15:22 +01:00
|
|
|
var MINIMAL;
|
2022-11-24 14:13:18 +01:00
|
|
|
var LANG;
|
|
|
|
var CAPTIONS_LANG;
|
2023-06-21 13:37:43 +02:00
|
|
|
var CUSTOM_LANG_OPTIONS;
|
2022-11-23 23:57:58 +01:00
|
|
|
var CUSTOM_CAPTIONS_LANG_OPTIONS;
|
2022-03-16 12:15:22 +01:00
|
|
|
var PREJOIN;
|
2024-07-02 19:19:05 +02:00
|
|
|
var VIDEO_ENABLED;
|
|
|
|
var AUDIO_ENABLED;
|
2022-03-16 12:15:22 +01:00
|
|
|
|
|
|
|
var SCREENSHARE_BUTTON;
|
|
|
|
var FULLSCREEN_BUTTON;
|
2022-06-01 18:15:44 +02:00
|
|
|
var ACTIVITIES_PANEL_BUTTON;
|
|
|
|
var RECORDING_BUTTON;
|
2023-02-17 17:39:14 +01:00
|
|
|
var BROADCASTING_BUTTON;
|
2022-03-16 12:15:22 +01:00
|
|
|
var CHAT_PANEL_BUTTON;
|
|
|
|
var DISPLAY_LOGO;
|
2024-07-02 19:19:05 +02:00
|
|
|
var DISPLAY_ROOM_NAME;
|
2022-03-16 12:15:22 +01:00
|
|
|
var DISPLAY_PARTICIPANT_NAME;
|
|
|
|
var DISPLAY_AUDIO_DETECTION;
|
2024-07-02 19:19:05 +02:00
|
|
|
var VIDEO_CONTROLS;
|
2022-03-16 12:15:22 +01:00
|
|
|
var LEAVE_BUTTON;
|
|
|
|
var PARTICIPANT_MUTE_BUTTON;
|
|
|
|
var PARTICIPANTS_PANEL_BUTTON;
|
2022-06-01 18:15:44 +02:00
|
|
|
var ACTIVITIES_RECORDING_ACTIVITY;
|
2023-02-17 17:39:14 +01:00
|
|
|
var ACTIVITIES_BROADCASTING_ACTIVITY;
|
2022-06-01 18:15:44 +02:00
|
|
|
var RECORDING_ERROR;
|
2023-02-17 17:39:14 +01:00
|
|
|
var BROADCASTING_ERROR;
|
2022-06-16 15:56:57 +02:00
|
|
|
var TOOLBAR_SETTINGS_BUTTON;
|
2022-07-06 13:46:42 +02:00
|
|
|
var CAPTIONS_BUTTON;
|
2022-03-16 12:15:22 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
var ROOM_NAME;
|
2023-03-08 13:04:10 +01:00
|
|
|
var FAKE_DEVICES;
|
2024-07-02 19:19:05 +02:00
|
|
|
var FAKE_RECORDINGS;
|
2022-03-16 12:15:22 +01:00
|
|
|
|
2022-03-16 16:34:55 +01:00
|
|
|
var PARTICIPANT_NAME;
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
var OPENVIDU_CALL_SERVER_URL;
|
|
|
|
// var OPENVIDU_SECRET;
|
2022-11-24 18:12:40 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2022-11-23 23:57:58 +01:00
|
|
|
var url = new URL(window.location.href);
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
OPENVIDU_CALL_SERVER_URL = url.searchParams.get('OV_URL');
|
|
|
|
// OPENVIDU_SECRET = url.searchParams.get('OV_SECRET');
|
2022-11-23 23:57:58 +01:00
|
|
|
|
2023-03-08 13:04:10 +01:00
|
|
|
FAKE_DEVICES = url.searchParams.get('fakeDevices') === null ? false : url.searchParams.get('fakeDevices') === 'true';
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
FAKE_RECORDINGS = url.searchParams.get('fakeRecordings') === null ? false : url.searchParams.get('fakeRecordings') === 'true';
|
|
|
|
|
2022-11-23 23:57:58 +01:00
|
|
|
// Directives
|
|
|
|
MINIMAL = url.searchParams.get('minimal') === null ? false : url.searchParams.get('minimal') === 'true';
|
|
|
|
LANG = url.searchParams.get('lang') || 'en';
|
2024-07-02 19:19:05 +02:00
|
|
|
CUSTOM_LANG_OPTIONS = url.searchParams.get('langOptions') === null ? false : url.searchParams.get('langOptions') === 'true';
|
|
|
|
// CAPTIONS_LANG = url.searchParams.get('captionsLang') || 'en-US';
|
|
|
|
// CUSTOM_CAPTIONS_LANG_OPTIONS = url.searchParams.get('captionsLangOptions') === null ? false : url.searchParams.get('captionsLangOptions') === 'true';
|
|
|
|
PARTICIPANT_NAME =
|
|
|
|
url.searchParams.get('participantName') === null
|
|
|
|
? 'TEST_USER' + Math.random().toString(36).substr(2, 9)
|
|
|
|
: url.searchParams.get('participantName');
|
2022-11-23 23:57:58 +01:00
|
|
|
PREJOIN = url.searchParams.get('prejoin') === null ? true : url.searchParams.get('prejoin') === 'true';
|
2024-07-02 19:19:05 +02:00
|
|
|
VIDEO_ENABLED = url.searchParams.get('videoEnabled') === null ? true : url.searchParams.get('videoEnabled') === 'true';
|
|
|
|
AUDIO_ENABLED = url.searchParams.get('audioEnabled') === null ? true : url.searchParams.get('audioEnabled') === 'true';
|
2022-11-23 23:57:58 +01:00
|
|
|
SCREENSHARE_BUTTON = url.searchParams.get('screenshareBtn') === null ? true : url.searchParams.get('screenshareBtn') === 'true';
|
2022-12-23 16:17:04 +01:00
|
|
|
RECORDING_BUTTON =
|
|
|
|
url.searchParams.get('toolbarRecordingButton') === null ? true : url.searchParams.get('toolbarRecordingButton') === 'true';
|
2022-11-23 23:57:58 +01:00
|
|
|
FULLSCREEN_BUTTON = url.searchParams.get('fullscreenBtn') === null ? true : url.searchParams.get('fullscreenBtn') === 'true';
|
2023-02-17 17:39:14 +01:00
|
|
|
BROADCASTING_BUTTON =
|
2023-02-17 17:03:15 +01:00
|
|
|
url.searchParams.get('toolbarBroadcastingButton') === null ? true : url.searchParams.get('toolbarBroadcastingButton') === 'true';
|
2022-12-23 16:17:04 +01:00
|
|
|
|
2023-02-17 17:03:15 +01:00
|
|
|
if (url.searchParams.get('broadcastingError') !== null) {
|
2023-02-17 17:39:14 +01:00
|
|
|
BROADCASTING_ERROR = url.searchParams.get('broadcastingError');
|
2022-12-23 16:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-11-23 23:57:58 +01:00
|
|
|
TOOLBAR_SETTINGS_BUTTON =
|
|
|
|
url.searchParams.get('toolbarSettingsBtn') === null ? true : url.searchParams.get('toolbarSettingsBtn') === 'true';
|
|
|
|
CAPTIONS_BUTTON = url.searchParams.get('toolbarCaptionsBtn') === null ? true : url.searchParams.get('toolbarCaptionsBtn') === 'true';
|
|
|
|
|
|
|
|
LEAVE_BUTTON = url.searchParams.get('leaveBtn') === null ? true : url.searchParams.get('leaveBtn') === 'true';
|
|
|
|
ACTIVITIES_PANEL_BUTTON =
|
|
|
|
url.searchParams.get('activitiesPanelBtn') === null ? true : url.searchParams.get('activitiesPanelBtn') === 'true';
|
|
|
|
CHAT_PANEL_BUTTON = url.searchParams.get('chatPanelBtn') === null ? true : url.searchParams.get('chatPanelBtn') === 'true';
|
|
|
|
PARTICIPANTS_PANEL_BUTTON =
|
|
|
|
url.searchParams.get('participantsPanelBtn') === null ? true : url.searchParams.get('participantsPanelBtn') === 'true';
|
2023-02-17 17:39:14 +01:00
|
|
|
ACTIVITIES_BROADCASTING_ACTIVITY =
|
2023-02-17 17:03:15 +01:00
|
|
|
url.searchParams.get('activitiesPanelBroadcastingActivity') === null
|
2022-12-23 16:17:04 +01:00
|
|
|
? true
|
2023-02-17 17:03:15 +01:00
|
|
|
: url.searchParams.get('activitiesPanelBroadcastingActivity') === 'true';
|
2022-11-23 23:57:58 +01:00
|
|
|
ACTIVITIES_RECORDING_ACTIVITY =
|
|
|
|
url.searchParams.get('activitiesPanelRecordingActivity') === null
|
|
|
|
? true
|
|
|
|
: url.searchParams.get('activitiesPanelRecordingActivity') === 'true';
|
|
|
|
if (url.searchParams.get('recordingError') !== null) {
|
|
|
|
RECORDING_ERROR = url.searchParams.get('recordingError');
|
|
|
|
}
|
|
|
|
|
|
|
|
DISPLAY_LOGO = url.searchParams.get('displayLogo') === null ? true : url.searchParams.get('displayLogo') === 'true';
|
2024-07-02 19:19:05 +02:00
|
|
|
DISPLAY_ROOM_NAME = url.searchParams.get('displayRoomName') === null ? true : url.searchParams.get('displayRoomName') === 'true';
|
2022-11-23 23:57:58 +01:00
|
|
|
DISPLAY_PARTICIPANT_NAME =
|
|
|
|
url.searchParams.get('displayParticipantName') === null ? true : url.searchParams.get('displayParticipantName') === 'true';
|
|
|
|
DISPLAY_AUDIO_DETECTION =
|
|
|
|
url.searchParams.get('displayAudioDetection') === null ? true : url.searchParams.get('displayAudioDetection') === 'true';
|
2024-07-02 19:19:05 +02:00
|
|
|
VIDEO_CONTROLS = url.searchParams.get('videoControls') === null ? true : url.searchParams.get('videoControls') === 'true';
|
2022-11-23 23:57:58 +01:00
|
|
|
PARTICIPANT_MUTE_BUTTON =
|
|
|
|
url.searchParams.get('participantMuteBtn') === null ? true : url.searchParams.get('participantMuteBtn') === 'true';
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
ROOM_NAME = url.searchParams.get('roomName') === null ? `E2ESession${Math.floor(Date.now())}` : url.searchParams.get('roomName');
|
2022-11-23 23:57:58 +01:00
|
|
|
|
|
|
|
var webComponent = document.querySelector('openvidu-webcomponent');
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.addEventListener('onTokenRequested', (event) => {
|
|
|
|
appendElement('onTokenRequested');
|
|
|
|
console.log('Token ready', event.detail);
|
|
|
|
joinSession(ROOM_NAME, event.detail);
|
|
|
|
});
|
|
|
|
webComponent.addEventListener('onReadyToJoin', (event) => appendElement('onReadyToJoin'));
|
|
|
|
webComponent.addEventListener('onRoomDisconnected', (event) => appendElement('onRoomDisconnected'));
|
|
|
|
webComponent.addEventListener('onVideoEnabledChanged', (event) => appendElement('onVideoEnabledChanged-' + event.detail));
|
|
|
|
webComponent.addEventListener('onVideoDeviceChanged', (event) => appendElement('onVideoDeviceChanged'));
|
|
|
|
webComponent.addEventListener('onAudioEnabledChanged', (eSESSIONvent) => appendElement('onAudioEnabledChanged-' + event.detail));
|
|
|
|
webComponent.addEventListener('onAudioDeviceChanged', (event) => appendElement('onAudioDeviceChanged'));
|
|
|
|
webComponent.addEventListener('onScreenShareEnabledChanged', (event) => appendElement('onScreenShareEnabledChanged'));
|
|
|
|
webComponent.addEventListener('onParticipantsPanelStatusChanged', (event) =>
|
|
|
|
appendElement('onParticipantsPanelStatusChanged-' + event.detail.isOpened)
|
|
|
|
);
|
|
|
|
webComponent.addEventListener('onLangChanged', (event) => appendElement('onLangChanged-' + event.detail.lang));
|
|
|
|
webComponent.addEventListener('onChatPanelStatusChanged', (event) =>
|
|
|
|
appendElement('onChatPanelStatusChanged-' + event.detail.isOpened)
|
2022-11-23 23:57:58 +01:00
|
|
|
);
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.addEventListener('onActivitiesPanelStatusChanged', (event) =>
|
|
|
|
appendElement('onActivitiesPanelStatusChanged-' + event.detail.isOpened)
|
2022-11-23 23:57:58 +01:00
|
|
|
);
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.addEventListener('onSettingsPanelStatusChanged', (event) =>
|
|
|
|
appendElement('onSettingsPanelStatusChanged-' + event.detail.isOpened)
|
|
|
|
);
|
|
|
|
webComponent.addEventListener('onFullscreenEnabledChanged', (event) => appendElement('onFullscreenEnabledChanged-' + event.detail));
|
2022-11-23 23:57:58 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.addEventListener('onRecordingStartRequested', async (event) => {
|
|
|
|
appendElement('onRecordingStartRequested-' + event.detail.roomName);
|
2022-11-23 23:57:58 +01:00
|
|
|
// Can't test the recording
|
|
|
|
// RECORDING_ID = await startRecording(SESSION_NAME);
|
|
|
|
});
|
|
|
|
// Can't test the recording
|
2024-07-02 19:19:05 +02:00
|
|
|
// webComponent.addEventListener('onRecordingStopRequested', async (event) => {
|
|
|
|
// appendElement('onRecordingStopRequested-' + event.detail.roomName);
|
2022-11-23 23:57:58 +01:00
|
|
|
// await stopRecording(RECORDING_ID);
|
|
|
|
// });
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.addEventListener('onRecordingStopRequested', async (event) => {
|
|
|
|
appendElement('onRecordingStopRequested-' + event.detail.roomName);
|
2022-11-23 23:57:58 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Can't test the recording
|
|
|
|
// webComponent.addEventListener('onActivitiesPanelStopRecordingClicked', async (event) => {
|
|
|
|
// appendElement('onActivitiesPanelStopRecordingClicked');
|
|
|
|
// await stopRecording(RECORDING_ID);
|
|
|
|
// });
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.addEventListener('onRecordingDeleteRequested', (event) => {
|
|
|
|
const { roomName, recordingId } = event.detail;
|
|
|
|
appendElement(`onRecordingDeleteRequested-${roomName}-${recordingId}`);
|
2023-02-17 17:23:13 +01:00
|
|
|
});
|
2022-11-23 23:57:58 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.addEventListener('onBroadcastingStartRequested', async (event) => {
|
|
|
|
const { roomName, broadcastUrl } = event.detail;
|
|
|
|
appendElement(`onBroadcastingStartRequested-${roomName}-${broadcastUrl}`);
|
2022-12-23 16:17:04 +01:00
|
|
|
});
|
|
|
|
|
2023-02-17 17:03:15 +01:00
|
|
|
webComponent.addEventListener('onActivitiesPanelStopBroadcastingClicked', async (event) => {
|
|
|
|
appendElement('onActivitiesPanelStopBroadcastingClicked');
|
2022-12-23 16:17:04 +01:00
|
|
|
});
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.addEventListener('onRoomCreated', (event) => {
|
|
|
|
var room = event.detail;
|
|
|
|
appendElement('onRoomCreated');
|
2022-11-23 23:57:58 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
room.on('disconnected', (e) => {
|
|
|
|
appendElement('roomDisconnected');
|
2022-11-23 23:57:58 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
webComponent.addEventListener('onParticipantCreated', (event) => {
|
|
|
|
var participant = event.detail;
|
2024-07-02 19:19:05 +02:00
|
|
|
appendElement(`${participant.name}-onParticipantCreated`);
|
2022-11-23 23:57:58 +01:00
|
|
|
});
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
setWebcomponentAttributes();
|
2022-03-16 12:15:22 +01:00
|
|
|
});
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
function setWebcomponentAttributes() {
|
2022-11-23 23:57:58 +01:00
|
|
|
var webComponent = document.querySelector('openvidu-webcomponent');
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.participantName = PARTICIPANT_NAME;
|
2022-11-23 23:57:58 +01:00
|
|
|
|
|
|
|
webComponent.minimal = MINIMAL;
|
|
|
|
webComponent.lang = LANG;
|
2023-06-21 13:37:43 +02:00
|
|
|
if (CUSTOM_LANG_OPTIONS) {
|
|
|
|
webComponent.langOptions = [
|
|
|
|
{ name: 'Esp', lang: 'es' },
|
|
|
|
{ name: 'Eng', lang: 'en' }
|
|
|
|
];
|
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
// TODO: Uncomment when the captions are implemented
|
|
|
|
// webComponent.captionsLang = CAPTIONS_LANG;
|
|
|
|
// if (CUSTOM_CAPTIONS_LANG_OPTIONS) {
|
|
|
|
// webComponent.captionsLangOptions = [
|
|
|
|
// { name: 'Esp', lang: 'es-ES' },
|
|
|
|
// { name: 'Eng', lang: 'en-US' }
|
|
|
|
// ];
|
|
|
|
// }
|
|
|
|
if (FAKE_DEVICES) {
|
|
|
|
console.warn('Using fake devices');
|
|
|
|
monkeyPatchMediaDevices();
|
|
|
|
}
|
|
|
|
if (FAKE_RECORDINGS) {
|
|
|
|
console.warn('Using fake recordings');
|
|
|
|
webComponent.recordingActivityRecordingsList = [{ status: 'ready', filename: 'fakeRecording' }];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BROADCASTING_ERROR) {
|
|
|
|
webComponent.broadcastingActivityBroadcastingError = { message: BROADCASTING_ERROR, broadcastAvailable: true };
|
2022-11-23 23:57:58 +01:00
|
|
|
}
|
|
|
|
webComponent.prejoin = PREJOIN;
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.videoEnabled = VIDEO_ENABLED;
|
|
|
|
webComponent.audioEnabled = AUDIO_ENABLED;
|
2022-11-23 23:57:58 +01:00
|
|
|
webComponent.toolbarScreenshareButton = SCREENSHARE_BUTTON;
|
|
|
|
|
|
|
|
webComponent.toolbarFullscreenButton = FULLSCREEN_BUTTON;
|
|
|
|
webComponent.toolbarSettingsButton = TOOLBAR_SETTINGS_BUTTON;
|
2024-07-02 19:19:05 +02:00
|
|
|
// webComponent.toolbarCaptionsButton = CAPTIONS_BUTTON;
|
2022-03-16 12:15:22 +01:00
|
|
|
webComponent.toolbarLeaveButton = LEAVE_BUTTON;
|
2022-11-23 23:57:58 +01:00
|
|
|
webComponent.toolbarRecordingButton = RECORDING_BUTTON;
|
2023-02-17 17:39:14 +01:00
|
|
|
webComponent.toolbarBroadcastingButton = BROADCASTING_BUTTON;
|
2022-11-23 23:57:58 +01:00
|
|
|
webComponent.toolbarActivitiesPanelButton = ACTIVITIES_PANEL_BUTTON;
|
2022-03-16 12:15:22 +01:00
|
|
|
webComponent.toolbarChatPanelButton = CHAT_PANEL_BUTTON;
|
|
|
|
webComponent.toolbarParticipantsPanelButton = PARTICIPANTS_PANEL_BUTTON;
|
|
|
|
webComponent.toolbarDisplayLogo = DISPLAY_LOGO;
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.toolbarDisplayRoomName = DISPLAY_ROOM_NAME;
|
2022-03-16 12:15:22 +01:00
|
|
|
webComponent.streamDisplayParticipantName = DISPLAY_PARTICIPANT_NAME;
|
|
|
|
webComponent.streamDisplayAudioDetection = DISPLAY_AUDIO_DETECTION;
|
2024-07-02 19:19:05 +02:00
|
|
|
webComponent.streamVideoControls = VIDEO_CONTROLS;
|
2022-03-16 12:15:22 +01:00
|
|
|
webComponent.participantPanelItemMuteButton = PARTICIPANT_MUTE_BUTTON;
|
|
|
|
|
2022-11-23 23:57:58 +01:00
|
|
|
webComponent.activitiesPanelRecordingActivity = ACTIVITIES_RECORDING_ACTIVITY;
|
2023-02-17 17:39:14 +01:00
|
|
|
webComponent.activitiesPanelBroadcastingActivity = ACTIVITIES_BROADCASTING_ACTIVITY;
|
2022-11-23 23:57:58 +01:00
|
|
|
webComponent.recordingActivityRecordingError = RECORDING_ERROR;
|
2022-03-16 12:15:22 +01:00
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
function appendElement(id) {
|
|
|
|
var eventsDiv = document.getElementById('events');
|
|
|
|
eventsDiv.setAttribute('style', 'position: absolute;');
|
|
|
|
var element = document.createElement('div');
|
|
|
|
element.setAttribute('id', id);
|
|
|
|
element.setAttribute('style', 'height: 1px;');
|
|
|
|
eventsDiv.appendChild(element);
|
2022-03-16 12:15:22 +01:00
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async function joinSession(roomName, participantName) {
|
|
|
|
var webComponent = document.querySelector('openvidu-webcomponent');
|
|
|
|
console.log('Joining session', roomName, participantName);
|
|
|
|
try {
|
|
|
|
webComponent.token = await getToken(roomName, participantName);
|
|
|
|
} catch (error) {
|
|
|
|
webComponent.tokenError = error;
|
|
|
|
}
|
2022-03-16 12:15:22 +01:00
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async function getToken(roomName, participantName) {
|
|
|
|
try {
|
|
|
|
const response = await fetch(OPENVIDU_CALL_SERVER_URL + '/call/api/rooms', {
|
|
|
|
method: 'POST',
|
2022-11-23 23:57:58 +01:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
2024-07-02 19:19:05 +02:00
|
|
|
// 'Authorization': 'Basic ' + btoa('OPENVIDUAPP:' + OPENVIDU_SECRET),
|
2022-11-23 23:57:58 +01:00
|
|
|
},
|
2024-07-02 19:19:05 +02:00
|
|
|
body: JSON.stringify({
|
|
|
|
participantName,
|
|
|
|
roomName
|
|
|
|
})
|
2022-11-23 23:57:58 +01:00
|
|
|
});
|
2022-06-01 18:15:44 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error('Failed to fetch token');
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
return data.token;
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|