bigbluebutton-Github/bigbluebutton-html5/app/client/globals.js

903 lines
30 KiB
JavaScript
Raw Normal View History

2016-01-13 04:15:16 +08:00
this.getBuildInformation = function() {
let copyrightYear, defaultWelcomeMessage, defaultWelcomeMessageFooter, html5ClientBuild, link, ref, ref1, ref2, ref3;
copyrightYear = ((ref = Meteor.config) != null ? ref.copyrightYear : void 0) || "DATE";
html5ClientBuild = ((ref1 = Meteor.config) != null ? ref1.html5ClientBuild : void 0) || "VERSION";
defaultWelcomeMessage = ((ref2 = Meteor.config) != null ? ref2.defaultWelcomeMessage : void 0) || "WELCOME MESSAGE";
defaultWelcomeMessageFooter = ((ref3 = Meteor.config) != null ? ref3.defaultWelcomeMessageFooter : void 0) || "WELCOME MESSAGE";
link = "<a href='http://bigbluebutton.org/' target='_blank'>http://bigbluebutton.org</a>";
return {
'copyrightYear': copyrightYear,
'html5ClientBuild': html5ClientBuild,
'defaultWelcomeMessage': defaultWelcomeMessage,
'defaultWelcomeMessageFooter': defaultWelcomeMessageFooter,
'link': link
};
};
2016-01-15 13:46:41 +08:00
// Convert a color `value` as integer to a hex color (e.g. 255 to #0000ff)
2016-01-13 04:15:16 +08:00
this.colourToHex = function(value) {
let hex;
hex = parseInt(value).toString(16);
while(hex.length < 6) {
hex = `0${hex}`;
}
return `#${hex}`;
};
2016-01-15 13:46:41 +08:00
// color can be a number (a hex converted to int) or a string (e.g. "#ffff00")
2016-01-13 04:15:16 +08:00
this.formatColor = function(color) {
if(color == null) {
2016-01-15 13:46:41 +08:00
color = "0"; // default value
2016-01-13 04:15:16 +08:00
}
if(!color.toString().match(/\#.*/)) {
color = colourToHex(color);
}
return color;
};
this.getInSession = function(k) {
return SessionAmplify.get(k);
};
2016-01-15 13:46:41 +08:00
// returns epoch in ms
2016-01-13 04:15:16 +08:00
this.getTime = function() {
return (new Date).valueOf();
};
2016-01-15 13:46:41 +08:00
// checks if the pan gesture is mostly horizontal
2016-01-13 04:15:16 +08:00
this.isPanHorizontal = function(event) {
return Math.abs(event.deltaX) > Math.abs(event.deltaY);
};
2016-01-15 13:46:41 +08:00
// helper to determine whether user has joined any type of audio
2016-01-13 04:15:16 +08:00
Handlebars.registerHelper("amIInAudio", () => {
return BBB.amIInAudio();
});
2016-01-15 13:46:41 +08:00
// helper to determine whether the user is in the listen only audio stream
2016-01-13 04:15:16 +08:00
Handlebars.registerHelper("amIListenOnlyAudio", () => {
return BBB.amIListenOnlyAudio();
});
2016-01-15 13:46:41 +08:00
// helper to determine whether the user is in the listen only audio stream
2016-01-13 04:15:16 +08:00
Handlebars.registerHelper("isMyMicLocked", () => {
return BBB.isMyMicLocked();
});
Handlebars.registerHelper("colourToHex", (_this => {
return function(value) {
return _this.window.colourToHex(value);
};
})(this));
2016-01-15 13:46:41 +08:00
Handlebars.registerHelper('equals', (a, b) => { // equals operator was dropped in Meteor's migration from Handlebars to Spacebars
2016-01-13 04:15:16 +08:00
return a === b;
});
Handlebars.registerHelper("getCurrentMeeting", () => {
return Meteor.Meetings.findOne();
});
Handlebars.registerHelper("getCurrentSlide", () => {
let result;
result = BBB.getCurrentSlide();
2016-01-15 13:46:41 +08:00
// console.log "result=#{JSON.stringify result}"
2016-01-13 04:15:16 +08:00
return result;
});
2016-01-15 13:46:41 +08:00
// Allow access through all templates
2016-01-13 04:15:16 +08:00
Handlebars.registerHelper("getInSession", k => {
return SessionAmplify.get(k);
});
Handlebars.registerHelper("getMeetingName", () => {
return BBB.getMeetingName();
});
Handlebars.registerHelper("getShapesForSlide", () => {
let currentSlide, ref;
currentSlide = BBB.getCurrentSlide();
2016-01-15 13:46:41 +08:00
// try to reuse the lines above
2016-01-13 04:15:16 +08:00
return Meteor.Shapes.find({
whiteboardId: currentSlide != null ? (ref = currentSlide.slide) != null ? ref.id : void 0 : void 0
});
});
2016-01-15 13:46:41 +08:00
// retrieves all users in the meeting
2016-01-13 04:15:16 +08:00
Handlebars.registerHelper("getUsersInMeeting", () => {
let users;
users = Meteor.Users.find().fetch();
if((users != null ? users.length : void 0) > 1) {
return getSortedUserList(users);
} else {
return users;
}
});
Handlebars.registerHelper("getWhiteboardTitle", () => {
return BBB.currentPresentationName() || "No active presentation";
2016-01-13 04:15:16 +08:00
});
Handlebars.registerHelper("getCurrentUserEmojiStatus", () => {
let ref, ref1;
return (ref = BBB.getCurrentUser()) != null ? (ref1 = ref.user) != null ? ref1.emoji_status : void 0 : void 0;
});
Handlebars.registerHelper("isCurrentUser", userId => {
let ref;
return userId === null || userId === ((ref = BBB.getCurrentUser()) != null ? ref.userId : void 0);
});
Handlebars.registerHelper("isCurrentUserMuted", () => {
return BBB.amIMuted();
});
2016-01-15 13:46:41 +08:00
//Retreives a username for a private chat tab from the database if it exists
2016-01-13 04:15:16 +08:00
Handlebars.registerHelper("privateChatName", () => {
let obj, ref;
obj = Meteor.Users.findOne({
userId: getInSession("inChatWith")
});
if(obj != null) {
return obj != null ? (ref = obj.user) != null ? ref.name : void 0 : void 0;
}
});
Handlebars.registerHelper("isCurrentUserEmojiStatusSet", () => {
return BBB.isCurrentUserEmojiStatusSet();
});
Handlebars.registerHelper("isCurrentUserSharingVideo", () => {
return BBB.amISharingVideo();
});
Handlebars.registerHelper("isCurrentUserTalking", () => {
return BBB.amITalking();
});
Handlebars.registerHelper("isCurrentUserPresenter", () => {
return BBB.isUserPresenter(getInSession('userId'));
});
Handlebars.registerHelper("isCurrentUserModerator", () => {
return BBB.getMyRole() === "MODERATOR";
});
Handlebars.registerHelper("isDisconnected", () => {
return !Meteor.status().connected;
});
Handlebars.registerHelper("isUserInAudio", userId => {
return BBB.isUserInAudio(userId);
});
Handlebars.registerHelper("isUserListenOnlyAudio", userId => {
return BBB.isUserListenOnlyAudio(userId);
});
Handlebars.registerHelper("isUserMuted", userId => {
return BBB.isUserMuted(userId);
});
Handlebars.registerHelper("isUserSharingVideo", userId => {
return BBB.isUserSharingWebcam(userId);
});
Handlebars.registerHelper("isUserTalking", userId => {
return BBB.isUserTalking(userId);
});
Handlebars.registerHelper('isMobile', () => {
return isMobile();
});
Handlebars.registerHelper('isPortraitMobile', () => {
return isPortraitMobile();
});
Handlebars.registerHelper('isMobileChromeOrFirefox', () => {
return isMobile() && ((getBrowserName() === 'Chrome') || (getBrowserName() === 'Firefox'));
});
Handlebars.registerHelper("meetingIsRecording", () => {
return BBB.isMeetingRecording();
});
Handlebars.registerHelper("messageFontSize", () => {
return {
style: `font-size: ${getInSession("messageFontSize")}px;`
};
});
Handlebars.registerHelper("pointerLocation", () => {
let currentPresentation, currentSlideDoc, pointer, presentationId, ref;
currentPresentation = Meteor.Presentations.findOne({
"presentation.current": true
});
presentationId = currentPresentation != null ? (ref = currentPresentation.presentation) != null ? ref.id : void 0 : void 0;
currentSlideDoc = Meteor.Slides.findOne({
"presentationId": presentationId,
"slide.current": true
});
pointer = Meteor.Cursor.findOne();
pointer.x = (-currentSlideDoc.slide.x_offset * 2 + currentSlideDoc.slide.width_ratio * pointer.x) / 100;
pointer.y = (-currentSlideDoc.slide.y_offset * 2 + currentSlideDoc.slide.height_ratio * pointer.y) / 100;
return pointer;
});
Handlebars.registerHelper("safeName", str => {
return safeString(str);
});
Handlebars.registerHelper("canJoinWithMic", () => {
if((BBB.isUserPresenter(getInSession('userId')) || !Meteor.config.app.listenOnly) && !BBB.isMyMicLocked()) {
return true;
} else {
return false;
}
});
Handlebars.registerHelper('containerPosition', section => {
if(getInSession('display_usersList')) {
return 'moved-to-right';
} else if(getInSession('display_menu')) {
return 'moved-to-left';
} else {
return '';
}
});
2016-01-15 13:46:41 +08:00
// vertically shrinks the whiteboard if the slide navigation controllers are present
2016-01-13 04:15:16 +08:00
Handlebars.registerHelper('whiteboardSize', section => {
if(BBB.isUserPresenter(getInSession('userId'))) {
return 'presenter-whiteboard';
} else {
if(BBB.isPollGoing(getInSession('userId'))) {
return 'poll-whiteboard';
} else {
return 'viewer-whiteboard';
}
}
});
Template.registerHelper('emojiIcons', function () {
return [
{ name: 'sad', icon: 'sad-face', title: '' },
{ name: 'happy', icon: 'happy-face', title: ''},
{ name: 'confused', icon: 'confused-face', title: ''},
{ name: 'neutral', icon: 'neutral-face', title: ''},
{ name: 'away', icon: 'clock', title: ''},
{ name: 'raiseHand', icon: 'hand', title: 'Lower your Hand'}
];
});
// scale the whiteboard to adapt to the resized window
this.scaleWhiteboard = function(callback) {
let adjustedDimensions;
adjustedDimensions = scaleSlide(getInSession('slideOriginalWidth'), getInSession('slideOriginalHeight'));
if(typeof whiteboardPaperModel !== "undefined" && whiteboardPaperModel !== null) {
whiteboardPaperModel.scale(adjustedDimensions.width, adjustedDimensions.height);
}
if(callback) {
callback();
}
};
2016-01-13 04:15:16 +08:00
this.getSortedUserList = function(users) {
if((users != null ? users.length : void 0) > 1) {
users.sort((a, b) => {
let aTime, bTime;
if(a.user.role === "MODERATOR" && b.user.role === "MODERATOR") {
if(a.user.set_emoji_time && b.user.set_emoji_time) {
aTime = a.user.set_emoji_time.getTime();
bTime = b.user.set_emoji_time.getTime();
if(aTime < bTime) {
return -1;
} else {
return 1;
}
} else if(a.user.set_emoji_time) {
return -1;
} else if(b.user.set_emoji_time) {
return 1;
}
} else if(a.user.role === "MODERATOR") {
return -1;
} else if(b.user.role === "MODERATOR") {
return 1;
} else if(a.user.set_emoji_time && b.user.set_emoji_time) {
aTime = a.user.set_emoji_time.getTime();
bTime = b.user.set_emoji_time.getTime();
if(aTime < bTime) {
return -1;
} else {
return 1;
}
} else if(a.user.set_emoji_time) {
return -1;
} else if(b.user.set_emoji_time) {
return 1;
} else if(!a.user.phone_user && !b.user.phone_user) {
} else if(!a.user.phone_user) {
return -1;
} else if(!b.user.phone_user) {
return 1;
}
2016-01-15 13:46:41 +08:00
//Check name (case-insensitive) in the event of a tie up above. If the name
//is the same then use userID which should be unique making the order the same
//across all clients.
2016-01-13 04:15:16 +08:00
if(a.user._sort_name < b.user._sort_name) {
return -1;
} else if(a.user._sort_name > b.user._sort_name) {
return 1;
} else if(a.user.userid.toLowerCase() > b.user.userid.toLowerCase()) {
return -1;
} else if(a.user.userid.toLowerCase() < b.user.userid.toLowerCase()) {
return 1;
}
});
}
return users;
};
2016-01-15 13:46:41 +08:00
// transform plain text links into HTML tags compatible with Flash client
2016-01-13 04:15:16 +08:00
this.linkify = function(str) {
return str = str.replace(re_weburl, "<a href='event:$&'><u>$&</u></a>");
};
this.setInSession = function(k, v) {
return SessionAmplify.set(k, v);
};
this.safeString = function(str) {
if(typeof str === 'string') {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
};
2016-01-15 13:46:41 +08:00
this.toggleCam = function(event) {
// Meteor.Users.update {_id: context._id} , {$set:{"user.sharingVideo": !context.sharingVideo}}
// Meteor.call('userToggleCam', context._id, !context.sharingVideo)
};
2016-01-13 04:15:16 +08:00
this.toggleChatbar = function() {
setInSession("display_chatbar", !getInSession("display_chatbar"));
if(!getInSession("display_chatbar")) {
$('#whiteboard').css('width', '100%');
$('#whiteboard .ui-resizable-handle').css('display', 'none');
} else {
$('#whiteboard').css('width', '');
$('#whiteboard .ui-resizable-handle').css('display', '');
}
return setTimeout(scaleWhiteboard, 0);
};
this.toggleMic = function(event) {
return BBB.toggleMyMic();
};
this.toggleUsersList = function() {
if($('.userlistMenu').hasClass('hiddenInLandscape')) {
$('.userlistMenu').removeClass('hiddenInLandscape');
} else {
$('.userlistMenu').addClass('hiddenInLandscape');
}
return setTimeout(scaleWhiteboard, 0);
};
this.populateNotifications = function(msg) {
let chat, chats, initChats, j, l, len, len1, myPrivateChats, myUserId, new_msg_userid, results, u, uniqueArray, users;
myUserId = getInSession("userId");
users = Meteor.Users.find().fetch();
2016-01-15 13:46:41 +08:00
// assuming that I only have access only to private messages where I am the sender or the recipient
2016-01-13 04:15:16 +08:00
myPrivateChats = Meteor.Chat.find({
'message.chat_type': 'PRIVATE_CHAT'
}).fetch();
uniqueArray = [];
for(j = 0, len = myPrivateChats.length; j < len; j++) {
chat = myPrivateChats[j];
if(chat.message.to_userid === myUserId) {
uniqueArray.push({
userId: chat.message.from_userid,
username: chat.message.from_username
});
}
if(chat.message.from_userid === myUserId) {
uniqueArray.push({
userId: chat.message.to_userid,
username: chat.message.to_username
});
}
}
2016-01-15 13:46:41 +08:00
//keep unique entries only
2016-01-13 04:15:16 +08:00
uniqueArray = uniqueArray.filter((itm, i, a) => {
return i === a.indexOf(itm);
});
if(msg.message.to_userid === myUserId) {
new_msg_userid = msg.message.from_userid;
}
if(msg.message.from_userid === myUserId) {
new_msg_userid = msg.message.to_userid;
}
chats = getInSession('chats');
if(chats === void 0) {
initChats = [
{
userId: "PUBLIC_CHAT",
gotMail: false,
number: 0
}
];
setInSession('chats', initChats);
}
results = [];
2016-01-15 13:46:41 +08:00
//insert the unique entries in the collection
2016-01-13 04:15:16 +08:00
for(l = 0, len1 = uniqueArray.length; l < len1; l++) {
u = uniqueArray[l];
chats = getInSession('chats');
if(chats.filter(chat => {
return chat.userId === u.userId;
}).length === 0 && u.userId === new_msg_userid) {
chats.push({
userId: u.userId,
gotMail: false,
number: 0
});
results.push(setInSession('chats', chats));
} else {
results.push(void 0);
}
}
return results;
};
this.toggleShield = function() {
if(parseFloat($('.shield').css('opacity')) === 0.5) {
$('.shield').css('opacity', '');
}
if(!$('.shield').hasClass('darken') && !$('.shield').hasClass('animatedShield')) {
return $('.shield').addClass('darken');
} else {
$('.shield').removeClass('darken');
return $('.shield').removeClass('animatedShield');
}
};
this.removeFullscreenStyles = function() {
$('#whiteboard-paper').removeClass('vertically-centered');
$('#chat').removeClass('invisible');
$('#users').removeClass('invisible');
$('#navbar').removeClass('invisible');
$('.FABTriggerButton').removeClass('invisible');
$('.fullscreenButton').removeClass('exitFullscreenButton');
$('.fullscreenButton').addClass('whiteboardFullscreenButton');
$('.fullscreenButton i').removeClass('ion-arrow-shrink');
return $('.fullscreenButton i').addClass('ion-arrow-expand');
};
this.enterWhiteboardFullscreen = function() {
let element;
element = document.getElementById('whiteboard');
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
$('.fullscreenButton').addClass('iconFirefox');
} else if(element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
$('.fullscreenButton').addClass('iconChrome');
} else if(element.msRequestFullscreen) {
element.msRequestFullscreen();
}
$('#chat').addClass('invisible');
$('#users').addClass('invisible');
$('#navbar').addClass('invisible');
$('.FABTriggerButton').addClass('invisible');
$('.fullscreenButton').removeClass('whiteboardFullscreenButton');
$('.fullscreenButton').addClass('exitFullscreenButton');
$('.fullscreenButton i').removeClass('ion-arrow-expand');
$('.fullscreenButton i').addClass('ion-arrow-shrink');
$('#whiteboard-paper').addClass('vertically-centered');
$('#whiteboard').bind('webkitfullscreenchange', e => {
if(document.webkitFullscreenElement === null) {
$('#whiteboard').unbind('webkitfullscreenchange');
$('.fullscreenButton').removeClass('iconChrome');
removeFullscreenStyles();
return scaleWhiteboard();
}
});
return $(document).bind('mozfullscreenchange', e => {
if(document.mozFullScreenElement === null) {
$(document).unbind('mozfullscreenchange');
$('.fullscreenButton').removeClass('iconFirefox');
removeFullscreenStyles();
return scaleWhiteboard();
}
});
};
this.closeMenus = function() {
if($('.userlistMenu').hasClass('menuOut')) {
return toggleUserlistMenu();
} else if($('.settingsMenu').hasClass('menuOut')) {
return toggleSettingsMenu();
}
};
2016-01-15 13:46:41 +08:00
// Periodically check the status of the WebRTC call, when a call has been established attempt to hangup,
// retry if a call is in progress, send the leave voice conference message to BBB
2016-01-13 04:15:16 +08:00
this.exitVoiceCall = function(event, afterExitCall) {
let checkToHangupCall, hangupCallback;
2016-01-15 13:46:41 +08:00
// To be called when the hangup is initiated
2016-01-13 04:15:16 +08:00
hangupCallback = function() {
return console.log("Exiting Voice Conference");
};
2016-01-15 13:46:41 +08:00
// Checks periodically until a call is established so we can successfully end the call
// clean state
2016-01-13 04:15:16 +08:00
getInSession("triedHangup", false);
2016-01-15 13:46:41 +08:00
// function to initiate call
2016-01-13 04:15:16 +08:00
(checkToHangupCall = function(context) {
2016-01-15 13:46:41 +08:00
// if an attempt to hang up the call is made when the current session is not yet finished, the request has no effect
// keep track in the session if we haven't tried a hangup
2016-01-13 04:15:16 +08:00
if(BBB.getCallStatus() !== null && !getInSession("triedHangup")) {
console.log("Attempting to hangup on WebRTC call");
if(BBB.amIListenOnlyAudio()) {
Meteor.call(
'listenOnlyRequestToggle',
BBB.getMeetingId(),
getInSession("userId"),
getInSession("authToken"),
false
);
}
BBB.leaveVoiceConference(hangupCallback);
getInSession("triedHangup", true);
notification_WebRTCAudioExited();
if(afterExitCall) {
return afterExitCall(this, Meteor.config.app.listenOnly);
}
} else {
console.log(
`RETRYING hangup on WebRTC call in ${Meteor.config.app.WebRTCHangupRetryInterval} ms`
);
return setTimeout(checkToHangupCall, Meteor.config.app.WebRTCHangupRetryInterval);
}
2016-01-15 13:46:41 +08:00
})(this); // automatically run function
2016-01-13 04:15:16 +08:00
return false;
};
2016-01-15 13:46:41 +08:00
// close the daudio UI, then join the conference. If listen only send the request to the server
2016-01-13 04:15:16 +08:00
this.joinVoiceCall = function(event, arg) {
let isListenOnly, joinCallback;
isListenOnly = (arg != null ? arg : {}).isListenOnly;
if(!isWebRTCAvailable()) {
notification_WebRTCNotSupported();
return;
}
if(isListenOnly == null) {
isListenOnly = true;
}
2016-01-15 13:46:41 +08:00
// create voice call params
2016-01-13 04:15:16 +08:00
joinCallback = function(message) {
return console.log("Beginning WebRTC Conference Call");
};
notification_WebRTCAudioJoining();
if(isListenOnly) {
Meteor.call(
'listenOnlyRequestToggle',
BBB.getMeetingId(),
getInSession("userId"),
getInSession("authToken"),
true
);
}
2016-01-15 13:46:41 +08:00
BBB.joinVoiceConference(joinCallback, isListenOnly); // make the call //TODO should we apply role permissions to this action?
2016-01-13 04:15:16 +08:00
return false;
};
2016-01-15 13:46:41 +08:00
// Starts the entire logout procedure.
// meeting: the meeting the user is in
// the user's userId
2016-01-13 04:15:16 +08:00
this.userLogout = function(meeting, user) {
Meteor.call("userLogout", meeting, user, getInSession("authToken"));
console.log("logging out");
2016-01-15 13:46:41 +08:00
return clearSessionVar(document.location = getInSession('logoutURL')); // navigate to logout
2016-01-13 04:15:16 +08:00
};
this.kickUser = function(meetingId, toKickUserId, requesterUserId, authToken) {
return Meteor.call("kickUser", meetingId, toKickUserId, requesterUserId, authToken);
};
this.setUserPresenter = function(
meetingId,
newPresenterId,
requesterSetPresenter,
newPresenterName,
authToken) {
return Meteor.call("setUserPresenter", meetingId, newPresenterId, requesterSetPresenter, newPresenterName, authToken);
};
2016-01-15 13:46:41 +08:00
// Clear the local user session
2016-01-13 04:15:16 +08:00
this.clearSessionVar = function(callback) {
amplify.store('authToken', null);
2016-01-16 00:41:16 +08:00
amplify.store('bbbServerVersion', null);
2016-01-13 04:15:16 +08:00
amplify.store('chats', null);
amplify.store('dateOfBuild', null);
amplify.store('display_chatPane', null);
amplify.store('display_chatbar', null);
amplify.store('display_navbar', null);
amplify.store('display_usersList', null);
amplify.store('display_whiteboard', null);
amplify.store('inChatWith', null);
amplify.store('logoutURL', null);
amplify.store('meetingId', null);
amplify.store('messageFontSize', null);
amplify.store('tabsRenderedTime', null);
amplify.store('userId', null);
amplify.store('display_menu', null);
if(callback != null) {
return callback();
}
};
2016-01-15 13:46:41 +08:00
// assign the default values for the Session vars
2016-01-13 04:15:16 +08:00
this.setDefaultSettings = function() {
let initChats;
setInSession("display_navbar", true);
setInSession("display_chatbar", true);
setInSession("display_whiteboard", true);
setInSession("display_chatPane", true);
2016-01-15 13:46:41 +08:00
//if it is a desktop version of the client
2016-01-13 04:15:16 +08:00
if(isPortraitMobile() || isLandscapeMobile()) {
setInSession("messageFontSize", Meteor.config.app.mobileFont);
2016-01-15 13:46:41 +08:00
} else { //if this is a mobile version of the client
2016-01-13 04:15:16 +08:00
setInSession("messageFontSize", Meteor.config.app.desktopFont);
}
setInSession('display_slidingMenu', false);
setInSession('display_hiddenNavbarSection', false);
if(isLandscape()) {
setInSession('display_usersList', true);
} else {
setInSession('display_usersList', false);
}
setInSession('display_menu', false);
setInSession('chatInputMinHeight', 0);
2016-01-15 13:46:41 +08:00
//keep notifications and an opened private chat tab if page was refreshed
//reset to default if that's a new user
2016-01-13 04:15:16 +08:00
if(loginOrRefresh()) {
initChats = [
{
userId: "PUBLIC_CHAT",
gotMail: false,
number: 0
}
];
setInSession('chats', initChats);
setInSession("inChatWith", 'PUBLIC_CHAT');
}
2016-01-15 13:46:41 +08:00
return TimeSync.loggingEnabled = false; // suppresses the log messages from timesync
2016-01-13 04:15:16 +08:00
};
2016-01-15 13:46:41 +08:00
//true if it is a new user, false if the client was just refreshed
2016-01-13 04:15:16 +08:00
this.loginOrRefresh = function() {
let checkId, userId;
userId = getInSession('userId');
checkId = getInSession('checkId');
if(checkId === void 0) {
setInSession('checkId', userId);
return true;
} else if(userId !== checkId) {
setInSession('checkId', userId);
return true;
} else {
return false;
}
};
this.onLoadComplete = function() {
let ref;
document.title = `BigBlueButton ${(ref = BBB.getMeetingName()) != null ? ref : 'HTML5'}`;
setDefaultSettings();
Meteor.Users.find().observe({
removed(oldDocument) {
if(oldDocument.userId === getInSession('userId')) {
return document.location = getInSession('logoutURL');
}
}
});
return Meteor.Users.find().observe({
changed(newUser, oldUser) {
if(Meteor.config.app.listenOnly === true && newUser.user.presenter === false && oldUser.user.presenter === true && BBB.getCurrentUser().userId === newUser.userId && oldUser.user.listenOnly === false) {
return exitVoiceCall(this, joinVoiceCall);
}
}
});
};
2016-01-15 13:46:41 +08:00
// Detects a mobile device
2016-01-13 04:15:16 +08:00
this.isMobile = function() {
2016-01-15 13:46:41 +08:00
return navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/iPhone|iPad|iPod/i) ||
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/Windows Phone/i) ||
navigator.userAgent.match(/IEMobile/i) ||
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/webOS/i);
2016-01-13 04:15:16 +08:00
};
this.isLandscape = function() {
2016-01-15 13:46:41 +08:00
return !isMobile() &&
window.matchMedia('(orientation: landscape)').matches && // browser is landscape
window.matchMedia('(min-device-aspect-ratio: 1/1)').matches; // device is landscape
2016-01-13 04:15:16 +08:00
};
this.isPortrait = function() {
2016-01-15 13:46:41 +08:00
return !isMobile() &&
window.matchMedia('(orientation: portrait)').matches && // browser is portrait
window.matchMedia('(min-device-aspect-ratio: 1/1)').matches; // device is landscape
2016-01-13 04:15:16 +08:00
};
2016-01-15 13:46:41 +08:00
// Checks if the view is portrait and a mobile device is being used
2016-01-13 04:15:16 +08:00
this.isPortraitMobile = function() {
2016-01-15 13:46:41 +08:00
return isMobile() &&
window.matchMedia('(orientation: portrait)').matches && // browser is portrait
window.matchMedia('(max-device-aspect-ratio: 1/1)').matches; // device is portrait
2016-01-13 04:15:16 +08:00
};
2016-01-15 13:46:41 +08:00
// Checks if the view is landscape and mobile device is being used
2016-01-13 04:15:16 +08:00
this.isLandscapeMobile = function() {
2016-01-15 13:46:41 +08:00
return isMobile() &&
window.matchMedia('(orientation: landscape)').matches && // browser is landscape
window.matchMedia('(min-device-aspect-ratio: 1/1)').matches; // device is landscape
2016-01-13 04:15:16 +08:00
};
this.isLandscapePhone = function() {
2016-01-15 13:46:41 +08:00
// @phone-landscape media query:
return window.matchMedia('(orientation: landscape)').matches &&
window.matchMedia('(min-device-aspect-ratio: 1/1)').matches &&
window.matchMedia('(max-device-width: 959px)').matches;
2016-01-13 04:15:16 +08:00
};
this.isPortraitPhone = function() {
2016-01-15 13:46:41 +08:00
// @phone-portrait media query:
return (window.matchMedia('(orientation: portrait)').matches &&
window.matchMedia('(max-device-aspect-ratio: 1/1)').matches &&
window.matchMedia('(max-device-width: 480px)').matches) ||
// @phone-portrait-with-keyboard media query:
(window.matchMedia('(orientation: landscape)').matches &&
window.matchMedia('(max-device-aspect-ratio: 1/1)').matches &&
window.matchMedia('(max-device-width: 480px)').matches);
2016-01-13 04:15:16 +08:00
};
this.isPhone = function() {
return isLandscapePhone() || isPortraitPhone();
};
2016-01-15 13:46:41 +08:00
// The webpage orientation is now landscape
2016-01-13 04:15:16 +08:00
this.orientationBecameLandscape = function() {
return adjustChatInputHeight();
};
2016-01-15 13:46:41 +08:00
// The webpage orientation is now portrait
2016-01-13 04:15:16 +08:00
this.orientationBecamePortrait = function() {
return adjustChatInputHeight();
};
2016-01-15 13:46:41 +08:00
// Checks if only one panel (userlist/whiteboard/chatbar) is currently open
2016-01-13 04:15:16 +08:00
this.isOnlyOnePanelOpen = function() {
2016-01-15 13:46:41 +08:00
//return (getInSession("display_usersList") ? 1 : 0) + (getInSession("display_whiteboard") ? 1 : 0) + (getInSession("display_chatbar") ? 1 : 0) === 1
2016-01-13 04:15:16 +08:00
return getInSession("display_usersList") + getInSession("display_whiteboard") + getInSession("display_chatbar") === 1;
};
2016-01-15 13:46:41 +08:00
// determines which browser is being used
2016-01-13 04:15:16 +08:00
this.getBrowserName = function() {
if(navigator.userAgent.match(/Chrome/i)) {
return 'Chrome';
} else if(navigator.userAgent.match(/Firefox/i)) {
return 'Firefox';
} else if(navigator.userAgent.match(/Safari/i)) {
return 'Safari';
} else if(navigator.userAgent.match(/Trident/i)) {
return 'IE';
} else {
return null;
}
};
this.scrollChatDown = function() {
let ref;
return $('#chatbody').scrollTop((ref = $('#chatbody')[0]) != null ? ref.scrollHeight : void 0);
};
2016-01-15 13:46:41 +08:00
// changes the height of the chat input area if needed (based on the textarea content)
2016-01-13 04:15:16 +08:00
this.adjustChatInputHeight = function() {
let projectedHeight, ref;
if(isLandscape()) {
$('#newMessageInput').css('height', 'auto');
projectedHeight = $('#newMessageInput')[0].scrollHeight + 23;
if(projectedHeight !== $('.panel-footer').height() && projectedHeight >= getInSession('chatInputMinHeight')) {
2016-01-15 13:46:41 +08:00
$('#newMessageInput').css('overflow', 'hidden'); // prevents a scroll bar
// resizes the chat input area
2016-01-13 04:15:16 +08:00
$('.panel-footer').css('top', `${-(projectedHeight - 70)}px`);
$('.panel-footer').css('height', `${projectedHeight}px`);
2016-01-15 13:46:41 +08:00
2016-01-13 04:15:16 +08:00
$('#newMessageInput').height($('#newMessageInput')[0].scrollHeight);
2016-01-15 13:46:41 +08:00
// resizes the chat messages container
2016-01-13 04:15:16 +08:00
$('#chatbody').height($('#chat').height() - projectedHeight - 45);
$('#chatbody').scrollTop((ref = $('#chatbody')[0]) != null ? ref.scrollHeight : void 0);
}
return $('#newMessageInput').css('height', '');
} else if(isPortrait()) {
$('.panel-footer').attr('style', '');
$('#chatbody').attr('style', '');
return $('#newMessageInput').attr('style', '');
}
};
this.toggleEmojisFAB = function() {
if($('.FABContainer').hasClass('openedFAB')) {
$('.FABContainer > button:nth-child(2)').css('opacity', $('.FABContainer > button:nth-child(2)').css('opacity'));
$('.FABContainer > button:nth-child(3)').css('opacity', $('.FABContainer > button:nth-child(3)').css('opacity'));
$('.FABContainer > button:nth-child(4)').css('opacity', $('.FABContainer > button:nth-child(4)').css('opacity'));
$('.FABContainer > button:nth-child(5)').css('opacity', $('.FABContainer > button:nth-child(5)').css('opacity'));
$('.FABContainer > button:nth-child(6)').css('opacity', $('.FABContainer > button:nth-child(6)').css('opacity'));
$('.FABContainer > button:nth-child(7)').css('opacity', $('.FABContainer > button:nth-child(7)').css('opacity'));
$('.FABContainer').removeClass('openedFAB');
return $('.FABContainer').addClass('closedFAB');
} else {
$('.FABContainer > button:nth-child(2)').css('opacity', $('.FABContainer > button:nth-child(2)').css('opacity'));
$('.FABContainer > button:nth-child(3)').css('opacity', $('.FABContainer > button:nth-child(3)').css('opacity'));
$('.FABContainer > button:nth-child(4)').css('opacity', $('.FABContainer > button:nth-child(4)').css('opacity'));
$('.FABContainer > button:nth-child(5)').css('opacity', $('.FABContainer > button:nth-child(5)').css('opacity'));
$('.FABContainer > button:nth-child(6)').css('opacity', $('.FABContainer > button:nth-child(6)').css('opacity'));
$('.FABContainer > button:nth-child(7)').css('opacity', $('.FABContainer > button:nth-child(7)').css('opacity'));
$('.FABContainer').removeClass('closedFAB');
return $('.FABContainer').addClass('openedFAB');
}
};
this.toggleUserlistMenu = function() {
2016-01-15 13:46:41 +08:00
// menu
2016-01-13 04:15:16 +08:00
if($('.userlistMenu').hasClass('menuOut')) {
$('.userlistMenu').removeClass('menuOut');
} else {
$('.userlistMenu').addClass('menuOut');
}
2016-01-15 13:46:41 +08:00
// icon
2016-01-13 04:15:16 +08:00
if($('.toggleUserlistButton').hasClass('menuToggledOn')) {
return $('.toggleUserlistButton').removeClass('menuToggledOn');
} else {
return $('.toggleUserlistButton').addClass('menuToggledOn');
}
};
this.toggleSettingsMenu = function() {
2016-01-15 13:46:41 +08:00
// menu
2016-01-13 04:15:16 +08:00
if($('.settingsMenu').hasClass('menuOut')) {
$('.settingsMenu').removeClass('menuOut');
} else {
$('.settingsMenu').addClass('menuOut');
}
2016-01-15 13:46:41 +08:00
// icon
2016-01-13 04:15:16 +08:00
if($('.toggleMenuButton').hasClass('menuToggledOn')) {
return $('.toggleMenuButton').removeClass('menuToggledOn');
} else {
return $('.toggleMenuButton').addClass('menuToggledOn');
}
};