2018-01-11 09:15:44 +08:00
|
|
|
import { Tracker } from 'meteor/tracker';
|
2019-11-28 21:13:06 +08:00
|
|
|
import { Session } from 'meteor/session';
|
|
|
|
import Settings from '/imports/ui/services/settings';
|
2018-01-13 02:39:16 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2019-11-28 21:13:06 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import VideoStreams from '/imports/api/video-streams';
|
2018-04-09 22:39:27 +08:00
|
|
|
import UserListService from '/imports/ui/components/user-list/service';
|
2019-11-28 21:13:06 +08:00
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2019-11-30 05:48:04 +08:00
|
|
|
import { monitorVideoConnection } from '/imports/utils/stats';
|
2019-12-21 03:47:30 +08:00
|
|
|
import browser from 'browser-detect';
|
2020-06-15 03:13:47 +08:00
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2019-11-28 21:13:06 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2020-08-19 01:00:47 +08:00
|
|
|
import _ from 'lodash';
|
2019-11-28 21:13:06 +08:00
|
|
|
|
|
|
|
const CAMERA_PROFILES = Meteor.settings.public.kurento.cameraProfiles;
|
2019-12-19 01:44:56 +08:00
|
|
|
const MULTIPLE_CAMERAS = Meteor.settings.public.app.enableMultipleCameras;
|
|
|
|
const SKIP_VIDEO_PREVIEW = Meteor.settings.public.kurento.skipVideoPreview;
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
const SFU_URL = Meteor.settings.public.kurento.wsUrl;
|
2019-08-10 06:28:49 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|
|
|
const ROLE_VIEWER = Meteor.settings.public.user.role_viewer;
|
2019-11-30 05:48:04 +08:00
|
|
|
const ENABLE_NETWORK_MONITORING = Meteor.settings.public.networkMonitoring.enableNetworkMonitoring;
|
2020-06-16 04:51:46 +08:00
|
|
|
const MIRROR_WEBCAM = Meteor.settings.public.app.mirrorOwnWebcam;
|
2020-05-27 01:05:04 +08:00
|
|
|
const CAMERA_QUALITY_THRESHOLDS = Meteor.settings.public.kurento.cameraQualityThresholds.thresholds || [];
|
2020-08-19 01:00:47 +08:00
|
|
|
const {
|
|
|
|
enabled: PAGINATION_ENABLED,
|
2020-08-20 23:43:02 +08:00
|
|
|
pageChangeDebounceTime: PAGE_CHANGE_DEBOUNCE_TIME,
|
2020-08-19 01:00:47 +08:00
|
|
|
desktopPageSizes: DESKTOP_PAGE_SIZES,
|
|
|
|
mobilePageSizes: MOBILE_PAGE_SIZES,
|
|
|
|
} = Meteor.settings.public.kurento.pagination;
|
2019-08-10 06:28:49 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
const TOKEN = '_';
|
2019-08-10 06:28:49 +08:00
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
class VideoService {
|
|
|
|
constructor() {
|
|
|
|
this.defineProperties({
|
2019-11-28 21:13:06 +08:00
|
|
|
isConnecting: false,
|
2018-01-11 09:15:44 +08:00
|
|
|
isConnected: false,
|
2020-08-19 01:00:47 +08:00
|
|
|
currentVideoPageIndex: 0,
|
|
|
|
numberOfPages: 0,
|
2018-01-11 09:15:44 +08:00
|
|
|
});
|
2020-03-27 05:15:41 +08:00
|
|
|
this.skipVideoPreview = null;
|
|
|
|
this.userParameterProfile = null;
|
2019-12-21 03:47:30 +08:00
|
|
|
const BROWSER_RESULTS = browser();
|
|
|
|
this.isMobile = BROWSER_RESULTS.mobile || BROWSER_RESULTS.os.includes('Android');
|
|
|
|
this.isSafari = BROWSER_RESULTS.name === 'safari';
|
2020-08-19 21:56:22 +08:00
|
|
|
this.pageChangeLocked = false;
|
2019-12-21 03:47:30 +08:00
|
|
|
|
|
|
|
this.numberOfDevices = 0;
|
|
|
|
|
|
|
|
this.updateNumberOfDevices = this.updateNumberOfDevices.bind(this);
|
2019-12-21 04:02:34 +08:00
|
|
|
// Safari doesn't support ondevicechange
|
|
|
|
if (!this.isSafari) {
|
|
|
|
navigator.mediaDevices.ondevicechange = (event) => this.updateNumberOfDevices();
|
|
|
|
}
|
2019-12-21 03:47:30 +08:00
|
|
|
this.updateNumberOfDevices();
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
2017-09-20 11:12:10 +08:00
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
defineProperties(obj) {
|
|
|
|
Object.keys(obj).forEach((key) => {
|
|
|
|
const privateKey = `_${key}`;
|
|
|
|
this[privateKey] = {
|
|
|
|
value: obj[key],
|
|
|
|
tracker: new Tracker.Dependency(),
|
|
|
|
};
|
2017-09-20 11:12:10 +08:00
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
Object.defineProperty(this, key, {
|
|
|
|
set: (value) => {
|
|
|
|
this[privateKey].value = value;
|
|
|
|
this[privateKey].tracker.changed();
|
|
|
|
},
|
|
|
|
get: () => {
|
|
|
|
this[privateKey].tracker.depend();
|
|
|
|
return this[privateKey].value;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2020-05-09 00:43:29 +08:00
|
|
|
fetchNumberOfDevices(devices) {
|
|
|
|
const deviceIds = [];
|
|
|
|
devices.forEach(d => {
|
|
|
|
const validDeviceId = d.deviceId !== '' && !deviceIds.includes(d.deviceId)
|
|
|
|
if (d.kind === 'videoinput' && validDeviceId) {
|
|
|
|
deviceIds.push(d.deviceId);
|
|
|
|
}
|
2019-12-21 03:47:30 +08:00
|
|
|
});
|
2020-05-09 00:43:29 +08:00
|
|
|
|
|
|
|
return deviceIds.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateNumberOfDevices(devices = null) {
|
|
|
|
if (devices) {
|
|
|
|
this.numberOfDevices = this.fetchNumberOfDevices(devices);
|
|
|
|
} else {
|
|
|
|
navigator.mediaDevices.enumerateDevices().then(devices => {
|
|
|
|
this.numberOfDevices = this.fetchNumberOfDevices(devices);
|
|
|
|
});
|
|
|
|
}
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
joinVideo(deviceId) {
|
|
|
|
this.deviceId = deviceId;
|
|
|
|
this.isConnecting = true;
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
joinedVideo() {
|
|
|
|
this.isConnected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
exitVideo() {
|
2019-11-28 21:13:06 +08:00
|
|
|
if (this.isConnected) {
|
|
|
|
logger.info({
|
|
|
|
logCode: 'video_provider_unsharewebcam',
|
|
|
|
}, `Sending unshare all ${Auth.userID} webcams notification to meteor`);
|
|
|
|
const streams = VideoStreams.find(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId: Auth.userID,
|
|
|
|
}, { fields: { stream: 1 } },
|
|
|
|
).fetch();
|
|
|
|
|
|
|
|
streams.forEach(s => this.sendUserUnshareWebcam(s.stream));
|
|
|
|
this.exitedVideo();
|
|
|
|
}
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
exitedVideo() {
|
2019-11-28 21:13:06 +08:00
|
|
|
this.isConnecting = false;
|
|
|
|
this.deviceId = null;
|
2018-01-11 09:15:44 +08:00
|
|
|
this.isConnected = false;
|
|
|
|
}
|
|
|
|
|
2019-11-29 04:28:41 +08:00
|
|
|
stopVideo(cameraId) {
|
2019-11-28 21:13:06 +08:00
|
|
|
const streams = VideoStreams.find(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId: Auth.userID,
|
|
|
|
}, { fields: { stream: 1 } },
|
|
|
|
).fetch().length;
|
|
|
|
this.sendUserUnshareWebcam(cameraId);
|
|
|
|
if (streams < 2) {
|
|
|
|
// If the user had less than 2 streams, set as a full disconnection
|
|
|
|
this.exitedVideo();
|
|
|
|
}
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
|
|
|
|
2019-11-29 04:28:41 +08:00
|
|
|
getSharedDevices() {
|
|
|
|
const devices = VideoStreams.find(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId: Auth.userID,
|
|
|
|
}, { fields: { deviceId: 1 } },
|
|
|
|
).fetch().map(vs => vs.deviceId);
|
|
|
|
|
|
|
|
return devices;
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
sendUserShareWebcam(cameraId) {
|
|
|
|
makeCall('userShareWebcam', cameraId);
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
2019-09-06 02:29:30 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
sendUserUnshareWebcam(cameraId) {
|
|
|
|
makeCall('userUnshareWebcam', cameraId);
|
|
|
|
}
|
2018-04-10 02:28:54 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
getAuthenticatedURL() {
|
|
|
|
return Auth.authenticateURL(SFU_URL);
|
|
|
|
}
|
2018-04-10 02:28:54 +08:00
|
|
|
|
2020-08-21 01:26:32 +08:00
|
|
|
isPaginationEnabled () {
|
|
|
|
return PAGINATION_ENABLED && (this.getMyPageSize() > 0);
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
setNumberOfPages (numberOfPublishers, numberOfSubscribers, pageSize) {
|
|
|
|
// Page size 0 means no pagination, return itself
|
|
|
|
if (pageSize === 0) return pageSize;
|
|
|
|
|
|
|
|
// Page size refers only to the number of subscribers. Publishers are always
|
|
|
|
// shown, hence not accounted for
|
|
|
|
const nofPages = Math.ceil((numberOfSubscribers || numberOfPublishers) / pageSize);
|
|
|
|
|
|
|
|
if (nofPages !== this.numberOfPages) {
|
|
|
|
this.numberOfPages = nofPages;
|
|
|
|
// Check if we have to page back on the current video page index due to a
|
|
|
|
// page ceasing to exist
|
|
|
|
if ((this.currentVideoPageIndex + 1) > this.numberOfPages) {
|
|
|
|
this.getPreviousVideoPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.numberOfPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
getNumberOfPages () {
|
|
|
|
return this.numberOfPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCurrentVideoPageIndex (newVideoPageIndex) {
|
|
|
|
if (this.currentVideoPageIndex !== newVideoPageIndex) {
|
2020-08-19 21:56:22 +08:00
|
|
|
this.currentVideoPageIndex = newVideoPageIndex;
|
2020-08-19 01:00:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentVideoPageIndex () {
|
|
|
|
return this.currentVideoPageIndex;
|
|
|
|
}
|
|
|
|
|
2020-08-20 06:27:47 +08:00
|
|
|
calculateNextPage () {
|
2020-08-24 22:35:28 +08:00
|
|
|
if (this.numberOfPages === 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-20 06:27:47 +08:00
|
|
|
return ((this.currentVideoPageIndex + 1) % this.numberOfPages + this.numberOfPages) % this.numberOfPages;
|
|
|
|
}
|
|
|
|
|
|
|
|
calculatePreviousPage () {
|
2020-08-24 22:35:28 +08:00
|
|
|
if (this.numberOfPages === 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-20 06:27:47 +08:00
|
|
|
return ((this.currentVideoPageIndex - 1) % this.numberOfPages + this.numberOfPages) % this.numberOfPages;
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
getNextVideoPage() {
|
2020-08-24 22:35:28 +08:00
|
|
|
const nextPage = this.calculateNextPage();
|
|
|
|
this.setCurrentVideoPageIndex(nextPage);
|
2020-08-19 01:00:47 +08:00
|
|
|
|
|
|
|
return this.currentVideoPageIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
getPreviousVideoPage() {
|
2020-08-24 22:35:28 +08:00
|
|
|
const previousPage = this.calculatePreviousPage();
|
|
|
|
this.setCurrentVideoPageIndex(previousPage);
|
2020-08-19 01:00:47 +08:00
|
|
|
|
|
|
|
return this.currentVideoPageIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
getMyPageSize () {
|
|
|
|
const myRole = this.getMyRole();
|
|
|
|
const pageSizes = !this.isMobile ? DESKTOP_PAGE_SIZES : MOBILE_PAGE_SIZES;
|
|
|
|
|
|
|
|
switch (myRole) {
|
|
|
|
case ROLE_MODERATOR:
|
|
|
|
return pageSizes.moderator;
|
|
|
|
case ROLE_VIEWER:
|
|
|
|
default:
|
|
|
|
return pageSizes.viewer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getVideoPage (streams, pageSize) {
|
|
|
|
// Publishers are taken into account for the page size calculations. They
|
|
|
|
// also appear on every page.
|
|
|
|
const [mine, others] = _.partition(streams, (vs => { return Auth.userID === vs.userId; }));
|
|
|
|
// Recalculate total number of pages
|
|
|
|
this.setNumberOfPages(mine.length, others.length, pageSize);
|
|
|
|
const paginatedStreams = _.chunk(others, pageSize)[this.currentVideoPageIndex] || [];
|
|
|
|
const streamsOnPage = [...mine, ...paginatedStreams];
|
|
|
|
|
|
|
|
return streamsOnPage;
|
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
getVideoStreams() {
|
2020-03-27 02:17:59 +08:00
|
|
|
let streams = VideoStreams.find(
|
2019-11-28 21:13:06 +08:00
|
|
|
{ meetingId: Auth.meetingID },
|
2019-09-06 04:03:22 +08:00
|
|
|
{
|
|
|
|
fields: {
|
2019-11-28 21:13:06 +08:00
|
|
|
userId: 1, stream: 1, name: 1,
|
2019-09-06 04:03:22 +08:00
|
|
|
},
|
2019-11-28 21:13:06 +08:00
|
|
|
},
|
|
|
|
).fetch();
|
2019-08-10 06:28:49 +08:00
|
|
|
|
2020-03-27 02:17:59 +08:00
|
|
|
const moderatorOnly = this.webcamsOnlyForModerator();
|
2020-08-05 22:35:08 +08:00
|
|
|
if (moderatorOnly) streams = this.filterModeratorOnly(streams);
|
2019-08-10 06:28:49 +08:00
|
|
|
|
2020-03-27 02:17:59 +08:00
|
|
|
const connectingStream = this.getConnectingStream(streams);
|
2019-11-28 21:13:06 +08:00
|
|
|
if (connectingStream) streams.push(connectingStream);
|
2019-08-10 06:28:49 +08:00
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
const mappedStreams = streams.map(vs => ({
|
2019-11-28 21:13:06 +08:00
|
|
|
cameraId: vs.stream,
|
|
|
|
userId: vs.userId,
|
|
|
|
name: vs.name,
|
|
|
|
})).sort(UserListService.sortUsersByName);
|
2020-08-19 01:00:47 +08:00
|
|
|
|
|
|
|
const pageSize = this.getMyPageSize();
|
|
|
|
|
|
|
|
// Pagination is either explictly disabled or pagination is set to 0 (which
|
|
|
|
// is equivalent to disabling it), so return the mapped streams as they are
|
|
|
|
// which produces the original non paginated behaviour
|
|
|
|
if (!PAGINATION_ENABLED || pageSize === 0) {
|
2020-08-25 02:30:24 +08:00
|
|
|
return { streams: mappedStreams, totalNumberOfStreams: mappedStreams.length };
|
2020-08-19 01:00:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const paginatedStreams = this.getVideoPage(mappedStreams, pageSize);
|
2020-08-25 02:30:24 +08:00
|
|
|
return { streams: paginatedStreams, totalNumberOfStreams: mappedStreams.length };
|
2019-11-28 21:13:06 +08:00
|
|
|
}
|
2019-08-10 06:28:49 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
getConnectingStream(streams) {
|
|
|
|
let connectingStream;
|
2018-04-10 02:28:54 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
if (this.isConnecting) {
|
|
|
|
if (this.deviceId) {
|
|
|
|
const stream = this.buildStreamName(Auth.userID, this.deviceId);
|
|
|
|
if (!this.hasStream(streams, stream) && !this.isUserLocked()) {
|
|
|
|
connectingStream = {
|
|
|
|
stream,
|
|
|
|
userId: Auth.userID,
|
|
|
|
name: Auth.fullname,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Connecting stream is already stored at database
|
|
|
|
this.deviceId = null;
|
|
|
|
this.isConnecting = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.error({
|
|
|
|
logCode: 'video_provider_missing_deviceid',
|
|
|
|
}, 'Could not retrieve a valid deviceId');
|
|
|
|
}
|
2019-08-10 06:28:49 +08:00
|
|
|
}
|
2018-04-10 02:28:54 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
return connectingStream;
|
2018-04-10 02:28:54 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
buildStreamName(userId, deviceId) {
|
|
|
|
return `${userId}${TOKEN}${deviceId}`;
|
2018-03-22 22:14:54 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
hasVideoStream() {
|
|
|
|
const videoStreams = VideoStreams.findOne({ userId: Auth.userID },
|
|
|
|
{ fields: {} });
|
|
|
|
return !!videoStreams;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasStream(streams, stream) {
|
|
|
|
return streams.find(s => s.stream === stream);
|
2018-03-22 22:14:54 +08:00
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
getMyRole () {
|
|
|
|
return Users.findOne({ userId: Auth.userID },
|
|
|
|
{ fields: { role: 1 } }).role;
|
|
|
|
}
|
|
|
|
|
2020-03-27 02:17:59 +08:00
|
|
|
filterModeratorOnly(streams) {
|
2020-08-19 01:00:47 +08:00
|
|
|
const amIViewer = this.getMyRole() === ROLE_VIEWER;
|
2020-03-27 02:17:59 +08:00
|
|
|
|
|
|
|
if (amIViewer) {
|
|
|
|
const moderators = Users.find(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
connectionStatus: 'online',
|
|
|
|
role: ROLE_MODERATOR,
|
|
|
|
},
|
2020-03-27 05:15:41 +08:00
|
|
|
{ fields: { userId: 1 } },
|
2020-03-27 02:17:59 +08:00
|
|
|
).fetch().map(user => user.userId);
|
|
|
|
|
|
|
|
return streams.reduce((result, stream) => {
|
|
|
|
const { userId } = stream;
|
|
|
|
|
|
|
|
const isModerator = moderators.includes(userId);
|
2020-08-19 01:00:47 +08:00
|
|
|
const isMe = Auth.userID === userId;
|
2020-03-27 02:17:59 +08:00
|
|
|
|
|
|
|
if (isModerator || isMe) result.push(stream);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}, []);
|
|
|
|
}
|
2020-03-27 05:15:41 +08:00
|
|
|
return streams;
|
2020-03-27 02:17:59 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
disableCam() {
|
2019-08-30 00:26:07 +08:00
|
|
|
const m = Meetings.findOne({ meetingId: Auth.meetingID },
|
|
|
|
{ fields: { 'lockSettingsProps.disableCam': 1 } });
|
2019-04-04 01:23:31 +08:00
|
|
|
return m.lockSettingsProps ? m.lockSettingsProps.disableCam : false;
|
2018-03-22 22:14:54 +08:00
|
|
|
}
|
|
|
|
|
2020-03-27 02:17:59 +08:00
|
|
|
webcamsOnlyForModerator() {
|
|
|
|
const m = Meetings.findOne({ meetingId: Auth.meetingID },
|
|
|
|
{ fields: { 'usersProp.webcamsOnlyForModerator': 1 } });
|
|
|
|
return m.usersProp ? m.usersProp.webcamsOnlyForModerator : false;
|
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
getInfo() {
|
|
|
|
const m = Meetings.findOne({ meetingId: Auth.meetingID },
|
|
|
|
{ fields: { 'voiceProp.voiceConf': 1 } });
|
|
|
|
const voiceBridge = m.voiceProp ? m.voiceProp.voiceConf : null;
|
|
|
|
return {
|
|
|
|
userId: Auth.userID,
|
|
|
|
userName: Auth.fullname,
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
sessionToken: Auth.sessionToken,
|
|
|
|
voiceBridge,
|
|
|
|
};
|
2018-01-13 05:31:01 +08:00
|
|
|
}
|
|
|
|
|
2020-03-27 02:17:59 +08:00
|
|
|
mirrorOwnWebcam(user) {
|
|
|
|
// only true if setting defined and video ids match
|
|
|
|
const isOwnWebcam = user ? this.userId() === user.userId : true;
|
|
|
|
const isEnabledMirroring = getFromUserSettings('bbb_mirror_own_webcam', MIRROR_WEBCAM);
|
|
|
|
return isOwnWebcam && isEnabledMirroring;
|
|
|
|
}
|
|
|
|
|
2019-12-19 01:44:56 +08:00
|
|
|
getMyStream(deviceId) {
|
|
|
|
const videoStream = VideoStreams.findOne(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId: Auth.userID,
|
|
|
|
deviceId: deviceId
|
|
|
|
}, { fields: { stream: 1 } }
|
|
|
|
);
|
|
|
|
return videoStream ? videoStream.stream : null;
|
2018-03-20 01:52:39 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
isUserLocked() {
|
|
|
|
return !!Users.findOne({
|
|
|
|
userId: Auth.userID,
|
|
|
|
locked: true,
|
|
|
|
role: { $ne: ROLE_MODERATOR },
|
|
|
|
}, { fields: {} }) && this.disableCam();
|
2018-07-10 05:29:27 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
lockUser() {
|
|
|
|
if (this.isConnected) {
|
|
|
|
this.exitVideo();
|
|
|
|
}
|
2018-07-10 05:29:27 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
isLocalStream(cameraId) {
|
|
|
|
return cameraId.startsWith(Auth.userID);
|
|
|
|
}
|
|
|
|
|
|
|
|
playStart(cameraId) {
|
|
|
|
if (this.isLocalStream(cameraId)) {
|
|
|
|
this.sendUserShareWebcam(cameraId);
|
|
|
|
this.joinedVideo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getCameraProfile() {
|
|
|
|
const profileId = Session.get('WebcamProfileId') || '';
|
|
|
|
const cameraProfile = CAMERA_PROFILES.find(profile => profile.id === profileId)
|
|
|
|
|| CAMERA_PROFILES.find(profile => profile.default)
|
|
|
|
|| CAMERA_PROFILES[0];
|
|
|
|
const deviceId = Session.get('WebcamDeviceId');
|
|
|
|
if (deviceId) {
|
|
|
|
cameraProfile.constraints = cameraProfile.constraints || {};
|
|
|
|
cameraProfile.constraints.deviceId = { exact: deviceId };
|
|
|
|
}
|
|
|
|
|
|
|
|
return cameraProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
addCandidateToPeer(peer, candidate, cameraId) {
|
|
|
|
peer.addIceCandidate(candidate, (error) => {
|
|
|
|
if (error) {
|
|
|
|
// Just log the error. We can't be sure if a candidate failure on add is
|
|
|
|
// fatal or not, so that's why we have a timeout set up for negotiations
|
|
|
|
// and listeners for ICE state transitioning to failures, so we won't
|
|
|
|
// act on it here
|
|
|
|
logger.error({
|
|
|
|
logCode: 'video_provider_addicecandidate_error',
|
|
|
|
extraInfo: {
|
|
|
|
cameraId,
|
|
|
|
error,
|
|
|
|
},
|
|
|
|
}, `Adding ICE candidate failed for ${cameraId} due to ${error.message}`);
|
|
|
|
}
|
|
|
|
});
|
2018-08-27 15:37:25 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
processInboundIceQueue(peer, cameraId) {
|
|
|
|
while (peer.inboundIceQueue.length) {
|
|
|
|
const candidate = peer.inboundIceQueue.shift();
|
|
|
|
this.addCandidateToPeer(peer, candidate, cameraId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onBeforeUnload() {
|
|
|
|
this.exitVideo();
|
|
|
|
}
|
|
|
|
|
|
|
|
isDisabled() {
|
|
|
|
const { viewParticipantsWebcams } = Settings.dataSaving;
|
|
|
|
|
|
|
|
return this.isUserLocked() || this.isConnecting || !viewParticipantsWebcams;
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
getRole(isLocal) {
|
|
|
|
return isLocal ? 'share' : 'viewer';
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
2019-11-30 05:48:04 +08:00
|
|
|
|
2020-03-27 05:15:41 +08:00
|
|
|
getSkipVideoPreview(fromInterface = false) {
|
|
|
|
if (this.skipVideoPreview === null) {
|
|
|
|
this.skipVideoPreview = getFromUserSettings('bbb_skip_video_preview', false) || SKIP_VIDEO_PREVIEW;
|
|
|
|
}
|
|
|
|
|
2019-12-19 01:44:56 +08:00
|
|
|
return this.skipVideoPreview && !fromInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
getUserParameterProfile() {
|
2020-03-27 05:15:41 +08:00
|
|
|
if (this.userParameterProfile === null) {
|
|
|
|
this.userParameterProfile = getFromUserSettings(
|
|
|
|
'bbb_preferred_camera_profile',
|
|
|
|
(CAMERA_PROFILES.filter(i => i.default) || {}).id,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-19 01:44:56 +08:00
|
|
|
return this.userParameterProfile;
|
2018-08-27 15:37:25 +08:00
|
|
|
}
|
|
|
|
|
2019-12-19 01:44:56 +08:00
|
|
|
isMultipleCamerasEnabled() {
|
|
|
|
// Multiple cameras shouldn't be enabled with video preview skipping
|
2019-12-21 03:47:30 +08:00
|
|
|
// Mobile shouldn't be able to share more than one camera at the same time
|
|
|
|
// Safari needs to implement devicechange event for safe device control
|
2020-03-27 05:15:41 +08:00
|
|
|
return MULTIPLE_CAMERAS
|
|
|
|
&& !this.getSkipVideoPreview()
|
|
|
|
&& !this.isMobile
|
|
|
|
&& !this.isSafari
|
|
|
|
&& this.numberOfDevices > 1;
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
2017-09-01 23:26:57 +08:00
|
|
|
|
2019-11-30 05:48:04 +08:00
|
|
|
monitor(conn) {
|
|
|
|
if (ENABLE_NETWORK_MONITORING) monitorVideoConnection(conn);
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
2020-05-27 01:05:04 +08:00
|
|
|
|
|
|
|
amIModerator() {
|
|
|
|
return Users.findOne({ userId: Auth.userID },
|
|
|
|
{ fields: { role: 1 } }).role === ROLE_MODERATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
getNumberOfPublishers() {
|
|
|
|
return VideoStreams.find({ meetingId: Auth.meetingID }).count();
|
|
|
|
}
|
|
|
|
|
|
|
|
isProfileBetter (newProfileId, originalProfileId) {
|
|
|
|
return CAMERA_PROFILES.findIndex(({ id }) => id === newProfileId)
|
|
|
|
> CAMERA_PROFILES.findIndex(({ id }) => id === originalProfileId);
|
|
|
|
}
|
|
|
|
|
|
|
|
applyBitrate (peer, bitrate) {
|
|
|
|
const peerConnection = peer.peerConnection;
|
|
|
|
if ('RTCRtpSender' in window
|
|
|
|
&& 'setParameters' in window.RTCRtpSender.prototype
|
|
|
|
&& 'getParameters' in window.RTCRtpSender.prototype) {
|
|
|
|
peerConnection.getSenders().forEach(sender => {
|
|
|
|
const { track } = sender;
|
|
|
|
if (track && track.kind === 'video') {
|
|
|
|
const parameters = sender.getParameters();
|
|
|
|
if (!parameters.encodings) {
|
|
|
|
parameters.encodings = [{}];
|
|
|
|
}
|
|
|
|
|
2020-05-27 23:15:48 +08:00
|
|
|
const normalizedBitrate = bitrate * 1000;
|
|
|
|
// Only reset bitrate if it changed in some way to avoid enconder fluctuations
|
|
|
|
if (parameters.encodings[0].maxBitrate !== normalizedBitrate) {
|
|
|
|
parameters.encodings[0].maxBitrate = normalizedBitrate;
|
|
|
|
sender.setParameters(parameters)
|
|
|
|
.then(() => {
|
|
|
|
logger.info({
|
|
|
|
logCode: 'video_provider_bitratechange',
|
|
|
|
extraInfo: { bitrate },
|
|
|
|
}, `Bitrate changed: ${bitrate}`);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_provider_bitratechange_failed',
|
|
|
|
extraInfo: { bitrate, errorMessage: error.message, errorCode: error.code },
|
|
|
|
}, `Bitrate change failed.`);
|
|
|
|
});
|
|
|
|
}
|
2020-05-27 01:05:04 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 23:15:48 +08:00
|
|
|
// Some browsers (mainly iOS Safari) garble the stream if a constraint is
|
|
|
|
// reconfigured without propagating previous height/width info
|
|
|
|
reapplyResolutionIfNeeded (track, constraints) {
|
|
|
|
if (typeof track.getSettings !== 'function') {
|
|
|
|
return constraints;
|
|
|
|
}
|
|
|
|
|
|
|
|
const trackSettings = track.getSettings();
|
|
|
|
|
|
|
|
if (trackSettings.width && trackSettings.height) {
|
|
|
|
return {
|
|
|
|
...constraints,
|
|
|
|
width: trackSettings.width,
|
|
|
|
height: trackSettings.height
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return constraints;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 01:05:04 +08:00
|
|
|
applyCameraProfile (peer, profileId) {
|
|
|
|
const profile = CAMERA_PROFILES.find(targetProfile => targetProfile.id === profileId);
|
|
|
|
|
|
|
|
if (!profile) {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_provider_noprofile',
|
|
|
|
extraInfo: { profileId },
|
|
|
|
}, `Apply failed: no camera profile found.`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Profile is currently applied or it's better than the original user's profile,
|
|
|
|
// skip
|
|
|
|
if (peer.currentProfileId === profileId
|
|
|
|
|| this.isProfileBetter(profileId, peer.originalProfileId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { bitrate, constraints } = profile;
|
|
|
|
|
|
|
|
if (bitrate) {
|
|
|
|
this.applyBitrate(peer, bitrate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (constraints && typeof constraints.video === 'object') {
|
|
|
|
peer.peerConnection.getSenders().forEach(sender => {
|
|
|
|
const { track } = sender;
|
|
|
|
if (track && track.kind === 'video' && typeof track.applyConstraints === 'function') {
|
2020-05-27 23:15:48 +08:00
|
|
|
let normalizedVideoConstraints = this.reapplyResolutionIfNeeded(track, constraints.video);
|
|
|
|
track.applyConstraints(normalizedVideoConstraints)
|
2020-05-27 01:05:04 +08:00
|
|
|
.then(() => {
|
|
|
|
logger.info({
|
|
|
|
logCode: 'video_provider_profile_applied',
|
|
|
|
extraInfo: { profileId },
|
|
|
|
}, `New camera profile applied: ${profileId}`);
|
|
|
|
peer.currentProfileId = profileId;
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_provider_profile_apply_failed',
|
|
|
|
extraInfo: { errorName: error.name, errorCode: error.code },
|
|
|
|
}, 'Error applying camera profile');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getThreshold (numberOfPublishers) {
|
|
|
|
let targetThreshold = { threshold: 0, profile: 'original' };
|
|
|
|
let finalThreshold = { threshold: 0, profile: 'original' };
|
|
|
|
|
|
|
|
for(let mapIndex = 0; mapIndex < CAMERA_QUALITY_THRESHOLDS.length; mapIndex++) {
|
|
|
|
targetThreshold = CAMERA_QUALITY_THRESHOLDS[mapIndex];
|
|
|
|
if (targetThreshold.threshold <= numberOfPublishers) {
|
|
|
|
finalThreshold = targetThreshold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return finalThreshold;
|
|
|
|
}
|
2017-12-09 00:38:51 +08:00
|
|
|
}
|
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
const videoService = new VideoService();
|
2018-01-13 02:39:16 +08:00
|
|
|
|
2017-09-01 23:26:57 +08:00
|
|
|
export default {
|
2018-01-11 09:15:44 +08:00
|
|
|
exitVideo: () => videoService.exitVideo(),
|
2019-11-28 21:13:06 +08:00
|
|
|
joinVideo: deviceId => videoService.joinVideo(deviceId),
|
2019-11-29 04:28:41 +08:00
|
|
|
stopVideo: cameraId => videoService.stopVideo(cameraId),
|
2019-11-28 21:13:06 +08:00
|
|
|
getVideoStreams: () => videoService.getVideoStreams(),
|
|
|
|
getInfo: () => videoService.getInfo(),
|
2019-12-19 01:44:56 +08:00
|
|
|
getMyStream: deviceId => videoService.getMyStream(deviceId),
|
2019-11-28 21:13:06 +08:00
|
|
|
isUserLocked: () => videoService.isUserLocked(),
|
|
|
|
lockUser: () => videoService.lockUser(),
|
|
|
|
getAuthenticatedURL: () => videoService.getAuthenticatedURL(),
|
|
|
|
isLocalStream: cameraId => videoService.isLocalStream(cameraId),
|
|
|
|
hasVideoStream: () => videoService.hasVideoStream(),
|
|
|
|
isDisabled: () => videoService.isDisabled(),
|
|
|
|
playStart: cameraId => videoService.playStart(cameraId),
|
|
|
|
getCameraProfile: () => videoService.getCameraProfile(),
|
|
|
|
addCandidateToPeer: (peer, candidate, cameraId) => videoService.addCandidateToPeer(peer, candidate, cameraId),
|
|
|
|
processInboundIceQueue: (peer, cameraId) => videoService.processInboundIceQueue(peer, cameraId),
|
|
|
|
getRole: isLocal => videoService.getRole(isLocal),
|
2019-11-29 04:28:41 +08:00
|
|
|
getSharedDevices: () => videoService.getSharedDevices(),
|
2019-12-19 01:44:56 +08:00
|
|
|
getSkipVideoPreview: fromInterface => videoService.getSkipVideoPreview(fromInterface),
|
|
|
|
getUserParameterProfile: () => videoService.getUserParameterProfile(),
|
|
|
|
isMultipleCamerasEnabled: () => videoService.isMultipleCamerasEnabled(),
|
2019-11-30 05:48:04 +08:00
|
|
|
monitor: conn => videoService.monitor(conn),
|
2020-06-15 03:13:47 +08:00
|
|
|
mirrorOwnWebcam: user => videoService.mirrorOwnWebcam(user),
|
2019-11-28 21:13:06 +08:00
|
|
|
onBeforeUnload: () => videoService.onBeforeUnload(),
|
|
|
|
notify: message => notify(message, 'error', 'video'),
|
2020-05-09 00:43:29 +08:00
|
|
|
updateNumberOfDevices: devices => videoService.updateNumberOfDevices(devices),
|
2020-05-27 01:05:04 +08:00
|
|
|
applyCameraProfile: (peer, newProfile) => videoService.applyCameraProfile(peer, newProfile),
|
|
|
|
getThreshold: (numberOfPublishers) => videoService.getThreshold(numberOfPublishers),
|
2020-08-21 01:26:32 +08:00
|
|
|
isPaginationEnabled: () => videoService.isPaginationEnabled(),
|
2020-08-19 01:00:47 +08:00
|
|
|
getNumberOfPages: () => videoService.getNumberOfPages(),
|
|
|
|
getCurrentVideoPageIndex: () => videoService.getCurrentVideoPageIndex(),
|
|
|
|
getPreviousVideoPage: () => videoService.getPreviousVideoPage(),
|
|
|
|
getNextVideoPage: () => videoService.getNextVideoPage(),
|
2020-08-20 23:43:02 +08:00
|
|
|
getPageChangeDebounceTime: () => { return PAGE_CHANGE_DEBOUNCE_TIME },
|
2017-09-01 23:26:57 +08:00
|
|
|
};
|