Upload files to "JS"
This commit is contained in:
+434
@@ -0,0 +1,434 @@
|
||||
window.Kronick =
|
||||
window.Kronick || {};
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the page after all deferred scripts
|
||||
* and HTML elements have loaded.
|
||||
*/
|
||||
window.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
/*
|
||||
* Initialize per-device microphone, suppression and spatial audio controls.
|
||||
*/
|
||||
if (
|
||||
typeof Kronick.initAudioSettings
|
||||
=== 'function'
|
||||
) {
|
||||
Kronick.initAudioSettings();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Restore saved room, username and avatar
|
||||
* values, then populate their datalists.
|
||||
*/
|
||||
if (
|
||||
typeof Kronick.loadSavedJoinInfo
|
||||
=== 'function'
|
||||
) {
|
||||
Kronick.loadSavedJoinInfo();
|
||||
}
|
||||
|
||||
if (
|
||||
typeof Kronick.populateSavedLists
|
||||
=== 'function'
|
||||
) {
|
||||
Kronick.populateSavedLists();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Display the empty-room placeholder before
|
||||
* a LiveKit connection is established.
|
||||
*/
|
||||
if (
|
||||
typeof Kronick.showEmptyRoomMessage
|
||||
=== 'function'
|
||||
) {
|
||||
Kronick.showEmptyRoomMessage();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the disconnected button states.
|
||||
*/
|
||||
if (
|
||||
typeof Kronick.setConnectionControls
|
||||
=== 'function'
|
||||
) {
|
||||
Kronick.setConnectionControls(
|
||||
'disconnected'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (typeof Kronick.initializeWindowManager === 'function') {
|
||||
Kronick.initializeWindowManager();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Music browser window.
|
||||
*/
|
||||
Kronick.initializeDraggableWindow(
|
||||
'musicFrameWrap',
|
||||
'musicFrameHeader',
|
||||
'musicFramePosition'
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Giphy browser window.
|
||||
*/
|
||||
Kronick.initializeDraggableWindow(
|
||||
'giphyFrameWrap',
|
||||
'giphyFrameHeader',
|
||||
'giphyFramePosition'
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Chat window.
|
||||
*/
|
||||
Kronick.initializeDraggableWindow(
|
||||
'chatFrameWrap',
|
||||
'chatFrameHeader',
|
||||
'chatFramePosition'
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Screen-share window.
|
||||
*/
|
||||
Kronick.initializeDraggableWindow(
|
||||
'screenShareFrameWrap',
|
||||
'screenShareFrameHeader',
|
||||
'screenShareFramePosition'
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Bring any clicked floating window to the
|
||||
* front of the other tool windows.
|
||||
*/
|
||||
document
|
||||
.querySelectorAll(
|
||||
'.tool-frame-wrap, '
|
||||
+ '.shared-media-wrap'
|
||||
)
|
||||
.forEach(windowElement => {
|
||||
windowElement.addEventListener(
|
||||
'mousedown',
|
||||
() => {
|
||||
if (
|
||||
typeof Kronick
|
||||
.bringToolWindowToFront
|
||||
=== 'function'
|
||||
) {
|
||||
Kronick
|
||||
.bringToolWindowToFront(
|
||||
windowElement
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* Keep floating windows inside the browser
|
||||
* viewport when the browser is resized.
|
||||
*/
|
||||
window.addEventListener(
|
||||
'resize',
|
||||
() => {
|
||||
if (
|
||||
typeof Kronick
|
||||
.keepVisibleWindowsInViewport
|
||||
=== 'function'
|
||||
) {
|
||||
Kronick
|
||||
.keepVisibleWindowsInViewport();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Update the screen-share button for the
|
||||
* initial disconnected state.
|
||||
*/
|
||||
if (
|
||||
typeof Kronick
|
||||
.updateScreenShareControls
|
||||
=== 'function'
|
||||
) {
|
||||
Kronick
|
||||
.updateScreenShareControls();
|
||||
}
|
||||
|
||||
|
||||
console.log(
|
||||
'Kronick application initialized.'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Safely initialize one draggable tool window.
|
||||
*
|
||||
* Missing optional windows will be reported but will
|
||||
* not prevent the rest of the application from loading.
|
||||
*/
|
||||
Kronick.initializeDraggableWindow =
|
||||
function initializeDraggableWindow(
|
||||
windowId,
|
||||
headerId,
|
||||
storageKey
|
||||
) {
|
||||
const windowElement =
|
||||
document.getElementById(
|
||||
windowId
|
||||
);
|
||||
|
||||
const headerElement =
|
||||
document.getElementById(
|
||||
headerId
|
||||
);
|
||||
|
||||
if (
|
||||
!windowElement
|
||||
|| !headerElement
|
||||
) {
|
||||
console.debug(
|
||||
'Optional draggable window not found:',
|
||||
{
|
||||
windowId,
|
||||
headerId
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
typeof Kronick.makeToolWindowDraggable
|
||||
!== 'function'
|
||||
) {
|
||||
console.error(
|
||||
'makeToolWindowDraggable() '
|
||||
+ 'is unavailable.'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Kronick.makeToolWindowDraggable(
|
||||
windowElement,
|
||||
headerElement,
|
||||
storageKey
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Receive messages from the chat, Giphy and music
|
||||
* iframes through the central message router.
|
||||
*/
|
||||
window.addEventListener(
|
||||
'message',
|
||||
event => {
|
||||
if (
|
||||
typeof Kronick.handleWindowMessage
|
||||
!== 'function'
|
||||
) {
|
||||
console.error(
|
||||
'Window message router '
|
||||
+ 'is unavailable.'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Kronick.handleWindowMessage(
|
||||
event
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Compatibility exports.
|
||||
*
|
||||
* These allow existing inline HTML handlers such as
|
||||
* onclick="connect()" to continue working while the
|
||||
* implementations remain organized under Kronick.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* LiveKit connection controls.
|
||||
*/
|
||||
window.connect =
|
||||
function connect() {
|
||||
return Kronick.connect();
|
||||
};
|
||||
|
||||
window.disconnect =
|
||||
function disconnect() {
|
||||
return Kronick.disconnect();
|
||||
};
|
||||
|
||||
window.toggleMute =
|
||||
function toggleMute() {
|
||||
return Kronick.toggleMute();
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Music browser controls.
|
||||
*/
|
||||
window.openMusicBrowser =
|
||||
function openMusicBrowser() {
|
||||
return Kronick.openMusicBrowser();
|
||||
};
|
||||
|
||||
window.closeMusicBrowser =
|
||||
function closeMusicBrowser() {
|
||||
return Kronick.closeMusicBrowser();
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Giphy browser controls.
|
||||
*/
|
||||
window.openGiphyBrowser =
|
||||
function openGiphyBrowser(
|
||||
targetMode = 'room'
|
||||
) {
|
||||
return Kronick.openGiphyBrowser(
|
||||
targetMode
|
||||
);
|
||||
};
|
||||
|
||||
window.closeGiphyBrowser =
|
||||
function closeGiphyBrowser() {
|
||||
return Kronick.closeGiphyBrowser();
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Chat controls.
|
||||
*/
|
||||
window.openChatWindow =
|
||||
function openChatWindow() {
|
||||
return Kronick.openChatWindow();
|
||||
};
|
||||
|
||||
window.closeChatWindow =
|
||||
function closeChatWindow() {
|
||||
return Kronick.closeChatWindow();
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Shared media controls.
|
||||
*/
|
||||
window.closeSharedMedia =
|
||||
function closeSharedMedia(
|
||||
sendStop = true
|
||||
) {
|
||||
return Kronick.closeSharedMedia(
|
||||
sendStop
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Participant controls.
|
||||
*/
|
||||
window.setParticipantVolume =
|
||||
function setParticipantVolume(
|
||||
sid,
|
||||
participantKey,
|
||||
value
|
||||
) {
|
||||
return Kronick.setParticipantVolume(
|
||||
sid,
|
||||
participantKey,
|
||||
value
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Screen-share controls.
|
||||
*/
|
||||
window.toggleScreenShare =
|
||||
function toggleScreenShare() {
|
||||
return Kronick.toggleScreenShare();
|
||||
};
|
||||
|
||||
window.stopScreenShare =
|
||||
function stopScreenShare() {
|
||||
return Kronick.stopScreenShare();
|
||||
};
|
||||
|
||||
window.openScreenShareWindow =
|
||||
function openScreenShareWindow() {
|
||||
return Kronick.openScreenShareWindow();
|
||||
};
|
||||
|
||||
window.closeScreenShareWindow =
|
||||
function closeScreenShareWindow() {
|
||||
return Kronick.closeScreenShareWindow();
|
||||
};
|
||||
|
||||
/*
|
||||
* Mobile layout uses the existing connection/audio sidebar as a drawer.
|
||||
* Desktop behavior is unchanged.
|
||||
*/
|
||||
Kronick.isMobileLayout = function isMobileLayout() {
|
||||
return window.matchMedia('(max-width: 760px)').matches;
|
||||
};
|
||||
|
||||
Kronick.setMobileSidebarOpen = function setMobileSidebarOpen(open) {
|
||||
if (!Kronick.isMobileLayout()) {
|
||||
open = false;
|
||||
}
|
||||
|
||||
document.body.classList.toggle('mobile-sidebar-open', Boolean(open));
|
||||
|
||||
const button = document.getElementById('mobileAudioMenuBtn');
|
||||
if (button) {
|
||||
button.setAttribute('aria-expanded', open ? 'true' : 'false');
|
||||
button.title = open
|
||||
? 'Close connection and audio settings'
|
||||
: 'Open connection and audio settings';
|
||||
}
|
||||
};
|
||||
|
||||
Kronick.toggleMobileSidebar = function toggleMobileSidebar() {
|
||||
Kronick.setMobileSidebarOpen(
|
||||
!document.body.classList.contains('mobile-sidebar-open')
|
||||
);
|
||||
};
|
||||
|
||||
Kronick.closeMobileSidebar = function closeMobileSidebar() {
|
||||
Kronick.setMobileSidebarOpen(false);
|
||||
};
|
||||
|
||||
window.addEventListener('keydown', event => {
|
||||
if (event.key === 'Escape' && document.body.classList.contains('mobile-sidebar-open')) {
|
||||
Kronick.closeMobileSidebar();
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
if (!Kronick.isMobileLayout()) {
|
||||
Kronick.closeMobileSidebar();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user