Changeset View
Changeset View
Standalone View
Standalone View
src/resources/js/meet/app.js
Show All 36 Lines | function Meet(container) | ||||
let microphones = [] // List of user audio devices | let microphones = [] // List of user audio devices | ||||
let connections = {} // Connected users in the session | let connections = {} // Connected users in the session | ||||
let containerWidth | let containerWidth | ||||
let containerHeight | let containerHeight | ||||
let chatCount = 0 | let chatCount = 0 | ||||
let volumeElement | let volumeElement | ||||
let subscribersContainer | let subscribersContainer | ||||
let scrollStop | |||||
OV = new OpenVidu() | OV = ovInit() | ||||
// If there's anything to do, do it here. | |||||
//OV.setAdvancedConfiguration(config) | |||||
// Disable all logging except errors | |||||
// OV.enableProdMode() | |||||
// Disconnect participant when browser's window close | // Disconnect participant when browser's window close | ||||
window.addEventListener('beforeunload', () => { | window.addEventListener('beforeunload', () => { | ||||
leaveRoom() | leaveRoom() | ||||
}) | }) | ||||
window.addEventListener('resize', resize) | window.addEventListener('resize', resize) | ||||
// Public methods | // Public methods | ||||
this.isScreenSharingSupported = isScreenSharingSupported | this.isScreenSharingSupported = isScreenSharingSupported | ||||
this.joinRoom = joinRoom | this.joinRoom = joinRoom | ||||
this.leaveRoom = leaveRoom | this.leaveRoom = leaveRoom | ||||
this.setupStart = setupStart | this.setupStart = setupStart | ||||
this.setupStop = setupStop | this.setupStop = setupStop | ||||
this.setupSetAudioDevice = setupSetAudioDevice | this.setupSetAudioDevice = setupSetAudioDevice | ||||
this.setupSetVideoDevice = setupSetVideoDevice | this.setupSetVideoDevice = setupSetVideoDevice | ||||
this.switchAudio = switchAudio | this.switchAudio = switchAudio | ||||
this.switchScreen = switchScreen | this.switchScreen = switchScreen | ||||
this.switchVideo = switchVideo | this.switchVideo = switchVideo | ||||
this.updateSession = updateSession | this.updateSession = updateSession | ||||
/** | /** | ||||
* Initialize OpenVidu instance | |||||
*/ | |||||
function ovInit() | |||||
{ | |||||
let ov = new OpenVidu() | |||||
// If there's anything to do, do it here. | |||||
//ov.setAdvancedConfiguration(config) | |||||
// Disable all logging except errors | |||||
// ov.enableProdMode() | |||||
return ov | |||||
} | |||||
/** | |||||
* Join the room session | * Join the room session | ||||
* | * | ||||
* @param data Session metadata and event handlers (token, shareToken, nickname, role, connections, | * @param data Session metadata and event handlers (token, shareToken, nickname, role, connections, | ||||
* chatElement, menuElement, onDestroy, onJoinRequest, onDismiss, onConnectionChange, | * chatElement, menuElement, onDestroy, onJoinRequest, onDismiss, onConnectionChange, | ||||
* onSessionDataUpdate, onMediaSetup) | * onSessionDataUpdate, onMediaSetup) | ||||
*/ | */ | ||||
function joinRoom(data) { | function joinRoom(data) { | ||||
resize(); | resize(); | ||||
▲ Show 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | function Meet(container) | ||||
/** | /** | ||||
* Setup the chat UI | * Setup the chat UI | ||||
*/ | */ | ||||
function setupChat() { | function setupChat() { | ||||
// The UI elements are created in the vue template | // The UI elements are created in the vue template | ||||
// Here we add a logic for how they work | // Here we add a logic for how they work | ||||
const chat = $(sessionData.chatElement).find('.chat').get(0) | |||||
const textarea = $(sessionData.chatElement).find('textarea') | const textarea = $(sessionData.chatElement).find('textarea') | ||||
const button = $(sessionData.menuElement).find('.link-chat') | const button = $(sessionData.menuElement).find('.link-chat') | ||||
textarea.on('keydown', e => { | textarea.on('keydown', e => { | ||||
if (e.keyCode == 13 && !e.shiftKey) { | if (e.keyCode == 13 && !e.shiftKey) { | ||||
if (textarea.val().length) { | if (textarea.val().length) { | ||||
signalChat(textarea.val()) | signalChat(textarea.val()) | ||||
textarea.val('') | textarea.val('') | ||||
} | } | ||||
return false | return false | ||||
} | } | ||||
}) | }) | ||||
// Add an element for the count of unread messages on the chat button | // Add an element for the count of unread messages on the chat button | ||||
button.append('<span class="badge badge-dark blinker">') | button.append('<span class="badge badge-dark blinker">') | ||||
.on('click', () => { | .on('click', () => { | ||||
button.find('.badge').text('') | button.find('.badge').text('') | ||||
chatCount = 0 | chatCount = 0 | ||||
// When opening the chat scroll it to the bottom, or we shouldn't? | |||||
mollekopf: "or we shouldn't?" can be removed from the comment I think. | |||||
scrollStop = false | |||||
chat.scrollTop = chat.scrollHeight | |||||
}) | |||||
$(chat).on('scroll', event => { | |||||
// Detect manual scrollbar moves, disable auto-scrolling until | |||||
// the scrollbar is positioned on the element bottom again | |||||
scrollStop = chat.scrollTop + chat.offsetHeight < chat.scrollHeight | |||||
}) | }) | ||||
} | } | ||||
/** | /** | ||||
* Signal events handler | * Signal events handler | ||||
*/ | */ | ||||
function signalEventHandler(signal) { | function signalEventHandler(signal) { | ||||
let conn, data | let conn, data | ||||
let connId = signal.from ? signal.from.connectionId : null | let connId = signal.from ? signal.from.connectionId : null | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | function pushChatMessage(data) { | ||||
if (!isSelf) { | if (!isSelf) { | ||||
chatCount++ | chatCount++ | ||||
} | } | ||||
} else { | } else { | ||||
chatCount = 0 | chatCount = 0 | ||||
} | } | ||||
$(sessionData.menuElement).find('.link-chat .badge').text(chatCount ? chatCount : '') | $(sessionData.menuElement).find('.link-chat .badge').text(chatCount ? chatCount : '') | ||||
// Scroll the chat element to the end | |||||
if (!scrollStop) { | |||||
chat.get(0).scrollTop = chat.get(0).scrollHeight | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* Send the user properties update signal to other participants | * Send the user properties update signal to other participants | ||||
* | * | ||||
* @param connection Optional connection to which the signal will be sent | * @param connection Optional connection to which the signal will be sent | ||||
* If not specified the signal is sent to all participants | * If not specified the signal is sent to all participants | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 574 Lines • ▼ Show 20 Lines | |||||
function screenConnect(callback) { | function screenConnect(callback) { | ||||
if (!sessionData.shareToken) { | if (!sessionData.shareToken) { | ||||
return false | return false | ||||
} | } | ||||
let gotSession = !!screenSession | let gotSession = !!screenSession | ||||
if (!screenOV) { | if (!screenOV) { | ||||
screenOV = new OpenVidu() | screenOV = ovInit() | ||||
} | } | ||||
// Init screen sharing session | // Init screen sharing session | ||||
if (!gotSession) { | if (!gotSession) { | ||||
screenSession = screenOV.initSession(); | screenSession = screenOV.initSession(); | ||||
} | } | ||||
let successFunc = function() { | let successFunc = function() { | ||||
▲ Show 20 Lines • Show All 137 Lines • Show Last 20 Lines |
"or we shouldn't?" can be removed from the comment I think.