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';
|
2021-12-21 03:02:59 +08:00
|
|
|
import { meetingIsBreakout } from '/imports/ui/components/app/service';
|
2019-11-28 21:13:06 +08:00
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2021-04-01 01:13:36 +08:00
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
2021-04-01 19:14:24 +08:00
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
2019-12-19 01:44:56 +08:00
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2021-02-02 02:47:05 +08:00
|
|
|
import VideoPreviewService from '../video-preview/service';
|
|
|
|
import Storage from '/imports/ui/services/storage/session';
|
2022-11-04 04:57:54 +08:00
|
|
|
import BBBStorage from '/imports/ui/services/storage';
|
2019-11-28 21:13:06 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2023-08-10 00:26:42 +08:00
|
|
|
import { debounce } from '/imports/utils/debounce';
|
2023-02-22 01:57:34 +08:00
|
|
|
import { partition } from '/imports/utils/array-utils';
|
2021-04-09 10:58:13 +08:00
|
|
|
import {
|
|
|
|
getSortingMethod,
|
|
|
|
sortVideoStreams,
|
|
|
|
} from '/imports/ui/components/video-provider/stream-sorting';
|
2021-04-27 05:05:06 +08:00
|
|
|
import getFromMeetingSettings from '/imports/ui/services/meeting-settings';
|
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;
|
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;
|
2020-03-27 02:17:59 +08:00
|
|
|
const ROLE_VIEWER = Meteor.settings.public.user.role_viewer;
|
2020-06-16 04:51:46 +08:00
|
|
|
const MIRROR_WEBCAM = Meteor.settings.public.app.mirrorOwnWebcam;
|
2021-12-21 03:02:59 +08:00
|
|
|
const PIN_WEBCAM = Meteor.settings.public.kurento.enableVideoPin;
|
2022-03-14 22:27:42 +08:00
|
|
|
const {
|
|
|
|
thresholds: CAMERA_QUALITY_THRESHOLDS = [],
|
|
|
|
applyConstraints: CAMERA_QUALITY_THR_CONSTRAINTS = false,
|
|
|
|
debounceTime: CAMERA_QUALITY_THR_DEBOUNCE = 2500,
|
|
|
|
} = Meteor.settings.public.kurento.cameraQualityThresholds;
|
2020-08-19 01:00:47 +08:00
|
|
|
const {
|
2020-08-29 03:29:45 +08:00
|
|
|
paginationToggleEnabled: PAGINATION_TOGGLE_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,
|
2023-08-14 20:46:05 +08:00
|
|
|
desktopGridSizes: DESKTOP_GRID_SIZES,
|
|
|
|
mobileGridSizes: MOBILE_GRID_SIZES,
|
2020-08-19 01:00:47 +08:00
|
|
|
} = Meteor.settings.public.kurento.pagination;
|
2021-03-17 00:27:34 +08:00
|
|
|
const PAGINATION_THRESHOLDS_CONF = Meteor.settings.public.kurento.paginationThresholds;
|
|
|
|
const PAGINATION_THRESHOLDS = PAGINATION_THRESHOLDS_CONF.thresholds.sort((t1, t2) => t1.users - t2.users);
|
|
|
|
const PAGINATION_THRESHOLDS_ENABLED = PAGINATION_THRESHOLDS_CONF.enabled;
|
2021-04-09 10:58:13 +08:00
|
|
|
const {
|
|
|
|
paginationSorting: PAGINATION_SORTING,
|
|
|
|
defaultSorting: DEFAULT_SORTING,
|
|
|
|
} = Meteor.settings.public.kurento.cameraSortingModes;
|
2021-04-27 03:05:53 +08:00
|
|
|
const DEFAULT_VIDEO_MEDIA_SERVER = Meteor.settings.public.kurento.videoMediaServer;
|
2019-11-28 21:13:06 +08:00
|
|
|
|
2021-08-14 04:24:44 +08:00
|
|
|
const FILTER_VIDEO_STATS = [
|
|
|
|
'outbound-rtp',
|
|
|
|
'inbound-rtp',
|
|
|
|
];
|
|
|
|
|
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,
|
2021-03-17 00:27:34 +08:00
|
|
|
pageSize: 0,
|
2018-01-11 09:15:44 +08:00
|
|
|
});
|
2020-03-27 05:15:41 +08:00
|
|
|
this.userParameterProfile = null;
|
2021-04-01 19:14:24 +08:00
|
|
|
|
2021-04-01 01:13:36 +08:00
|
|
|
this.isMobile = deviceInfo.isMobile;
|
2021-04-01 19:14:24 +08:00
|
|
|
this.isSafari = browserInfo.isSafari;
|
2019-12-21 03:47:30 +08:00
|
|
|
this.numberOfDevices = 0;
|
|
|
|
|
2020-08-22 06:10:25 +08:00
|
|
|
this.record = null;
|
2020-08-23 08:00:31 +08:00
|
|
|
this.hackRecordViewer = null;
|
2020-08-22 06:10:25 +08:00
|
|
|
|
2020-03-10 01:47:47 +08:00
|
|
|
// If the page isn't served over HTTPS there won't be mediaDevices
|
|
|
|
if (navigator.mediaDevices) {
|
|
|
|
this.updateNumberOfDevices = this.updateNumberOfDevices.bind(this);
|
|
|
|
// Safari doesn't support ondevicechange
|
|
|
|
if (!this.isSafari) {
|
|
|
|
navigator.mediaDevices.ondevicechange = event => this.updateNumberOfDevices();
|
|
|
|
}
|
|
|
|
this.updateNumberOfDevices();
|
2019-12-21 04:02:34 +08:00
|
|
|
}
|
2021-12-16 23:12:52 +08:00
|
|
|
|
|
|
|
// FIXME this is abhorrent. Remove when peer lifecycle is properly decoupled
|
|
|
|
// from the React component's lifecycle. Any attempt at a half-baked
|
|
|
|
// decoupling will most probably generate problems - prlanzarin Dec 16 2021
|
|
|
|
this.webRtcPeersRef = {};
|
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);
|
|
|
|
});
|
|
|
|
}
|
2019-12-21 03:47:30 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
joinVideo(deviceId) {
|
|
|
|
this.deviceId = deviceId;
|
|
|
|
this.isConnecting = true;
|
2021-02-02 02:47:05 +08:00
|
|
|
Storage.setItem('isFirstJoin', false);
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
joinedVideo() {
|
|
|
|
this.isConnected = true;
|
|
|
|
}
|
|
|
|
|
2021-03-27 03:51:39 +08:00
|
|
|
storeDeviceIds() {
|
|
|
|
const streams = VideoStreams.find(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId: Auth.userID,
|
|
|
|
}, { fields: { deviceId: 1 } },
|
|
|
|
).fetch();
|
|
|
|
|
|
|
|
let deviceIds = [];
|
|
|
|
streams.forEach(s => {
|
|
|
|
deviceIds.push(s.deviceId);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
Session.set('deviceIds', deviceIds.join());
|
|
|
|
}
|
|
|
|
|
2018-01-11 09:15:44 +08:00
|
|
|
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 } },
|
2021-01-13 00:11:32 +08:00
|
|
|
).fetch();
|
|
|
|
|
2021-01-22 02:39:21 +08:00
|
|
|
const hasTargetStream = streams.some(s => s.stream === cameraId);
|
|
|
|
const hasOtherStream = streams.some(s => s.stream !== cameraId);
|
2021-01-13 00:11:32 +08:00
|
|
|
|
2021-01-22 02:39:21 +08:00
|
|
|
// Check if the target (cameraId) stream exists in the remote collection.
|
|
|
|
// If it does, means it was successfully shared. So do the full stop procedure.
|
|
|
|
if (hasTargetStream) {
|
2021-01-13 00:11:32 +08:00
|
|
|
this.sendUserUnshareWebcam(cameraId);
|
2021-01-22 02:39:21 +08:00
|
|
|
}
|
2021-01-13 00:11:32 +08:00
|
|
|
|
2021-01-22 02:39:21 +08:00
|
|
|
if (!hasOtherStream) {
|
|
|
|
// There's no other remote stream, meaning (OR)
|
|
|
|
// a) This was effectively the last webcam being unshared
|
|
|
|
// b) This was a connecting stream timing out (not effectively shared)
|
|
|
|
// For both cases, we clean everything up.
|
2019-11-28 21:13:06 +08:00
|
|
|
this.exitedVideo();
|
2021-01-22 02:39:21 +08:00
|
|
|
} else {
|
|
|
|
// It was not the last webcam the user had successfully shared,
|
|
|
|
// nor was cameraId present in the server collection.
|
|
|
|
// Hence it's a connecting stream (not effectively shared) which timed out
|
|
|
|
this.stopConnectingStream();
|
2019-11-28 21:13:06 +08:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
sendUserShareWebcam(cameraId) {
|
|
|
|
makeCall('userShareWebcam', cameraId);
|
2018-01-11 09:15:44 +08:00
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
sendUserUnshareWebcam(cameraId) {
|
|
|
|
makeCall('userUnshareWebcam', cameraId);
|
|
|
|
}
|
2019-09-06 02:29:30 +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-29 03:29:45 +08:00
|
|
|
shouldRenderPaginationToggle() {
|
|
|
|
// Only enable toggle if configured to do so and if we have a page size properly setup
|
|
|
|
return PAGINATION_TOGGLE_ENABLED && (this.getMyPageSize() > 0);
|
|
|
|
}
|
|
|
|
|
2020-08-21 01:26:32 +08:00
|
|
|
isPaginationEnabled () {
|
2020-08-29 03:29:45 +08:00
|
|
|
return Settings.application.paginationEnabled && (this.getMyPageSize() > 0);
|
2020-08-21 01:26:32 +08:00
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
setNumberOfPages (numberOfPublishers, numberOfSubscribers, pageSize) {
|
|
|
|
// Page size 0 means no pagination, return itself
|
2020-08-25 03:48:39 +08:00
|
|
|
if (pageSize === 0) return 0;
|
2020-08-19 01:00:47 +08:00
|
|
|
|
|
|
|
// Page size refers only to the number of subscribers. Publishers are always
|
|
|
|
// shown, hence not accounted for
|
2021-12-21 03:02:59 +08:00
|
|
|
const nofPages = Math.ceil(numberOfSubscribers / pageSize);
|
2020-08-19 01:00:47 +08:00
|
|
|
|
|
|
|
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
|
2021-12-21 03:02:59 +08:00
|
|
|
if (nofPages === 0) {
|
|
|
|
this.currentVideoPageIndex = 0;
|
|
|
|
} else if ((this.currentVideoPageIndex + 1) > this.numberOfPages) {
|
2020-08-19 01:00:47 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-03-17 00:27:34 +08:00
|
|
|
getPageSizeDictionary () {
|
|
|
|
// Dynamic page sizes are disabled. Fetch the stock page sizes.
|
|
|
|
if (!PAGINATION_THRESHOLDS_ENABLED || PAGINATION_THRESHOLDS.length <= 0) {
|
|
|
|
return !this.isMobile ? DESKTOP_PAGE_SIZES : MOBILE_PAGE_SIZES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dynamic page sizes are enabled. Get the user count, isolate the
|
|
|
|
// matching threshold entry, return the val.
|
|
|
|
let targetThreshold;
|
|
|
|
const userCount = UserListService.getUserCount();
|
|
|
|
const processThreshold = (threshold = {
|
|
|
|
desktopPageSizes: DESKTOP_PAGE_SIZES,
|
|
|
|
mobilePageSizes: MOBILE_PAGE_SIZES
|
|
|
|
}) => {
|
|
|
|
// We don't demand that all page sizes should be set in pagination profiles.
|
|
|
|
// That saves us some space because don't necessarily need to scale mobile
|
|
|
|
// endpoints.
|
|
|
|
// If eg mobile isn't set, then return the default value.
|
|
|
|
if (!this.isMobile) {
|
|
|
|
return threshold.desktopPageSizes || DESKTOP_PAGE_SIZES;
|
|
|
|
} else {
|
|
|
|
return threshold.mobilePageSizes || MOBILE_PAGE_SIZES;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Short-circuit: no threshold yet, return stock values (processThreshold has a default arg)
|
|
|
|
if (userCount < PAGINATION_THRESHOLDS[0].users) return processThreshold();
|
|
|
|
|
|
|
|
// Reverse search for the threshold where our participant count is directly equal or great
|
|
|
|
// The PAGINATION_THRESHOLDS config is sorted when imported.
|
|
|
|
for (let mapIndex = PAGINATION_THRESHOLDS.length - 1; mapIndex >= 0; --mapIndex) {
|
|
|
|
targetThreshold = PAGINATION_THRESHOLDS[mapIndex];
|
|
|
|
if (targetThreshold.users <= userCount) {
|
|
|
|
return processThreshold(targetThreshold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setPageSize (size) {
|
|
|
|
if (this.pageSize !== size) {
|
|
|
|
this.pageSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.pageSize;
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
getMyPageSize () {
|
2021-03-17 00:27:34 +08:00
|
|
|
let size;
|
2020-08-19 01:00:47 +08:00
|
|
|
const myRole = this.getMyRole();
|
2021-03-17 00:27:34 +08:00
|
|
|
const pageSizes = this.getPageSizeDictionary();
|
2020-08-19 01:00:47 +08:00
|
|
|
switch (myRole) {
|
|
|
|
case ROLE_MODERATOR:
|
2021-03-17 00:27:34 +08:00
|
|
|
size = pageSizes.moderator;
|
|
|
|
break;
|
2020-08-19 01:00:47 +08:00
|
|
|
case ROLE_VIEWER:
|
|
|
|
default:
|
2021-03-17 00:27:34 +08:00
|
|
|
size = pageSizes.viewer
|
2020-08-19 01:00:47 +08:00
|
|
|
}
|
2021-03-17 00:27:34 +08:00
|
|
|
|
|
|
|
return this.setPageSize(size);
|
2020-08-19 01:00:47 +08:00
|
|
|
}
|
|
|
|
|
2023-08-09 00:05:54 +08:00
|
|
|
getGridSize () {
|
|
|
|
let size;
|
|
|
|
const myRole = this.getMyRole();
|
2023-08-14 20:46:05 +08:00
|
|
|
const gridSizes = !this.isMobile ? DESKTOP_GRID_SIZES : MOBILE_GRID_SIZES;
|
2023-08-09 00:05:54 +08:00
|
|
|
|
|
|
|
switch (myRole) {
|
|
|
|
case ROLE_MODERATOR:
|
2023-08-14 20:46:05 +08:00
|
|
|
size = gridSizes.moderator;
|
2023-08-09 00:05:54 +08:00
|
|
|
break;
|
|
|
|
case ROLE_VIEWER:
|
|
|
|
default:
|
2023-08-14 20:46:05 +08:00
|
|
|
size = gridSizes.viewer
|
2023-08-09 00:05:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
getVideoPage (streams, pageSize) {
|
|
|
|
// Publishers are taken into account for the page size calculations. They
|
2021-12-21 03:02:59 +08:00
|
|
|
// also appear on every page. Same for pinned user.
|
2023-02-22 01:57:34 +08:00
|
|
|
const [filtered, others] = partition(streams, (vs) => Auth.userID === vs.userId || vs.pin);
|
2021-12-21 03:02:59 +08:00
|
|
|
|
|
|
|
// Separate pin from local cameras
|
2023-02-22 01:57:34 +08:00
|
|
|
const [pin, mine] = partition(filtered, (vs) => vs.pin);
|
2020-08-25 03:48:39 +08:00
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
// Recalculate total number of pages
|
2021-12-21 03:02:59 +08:00
|
|
|
this.setNumberOfPages(filtered.length, others.length, pageSize);
|
2020-08-25 03:48:39 +08:00
|
|
|
const chunkIndex = this.currentVideoPageIndex * pageSize;
|
2021-05-05 00:34:02 +08:00
|
|
|
|
|
|
|
// This is an extra check because pagination is globally in effect (hard
|
|
|
|
// limited page sizes, toggles on), but we might still only have one page.
|
|
|
|
// Use the default sorting method if that's the case.
|
|
|
|
const sortingMethod = (this.numberOfPages > 1) ? PAGINATION_SORTING : DEFAULT_SORTING;
|
|
|
|
const paginatedStreams = sortVideoStreams(others, sortingMethod)
|
2020-08-25 03:48:39 +08:00
|
|
|
.slice(chunkIndex, (chunkIndex + pageSize)) || [];
|
2020-08-19 01:00:47 +08:00
|
|
|
|
2021-05-05 00:34:02 +08:00
|
|
|
if (getSortingMethod(sortingMethod).localFirst) {
|
2021-12-21 03:02:59 +08:00
|
|
|
return [...pin, ...mine, ...paginatedStreams];
|
2021-04-09 10:58:13 +08:00
|
|
|
}
|
2021-12-21 03:02:59 +08:00
|
|
|
return [...pin, ...paginatedStreams, ...mine];
|
2020-08-19 01:00:47 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 02:05:51 +08:00
|
|
|
getUsersIdFromVideoStreams() {
|
|
|
|
const usersId = VideoStreams.find(
|
|
|
|
{ meetingId: Auth.meetingID },
|
|
|
|
{ fields: { userId: 1 } },
|
|
|
|
).fetch().map(user => user.userId);
|
|
|
|
|
|
|
|
return usersId;
|
|
|
|
}
|
|
|
|
|
2021-12-21 03:02:59 +08:00
|
|
|
getVideoPinByUser(userId) {
|
|
|
|
const user = Users.findOne({ userId }, { fields: { pin: 1 } });
|
|
|
|
|
|
|
|
return user.pin;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleVideoPin(userId, userIsPinned) {
|
|
|
|
makeCall('changePin', userId, !userIsPinned);
|
|
|
|
}
|
|
|
|
|
2023-07-26 00:20:45 +08:00
|
|
|
isGridEnabled() {
|
|
|
|
return Session.get('isGridEnabled');
|
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
getVideoStreams() {
|
2021-04-09 10:58:13 +08:00
|
|
|
const pageSize = this.getMyPageSize();
|
|
|
|
const isPaginationDisabled = !this.isPaginationEnabled() || pageSize === 0;
|
|
|
|
const { neededDataTypes } = isPaginationDisabled
|
|
|
|
? getSortingMethod(DEFAULT_SORTING)
|
|
|
|
: getSortingMethod(PAGINATION_SORTING);
|
2023-07-26 00:20:45 +08:00
|
|
|
const isGridEnabled = this.isGridEnabled();
|
2023-08-14 20:30:53 +08:00
|
|
|
let gridUsers = [];
|
2023-08-14 20:52:52 +08:00
|
|
|
let users = [];
|
|
|
|
|
|
|
|
if (isGridEnabled) {
|
|
|
|
users = Users.find(
|
|
|
|
{ meetingId: Auth.meetingID },
|
|
|
|
{ fields: { loggedOut: 1, left: 1, ...neededDataTypes} },
|
|
|
|
).fetch();
|
|
|
|
}
|
2021-04-09 10:58:13 +08:00
|
|
|
|
2020-03-27 02:17:59 +08:00
|
|
|
let streams = VideoStreams.find(
|
2019-11-28 21:13:06 +08:00
|
|
|
{ meetingId: Auth.meetingID },
|
2021-04-09 10:58:13 +08:00
|
|
|
{ fields: neededDataTypes },
|
2019-11-28 21:13:06 +08:00
|
|
|
).fetch();
|
2019-08-10 06:28:49 +08:00
|
|
|
|
2021-06-12 01:55:57 +08:00
|
|
|
// Data savings enabled will only show local streams
|
|
|
|
const { viewParticipantsWebcams } = Settings.dataSaving;
|
|
|
|
if (!viewParticipantsWebcams) streams = this.filterLocalOnly(streams);
|
|
|
|
|
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);
|
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
|
|
|
// 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
|
2021-04-09 10:58:13 +08:00
|
|
|
if (isPaginationDisabled) {
|
2023-08-14 20:52:52 +08:00
|
|
|
if (isGridEnabled) {
|
|
|
|
const streamUsers = streams.map((stream) => stream.userId);
|
|
|
|
|
|
|
|
gridUsers = users.filter(
|
|
|
|
(user) => !user.loggedOut && !user.left && !streamUsers.includes(user.userId)
|
|
|
|
).map((user) => ({
|
|
|
|
isGridItem: true,
|
|
|
|
...user,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2020-08-25 03:48:39 +08:00
|
|
|
return {
|
2021-04-09 10:58:13 +08:00
|
|
|
streams: sortVideoStreams(streams, DEFAULT_SORTING),
|
2023-08-14 20:30:53 +08:00
|
|
|
gridUsers,
|
2021-04-09 10:58:13 +08:00
|
|
|
totalNumberOfStreams: streams.length
|
2020-08-25 03:48:39 +08:00
|
|
|
};
|
|
|
|
}
|
2020-08-19 01:00:47 +08:00
|
|
|
|
2021-04-09 10:58:13 +08:00
|
|
|
const paginatedStreams = this.getVideoPage(streams, pageSize);
|
|
|
|
|
2023-08-09 00:05:54 +08:00
|
|
|
if (isGridEnabled) {
|
|
|
|
const streamUsers = paginatedStreams.map((stream) => stream.userId);
|
|
|
|
|
|
|
|
gridUsers = users.filter(
|
|
|
|
(user) => !user.loggedOut && !user.left && !streamUsers.includes(user.userId)
|
|
|
|
).map((user) => ({
|
|
|
|
isGridItem: true,
|
|
|
|
...user,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return { streams: paginatedStreams, gridUsers, totalNumberOfStreams: streams.length };
|
2019-11-28 21:13:06 +08:00
|
|
|
}
|
2019-08-10 06:28:49 +08:00
|
|
|
|
2021-01-22 02:39:21 +08:00
|
|
|
stopConnectingStream () {
|
|
|
|
this.deviceId = null;
|
|
|
|
this.isConnecting = false;
|
|
|
|
}
|
|
|
|
|
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
|
2021-01-22 02:39:21 +08:00
|
|
|
this.stopConnectingStream();
|
2019-11-28 21:13:06 +08:00
|
|
|
}
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
|
2021-04-27 03:05:53 +08:00
|
|
|
getMediaServerAdapter() {
|
2021-04-27 05:05:06 +08:00
|
|
|
return getFromMeetingSettings('media-server-video', DEFAULT_VIDEO_MEDIA_SERVER);
|
2021-04-27 03:05:53 +08:00
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:47 +08:00
|
|
|
getMyRole () {
|
|
|
|
return Users.findOne({ userId: Auth.userID },
|
2020-08-28 03:09:07 +08:00
|
|
|
{ fields: { role: 1 } })?.role;
|
2020-08-19 01:00:47 +08:00
|
|
|
}
|
|
|
|
|
2020-08-22 06:10:25 +08:00
|
|
|
getRecord() {
|
|
|
|
if (this.record === null) {
|
|
|
|
this.record = getFromUserSettings('bbb_record_video', true);
|
|
|
|
}
|
|
|
|
|
2020-08-23 08:00:31 +08:00
|
|
|
// TODO: Remove this
|
|
|
|
// This is a hack to handle a missing piece at the backend of a particular deploy.
|
|
|
|
// If, at the time the video is shared, the user has a viewer role and
|
|
|
|
// meta_hack-record-viewer-video is 'false' this user won't have this video
|
|
|
|
// stream recorded.
|
|
|
|
if (this.hackRecordViewer === null) {
|
2021-04-27 05:05:06 +08:00
|
|
|
const value = getFromMeetingSettings('hack-record-viewer-video', null);
|
2020-08-23 08:00:31 +08:00
|
|
|
this.hackRecordViewer = value ? value.toLowerCase() === 'true' : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const hackRecord = this.getMyRole() === ROLE_MODERATOR || this.hackRecordViewer;
|
|
|
|
|
|
|
|
return this.record && hackRecord;
|
2020-08-22 06:10:25 +08:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-06-12 01:55:57 +08:00
|
|
|
filterLocalOnly(streams) {
|
|
|
|
return streams.filter(stream => stream.userId === Auth.userID);
|
|
|
|
}
|
|
|
|
|
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() {
|
2021-07-08 01:00:47 +08:00
|
|
|
const meeting = Meetings.findOne({ meetingId: Auth.meetingID },
|
2020-03-27 02:17:59 +08:00
|
|
|
{ fields: { 'usersProp.webcamsOnlyForModerator': 1 } });
|
2021-07-08 01:00:47 +08:00
|
|
|
const user = Users.findOne({ userId: Auth.userID }, { fields: { locked: 1, role: 1 } });
|
|
|
|
|
|
|
|
if (meeting?.usersProp && user?.role !== ROLE_MODERATOR && user?.locked) {
|
|
|
|
return meeting.usersProp.webcamsOnlyForModerator;
|
|
|
|
}
|
|
|
|
return false;
|
2020-03-27 02:17:59 +08:00
|
|
|
}
|
|
|
|
|
2022-02-22 21:33:26 +08:00
|
|
|
hasCapReached() {
|
|
|
|
const meeting = Meetings.findOne(
|
|
|
|
{ meetingId: Auth.meetingID },
|
|
|
|
{
|
|
|
|
fields: {
|
2022-03-02 23:58:02 +08:00
|
|
|
'meetingProp.meetingCameraCap': 1,
|
2022-02-22 21:33:26 +08:00
|
|
|
'usersProp.userCameraCap': 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2022-03-02 23:58:02 +08:00
|
|
|
// If the meeting prop data is unreachable, force a safe return
|
|
|
|
if (!meeting?.usersProp || !meeting?.meetingProp) return true;
|
2022-02-22 21:33:26 +08:00
|
|
|
|
2022-03-02 23:58:02 +08:00
|
|
|
const { meetingCameraCap } = meeting.meetingProp;
|
|
|
|
const { userCameraCap } = meeting.usersProp;
|
2022-02-22 21:33:26 +08:00
|
|
|
|
2022-03-02 23:58:02 +08:00
|
|
|
const meetingCap = meetingCameraCap !== 0 && this.getVideoStreamsCount() >= meetingCameraCap;
|
|
|
|
const userCap = userCameraCap !== 0 && this.getLocalVideoStreamsCount() >= userCameraCap;
|
|
|
|
|
|
|
|
return meetingCap || userCap;
|
|
|
|
}
|
|
|
|
|
|
|
|
getVideoStreamsCount() {
|
|
|
|
const streams = VideoStreams.find({}).count();
|
|
|
|
|
|
|
|
return streams;
|
2022-02-22 21:33:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getLocalVideoStreamsCount() {
|
|
|
|
const localStreams = VideoStreams.find(
|
|
|
|
{ userId: Auth.userID }
|
|
|
|
).count();
|
|
|
|
|
|
|
|
return localStreams;
|
|
|
|
}
|
|
|
|
|
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-07-01 05:15:18 +08:00
|
|
|
mirrorOwnWebcam(userId = null) {
|
2020-06-15 03:13:47 +08:00
|
|
|
// only true if setting defined and video ids match
|
2020-07-01 05:15:18 +08:00
|
|
|
const isOwnWebcam = userId ? Auth.userID === userId : true;
|
2020-06-16 04:51:46 +08:00
|
|
|
const isEnabledMirroring = getFromUserSettings('bbb_mirror_own_webcam', MIRROR_WEBCAM);
|
2020-06-16 04:43:02 +08:00
|
|
|
return isOwnWebcam && isEnabledMirroring;
|
2020-06-15 03:13:47 +08:00
|
|
|
}
|
|
|
|
|
2021-12-21 03:02:59 +08:00
|
|
|
isPinEnabled() {
|
|
|
|
return PIN_WEBCAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In user-list it is necessary to check if the user is sharing his webcam
|
|
|
|
isVideoPinEnabledForCurrentUser() {
|
|
|
|
const currentUser = Users.findOne({ userId: Auth.userID },
|
|
|
|
{ fields: { role: 1 } });
|
|
|
|
|
2023-03-15 04:39:06 +08:00
|
|
|
const isModerator = currentUser?.role === 'MODERATOR';
|
2021-12-21 03:02:59 +08:00
|
|
|
const isBreakout = meetingIsBreakout();
|
|
|
|
const isPinEnabled = this.isPinEnabled();
|
|
|
|
|
|
|
|
return !!(isModerator
|
|
|
|
&& isPinEnabled
|
|
|
|
&& !isBreakout);
|
|
|
|
}
|
|
|
|
|
2021-04-03 11:06:39 +08:00
|
|
|
getMyStreamId(deviceId) {
|
2019-12-19 01:44:56 +08:00
|
|
|
const videoStream = VideoStreams.findOne(
|
|
|
|
{
|
|
|
|
meetingId: Auth.meetingID,
|
|
|
|
userId: Auth.userID,
|
2020-03-10 01:47:47 +08:00
|
|
|
deviceId,
|
|
|
|
}, { fields: { stream: 1 } },
|
2019-12-19 01:44:56 +08:00
|
|
|
);
|
|
|
|
return videoStream ? videoStream.stream : null;
|
|
|
|
}
|
|
|
|
|
2019-11-28 21:13:06 +08:00
|
|
|
isUserLocked() {
|
|
|
|
return !!Users.findOne({
|
2021-11-20 02:23:17 +08:00
|
|
|
meetingId: Auth.meetingID,
|
2019-11-28 21:13:06 +08:00
|
|
|
userId: Auth.userID,
|
|
|
|
locked: true,
|
|
|
|
role: { $ne: ROLE_MODERATOR },
|
|
|
|
}, { fields: {} }) && this.disableCam();
|
2018-03-20 01:52:39 +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) {
|
2023-07-26 00:20:45 +08:00
|
|
|
return cameraId?.startsWith(Auth.userID);
|
2019-11-28 21:13:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
playStart(cameraId) {
|
|
|
|
if (this.isLocalStream(cameraId)) {
|
|
|
|
this.sendUserShareWebcam(cameraId);
|
|
|
|
this.joinedVideo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getCameraProfile() {
|
2022-11-04 04:57:54 +08:00
|
|
|
const profileId = BBBStorage.getItem('WebcamProfileId') || '';
|
2019-11-28 21:13:06 +08:00
|
|
|
const cameraProfile = CAMERA_PROFILES.find(profile => profile.id === profileId)
|
|
|
|
|| CAMERA_PROFILES.find(profile => profile.default)
|
|
|
|
|| CAMERA_PROFILES[0];
|
2022-11-04 04:57:54 +08:00
|
|
|
const deviceId = BBBStorage.getItem('WebcamDeviceId');
|
2019-11-28 21:13:06 +08:00
|
|
|
if (deviceId) {
|
|
|
|
cameraProfile.constraints = cameraProfile.constraints || {};
|
|
|
|
cameraProfile.constraints.deviceId = { exact: deviceId };
|
|
|
|
}
|
|
|
|
|
|
|
|
return cameraProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
addCandidateToPeer(peer, candidate, cameraId) {
|
2022-07-12 21:34:03 +08:00
|
|
|
peer.addIceCandidate(candidate).catch((error) => {
|
2019-11-28 21:13:06 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2022-04-05 01:02:50 +08:00
|
|
|
getStatus() {
|
|
|
|
if (this.isConnecting) return 'videoConnecting';
|
|
|
|
if (this.isConnected) return 'connected';
|
|
|
|
return 'disconnected';
|
|
|
|
}
|
|
|
|
|
2020-09-10 02:07:32 +08:00
|
|
|
disableReason() {
|
|
|
|
const locks = {
|
|
|
|
videoLocked: this.isUserLocked(),
|
2022-03-02 23:58:02 +08:00
|
|
|
camCapReached: this.hasCapReached() && !this.hasVideoStream(),
|
2020-09-10 02:07:32 +08:00
|
|
|
meteorDisconnected: !Meteor.status().connected
|
|
|
|
};
|
|
|
|
const locksKeys = Object.keys(locks);
|
|
|
|
const disableReason = locksKeys.filter( i => locks[i]).shift();
|
|
|
|
return disableReason ? disableReason : false;
|
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
|
|
|
|
2019-12-19 01:44:56 +08:00
|
|
|
getUserParameterProfile() {
|
2020-03-27 05:15:41 +08:00
|
|
|
if (this.userParameterProfile === null) {
|
|
|
|
this.userParameterProfile = getFromUserSettings(
|
|
|
|
'bbb_preferred_camera_profile',
|
2022-10-03 19:10:08 +08:00
|
|
|
(CAMERA_PROFILES.find(i => i.default) || {}).id || null,
|
2020-03-27 05:15:41 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-19 01:44:56 +08:00
|
|
|
return this.userParameterProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10 01:47:47 +08:00
|
|
|
return MULTIPLE_CAMERAS
|
2021-02-02 02:47:05 +08:00
|
|
|
&& !VideoPreviewService.getSkipVideoPreview()
|
2020-03-10 01:47:47 +08:00
|
|
|
&& !this.isMobile
|
|
|
|
&& !this.isSafari
|
|
|
|
&& this.numberOfDevices > 1;
|
2019-12-19 01:44:56 +08:00
|
|
|
}
|
|
|
|
|
2020-05-27 01:05:04 +08:00
|
|
|
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();
|
2021-05-13 03:42:07 +08:00
|
|
|
const normalizedBitrate = bitrate * 1000;
|
|
|
|
|
|
|
|
// The encoder parameters might not be up yet; if that's the case,
|
|
|
|
// add a filler object so we can alter the parameters anyways
|
|
|
|
if (parameters.encodings == null || parameters.encodings.length === 0) {
|
2020-05-27 01:05:04 +08:00
|
|
|
parameters.encodings = [{}];
|
|
|
|
}
|
|
|
|
|
2020-05-27 23:15:48 +08:00
|
|
|
// 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,
|
2022-03-14 22:27:42 +08:00
|
|
|
height: trackSettings.height,
|
2020-05-27 23:15:48 +08:00
|
|
|
};
|
|
|
|
}
|
2022-03-14 22:27:42 +08:00
|
|
|
|
|
|
|
return constraints;
|
2020-05-27 23:15:48 +08:00
|
|
|
}
|
|
|
|
|
2020-05-27 01:05:04 +08:00
|
|
|
applyCameraProfile (peer, profileId) {
|
2022-03-14 22:27:42 +08:00
|
|
|
const profile = CAMERA_PROFILES.find((targetProfile) => targetProfile.id === profileId);
|
|
|
|
|
|
|
|
// When this should be skipped:
|
|
|
|
// 1 - Badly defined profile
|
|
|
|
// 2 - Badly defined peer (ie {})
|
|
|
|
// 3 - The target profile is already applied
|
|
|
|
// 4 - The targetr profile is better than the original profile
|
|
|
|
if (!profile
|
|
|
|
|| peer == null
|
|
|
|
|| peer.peerConnection == null
|
|
|
|
|| peer.currentProfileId === profileId
|
2020-05-27 01:05:04 +08:00
|
|
|
|| this.isProfileBetter(profileId, peer.originalProfileId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { bitrate, constraints } = profile;
|
|
|
|
|
2022-03-14 22:27:42 +08:00
|
|
|
if (bitrate) this.applyBitrate(peer, bitrate);
|
2020-05-27 01:05:04 +08:00
|
|
|
|
2022-03-14 22:27:42 +08:00
|
|
|
if (CAMERA_QUALITY_THR_CONSTRAINTS
|
|
|
|
&& constraints
|
|
|
|
&& typeof constraints === 'object'
|
|
|
|
) {
|
|
|
|
peer.peerConnection.getSenders().forEach((sender) => {
|
2020-05-27 01:05:04 +08:00
|
|
|
const { track } = sender;
|
2022-03-14 22:27:42 +08:00
|
|
|
if (track && track.kind === 'video' && typeof track.applyConstraints === 'function') {
|
|
|
|
const normalizedVideoConstraints = this.reapplyResolutionIfNeeded(track, constraints);
|
2020-05-27 23:15:48 +08:00
|
|
|
track.applyConstraints(normalizedVideoConstraints)
|
2022-03-14 22:27:42 +08:00
|
|
|
.catch((error) => {
|
2020-05-27 01:05:04 +08:00
|
|
|
logger.warn({
|
2022-03-14 22:27:42 +08:00
|
|
|
logCode: 'video_provider_constraintchange_failed',
|
2020-05-27 01:05:04 +08:00
|
|
|
extraInfo: { errorName: error.name, errorCode: error.code },
|
|
|
|
}, 'Error applying camera profile');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-03-14 22:27:42 +08:00
|
|
|
|
|
|
|
logger.info({
|
|
|
|
logCode: 'video_provider_profile_applied',
|
|
|
|
extraInfo: { profileId },
|
|
|
|
}, `New camera profile applied: ${profileId}`);
|
|
|
|
|
|
|
|
peer.currentProfileId = profileId;
|
2020-05-27 01:05:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2021-04-03 11:06:39 +08:00
|
|
|
|
|
|
|
getPreloadedStream () {
|
|
|
|
if (this.deviceId == null) return;
|
|
|
|
return VideoPreviewService.getStream(this.deviceId);
|
|
|
|
}
|
2021-08-31 02:11:16 +08:00
|
|
|
|
2021-08-14 04:24:44 +08:00
|
|
|
/**
|
|
|
|
* Get all active video peers.
|
|
|
|
* @returns An Object containing the reference for all active peers peers
|
|
|
|
*/
|
|
|
|
getActivePeers() {
|
|
|
|
const videoData = this.getVideoStreams();
|
|
|
|
|
|
|
|
if (!videoData) return null;
|
|
|
|
|
|
|
|
const { streams: activeVideoStreams } = videoData;
|
|
|
|
|
|
|
|
if (!activeVideoStreams) return null;
|
|
|
|
|
|
|
|
const activePeers = {};
|
|
|
|
|
|
|
|
activeVideoStreams.forEach((stream) => {
|
2021-12-16 23:12:52 +08:00
|
|
|
if (this.webRtcPeersRef[stream.stream]) {
|
|
|
|
activePeers[stream.stream] = this.webRtcPeersRef[stream.stream].peerConnection;
|
2021-08-14 04:24:44 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return activePeers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get stats about all active video peer.
|
2021-08-23 22:07:12 +08:00
|
|
|
* We filter the status based on FILTER_VIDEO_STATS constant.
|
2021-08-14 04:24:44 +08:00
|
|
|
*
|
|
|
|
* For more information see:
|
|
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats
|
2021-08-23 23:36:01 +08:00
|
|
|
* and
|
|
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport
|
|
|
|
* @returns An Object containing the information about each active peer.
|
|
|
|
* The returned object follows the format:
|
|
|
|
* {
|
|
|
|
* peerId: RTCStatsReport
|
|
|
|
* }
|
2021-08-14 04:24:44 +08:00
|
|
|
*/
|
|
|
|
async getStats() {
|
|
|
|
const peers = this.getActivePeers();
|
|
|
|
|
|
|
|
if (!peers) return null;
|
|
|
|
|
|
|
|
const stats = {};
|
|
|
|
|
2021-08-31 02:11:16 +08:00
|
|
|
await Promise.all(
|
|
|
|
Object.keys(peers).map(async (peerId) => {
|
|
|
|
const peerStats = await peers[peerId].getStats();
|
2021-08-14 04:24:44 +08:00
|
|
|
|
2021-08-31 02:11:16 +08:00
|
|
|
const videoStats = {};
|
2021-08-14 04:24:44 +08:00
|
|
|
|
2021-08-31 02:11:16 +08:00
|
|
|
peerStats.forEach((stat) => {
|
|
|
|
if (FILTER_VIDEO_STATS.includes(stat.type)) {
|
|
|
|
videoStats[stat.type] = stat;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
stats[peerId] = videoStats;
|
|
|
|
})
|
|
|
|
);
|
2021-08-14 04:24:44 +08:00
|
|
|
|
|
|
|
return stats;
|
|
|
|
}
|
2021-12-16 23:12:52 +08:00
|
|
|
|
|
|
|
updatePeerDictionaryReference(newRef) {
|
|
|
|
this.webRtcPeersRef = newRef;
|
|
|
|
}
|
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 {
|
2021-03-27 03:51:39 +08:00
|
|
|
storeDeviceIds: () => videoService.storeDeviceIds(),
|
2018-01-11 09:15:44 +08:00
|
|
|
exitVideo: () => videoService.exitVideo(),
|
2021-07-20 04:19: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(),
|
2021-04-03 11:06:39 +08:00
|
|
|
getMyStreamId: deviceId => videoService.getMyStreamId(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(),
|
2022-04-05 01:02:50 +08:00
|
|
|
getStatus: () => videoService.getStatus(),
|
2020-09-10 02:07:32 +08:00
|
|
|
disableReason: () => videoService.disableReason(),
|
2019-11-28 21:13:06 +08:00
|
|
|
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),
|
2021-04-27 03:05:53 +08:00
|
|
|
getMediaServerAdapter: () => videoService.getMediaServerAdapter(),
|
2020-08-22 06:10:25 +08:00
|
|
|
getRecord: () => videoService.getRecord(),
|
2019-11-29 04:28:41 +08:00
|
|
|
getSharedDevices: () => videoService.getSharedDevices(),
|
2019-12-19 01:44:56 +08:00
|
|
|
getUserParameterProfile: () => videoService.getUserParameterProfile(),
|
|
|
|
isMultipleCamerasEnabled: () => videoService.isMultipleCamerasEnabled(),
|
2020-07-01 05:15:18 +08:00
|
|
|
mirrorOwnWebcam: userId => videoService.mirrorOwnWebcam(userId),
|
2022-02-22 21:33:26 +08:00
|
|
|
hasCapReached: () => videoService.hasCapReached(),
|
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),
|
2023-03-01 21:39:04 +08:00
|
|
|
applyCameraProfile: debounce(
|
2023-08-10 00:26:42 +08:00
|
|
|
videoService.applyCameraProfile.bind(videoService),
|
|
|
|
CAMERA_QUALITY_THR_DEBOUNCE,
|
|
|
|
{ leading: false, trailing: true },
|
2022-03-14 22:27:42 +08:00
|
|
|
),
|
2020-05-27 01:05:04 +08:00
|
|
|
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 },
|
2021-06-11 02:05:51 +08:00
|
|
|
getUsersIdFromVideoStreams: () => videoService.getUsersIdFromVideoStreams(),
|
2020-08-29 03:29:45 +08:00
|
|
|
shouldRenderPaginationToggle: () => videoService.shouldRenderPaginationToggle(),
|
2021-12-21 03:02:59 +08:00
|
|
|
toggleVideoPin: (userId, pin) => videoService.toggleVideoPin(userId, pin),
|
|
|
|
getVideoPinByUser: (userId) => videoService.getVideoPinByUser(userId),
|
|
|
|
isVideoPinEnabledForCurrentUser: () => videoService.isVideoPinEnabledForCurrentUser(),
|
|
|
|
isPinEnabled: () => videoService.isPinEnabled(),
|
2021-04-03 11:06:39 +08:00
|
|
|
getPreloadedStream: () => videoService.getPreloadedStream(),
|
2021-08-14 04:24:44 +08:00
|
|
|
getStats: () => videoService.getStats(),
|
2021-12-16 23:12:52 +08:00
|
|
|
updatePeerDictionaryReference: (newRef) => videoService.updatePeerDictionaryReference(newRef),
|
2017-09-01 23:26:57 +08:00
|
|
|
};
|