2024-05-29 21:26:11 +08:00
|
|
|
import { getSettingsSingletonInstance } from '/imports/ui/services/settings';
|
2024-04-20 04:34:43 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import { notify } from '/imports/ui/services/notification';
|
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
|
|
|
import VideoPreviewService from '/imports/ui/components/video-preview/service';
|
|
|
|
import Storage from '/imports/ui/services/storage/session';
|
2024-05-29 21:26:11 +08:00
|
|
|
import { getStorageSingletonInstance } from '/imports/ui/services/storage';
|
2024-04-20 04:34:43 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
|
|
|
import getFromMeetingSettings from '/imports/ui/services/meeting-settings';
|
2024-05-02 03:48:12 +08:00
|
|
|
import {
|
|
|
|
setVideoState,
|
|
|
|
setConnectingStream,
|
|
|
|
getVideoState,
|
|
|
|
} from './state';
|
|
|
|
import WebRtcPeer from '/imports/ui/services/webrtc-base/peer';
|
2024-05-06 22:24:45 +08:00
|
|
|
import { Constraints2 } from '/imports/ui/Types/meetingClientSettings';
|
2024-05-02 20:24:03 +08:00
|
|
|
import MediaStreamUtils from '/imports/utils/media-stream-utils';
|
2024-06-06 21:50:03 +08:00
|
|
|
import Session from '/imports/ui/services/storage/in-memory';
|
2024-07-30 21:20:18 +08:00
|
|
|
import type { Stream, StreamItem } from './types';
|
2024-07-19 20:52:55 +08:00
|
|
|
import { VIDEO_TYPES } from './enums';
|
2024-04-20 04:34:43 +08:00
|
|
|
|
|
|
|
const TOKEN = '_';
|
|
|
|
|
2024-07-30 21:20:18 +08:00
|
|
|
const FILTER_VIDEO_STATS = [
|
|
|
|
'outbound-rtp',
|
|
|
|
'inbound-rtp',
|
|
|
|
];
|
|
|
|
|
2024-04-20 04:34:43 +08:00
|
|
|
class VideoService {
|
2024-05-02 03:48:12 +08:00
|
|
|
public isMobile: boolean;
|
|
|
|
|
|
|
|
public webRtcPeersRef: Record<string, WebRtcPeer>;
|
|
|
|
|
|
|
|
private userParameterProfile: string | null;
|
|
|
|
|
|
|
|
private isSafari: boolean;
|
|
|
|
|
|
|
|
private numberOfDevices: number;
|
|
|
|
|
|
|
|
private record: boolean | null;
|
|
|
|
|
|
|
|
private hackRecordViewer: boolean | null;
|
|
|
|
|
|
|
|
private deviceId: string | null = null;
|
|
|
|
|
2024-07-30 21:20:18 +08:00
|
|
|
private activePeers: Record<string, RTCPeerConnection>;
|
|
|
|
|
2024-05-30 04:43:17 +08:00
|
|
|
private readonly clientSessionUUID: string;
|
2024-05-08 05:05:36 +08:00
|
|
|
|
2024-04-20 04:34:43 +08:00
|
|
|
constructor() {
|
|
|
|
this.userParameterProfile = null;
|
|
|
|
this.isMobile = deviceInfo.isMobile;
|
|
|
|
this.isSafari = browserInfo.isSafari;
|
|
|
|
this.numberOfDevices = 0;
|
|
|
|
this.record = null;
|
|
|
|
this.hackRecordViewer = null;
|
2024-05-30 04:43:17 +08:00
|
|
|
this.clientSessionUUID = sessionStorage.getItem('clientSessionUUID') || '0';
|
2024-04-20 04:34:43 +08:00
|
|
|
|
|
|
|
if (navigator.mediaDevices) {
|
|
|
|
this.updateNumberOfDevices = this.updateNumberOfDevices.bind(this);
|
|
|
|
if (!this.isSafari) {
|
2024-05-02 03:48:12 +08:00
|
|
|
navigator.mediaDevices.ondevicechange = () => this.updateNumberOfDevices();
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
this.updateNumberOfDevices();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.webRtcPeersRef = {};
|
2024-07-30 21:20:18 +08:00
|
|
|
this.activePeers = {};
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static fetchNumberOfDevices(devices: MediaDeviceInfo[]) {
|
|
|
|
const deviceIds: string[] = [];
|
2024-04-20 04:34:43 +08:00
|
|
|
devices.forEach((d) => {
|
2024-05-02 03:48:12 +08:00
|
|
|
const validDeviceId = d.deviceId !== '' && !deviceIds.includes(d.deviceId);
|
2024-04-20 04:34:43 +08:00
|
|
|
if (d.kind === 'videoinput' && validDeviceId) {
|
|
|
|
deviceIds.push(d.deviceId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return deviceIds.length;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
updateNumberOfDevices(devices: MediaDeviceInfo[] | null = null) {
|
2024-04-20 04:34:43 +08:00
|
|
|
if (devices) {
|
2024-05-02 03:48:12 +08:00
|
|
|
this.numberOfDevices = VideoService.fetchNumberOfDevices(devices);
|
2024-04-20 04:34:43 +08:00
|
|
|
} else {
|
|
|
|
navigator.mediaDevices.enumerateDevices().then((devices) => {
|
2024-05-02 03:48:12 +08:00
|
|
|
this.numberOfDevices = VideoService.fetchNumberOfDevices(devices);
|
2024-04-20 04:34:43 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-14 21:30:48 +08:00
|
|
|
joinVideo(deviceId: string, isUserLocked: boolean) {
|
2024-04-20 04:34:43 +08:00
|
|
|
this.deviceId = deviceId;
|
|
|
|
Storage.setItem('isFirstJoin', false);
|
2024-06-14 21:30:48 +08:00
|
|
|
if (!isUserLocked) {
|
2024-05-08 05:05:36 +08:00
|
|
|
const streamName = this.buildStreamName(deviceId);
|
2024-04-20 04:34:43 +08:00
|
|
|
const stream = {
|
|
|
|
stream: streamName,
|
2024-06-06 21:50:03 +08:00
|
|
|
userId: Auth.userID as string,
|
|
|
|
name: Auth.fullname as string,
|
2024-06-08 04:41:36 +08:00
|
|
|
nameSortable: Auth.fullname as string,
|
2024-07-19 20:52:55 +08:00
|
|
|
type: VIDEO_TYPES.CONNECTING,
|
2024-04-20 04:34:43 +08:00
|
|
|
};
|
|
|
|
setConnectingStream(stream);
|
2024-07-19 20:52:55 +08:00
|
|
|
setVideoState({ isConnecting: true });
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-07 04:05:37 +08:00
|
|
|
static joinedVideo() {
|
2024-07-19 20:52:55 +08:00
|
|
|
setVideoState({
|
2024-04-20 04:34:43 +08:00
|
|
|
isConnected: true,
|
|
|
|
isConnecting: false,
|
2024-07-19 20:52:55 +08:00
|
|
|
});
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-08 05:05:36 +08:00
|
|
|
storeDeviceIds(streams: Stream[]) {
|
2024-05-02 03:48:12 +08:00
|
|
|
const deviceIds: string[] = [];
|
2024-05-08 05:05:36 +08:00
|
|
|
streams
|
|
|
|
.filter((s) => this.isLocalStream(s.stream))
|
|
|
|
.forEach((s) => {
|
|
|
|
deviceIds.push(s.deviceId);
|
|
|
|
});
|
2024-06-06 21:50:03 +08:00
|
|
|
Session.setItem('deviceIds', deviceIds.join());
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
exitedVideo() {
|
|
|
|
this.stopConnectingStream();
|
2024-07-19 20:52:55 +08:00
|
|
|
setVideoState({
|
2024-04-20 04:34:43 +08:00
|
|
|
isConnected: false,
|
2024-07-19 20:52:55 +08:00
|
|
|
isConnecting: false,
|
|
|
|
});
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static getAuthenticatedURL() {
|
2024-05-29 21:26:11 +08:00
|
|
|
const SFU_URL = window.meetingClientSettings.public.kurento.wsUrl;
|
2024-04-20 04:34:43 +08:00
|
|
|
return Auth.authenticateURL(SFU_URL);
|
|
|
|
}
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
static getCameraProfiles() {
|
|
|
|
return window.meetingClientSettings.public.kurento.cameraProfiles;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static isPaginationEnabled() {
|
2024-05-29 21:26:11 +08:00
|
|
|
const Settings = getSettingsSingletonInstance();
|
2024-04-20 04:34:43 +08:00
|
|
|
return Settings.application.paginationEnabled;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static setCurrentVideoPageIndex(newVideoPageIndex: number) {
|
|
|
|
const { currentVideoPageIndex } = getVideoState();
|
2024-04-20 04:34:43 +08:00
|
|
|
if (currentVideoPageIndex !== newVideoPageIndex) {
|
2024-07-19 20:52:55 +08:00
|
|
|
setVideoState({ currentVideoPageIndex: newVideoPageIndex });
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static getCurrentVideoPageIndex() {
|
|
|
|
const { currentVideoPageIndex } = getVideoState();
|
2024-04-20 04:34:43 +08:00
|
|
|
return currentVideoPageIndex;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static calculateNextPage() {
|
|
|
|
const { numberOfPages, currentVideoPageIndex } = getVideoState();
|
2024-04-20 04:34:43 +08:00
|
|
|
if (numberOfPages === 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
return (((currentVideoPageIndex + 1) % numberOfPages) + numberOfPages) % numberOfPages;
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static calculatePreviousPage() {
|
|
|
|
const { numberOfPages, currentVideoPageIndex } = getVideoState();
|
2024-04-20 04:34:43 +08:00
|
|
|
if (numberOfPages === 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
return (((currentVideoPageIndex - 1) % numberOfPages) + numberOfPages) % numberOfPages;
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static getNextVideoPage() {
|
|
|
|
const nextPage = VideoService.calculateNextPage();
|
|
|
|
VideoService.setCurrentVideoPageIndex(nextPage);
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static getPreviousVideoPage() {
|
|
|
|
const previousPage = VideoService.calculatePreviousPage();
|
|
|
|
VideoService.setCurrentVideoPageIndex(previousPage);
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static isGridEnabled() {
|
2024-06-06 21:50:03 +08:00
|
|
|
return Session.getItem('isGridEnabled');
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stopConnectingStream() {
|
|
|
|
this.deviceId = null;
|
|
|
|
setConnectingStream(null);
|
|
|
|
}
|
|
|
|
|
2024-05-08 05:05:36 +08:00
|
|
|
buildStreamName(deviceId: string) {
|
|
|
|
return `${this.getPrefix()}${TOKEN}${deviceId}`;
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static getMediaServerAdapter() {
|
2024-05-29 21:26:11 +08:00
|
|
|
const DEFAULT_VIDEO_MEDIA_SERVER = window.meetingClientSettings.public.kurento.videoMediaServer;
|
2024-04-20 04:34:43 +08:00
|
|
|
return getFromMeetingSettings('media-server-video', DEFAULT_VIDEO_MEDIA_SERVER);
|
|
|
|
}
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
static getRoleModerator() {
|
|
|
|
return window.meetingClientSettings.public.user.role_moderator;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRoleViewer() {
|
|
|
|
return window.meetingClientSettings.public.user.role_viewer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getPageChangeDebounceTime() {
|
|
|
|
const {
|
|
|
|
pageChangeDebounceTime: PAGE_CHANGE_DEBOUNCE_TIME,
|
|
|
|
} = window.meetingClientSettings.public.kurento.pagination;
|
|
|
|
|
|
|
|
return PAGE_CHANGE_DEBOUNCE_TIME;
|
|
|
|
}
|
|
|
|
|
2024-06-14 22:35:53 +08:00
|
|
|
getRecord(myRole?: string) {
|
2024-05-29 21:26:11 +08:00
|
|
|
const ROLE_MODERATOR = VideoService.getRoleModerator();
|
|
|
|
|
2024-04-20 04:34:43 +08:00
|
|
|
if (this.record === null) {
|
|
|
|
this.record = getFromUserSettings('bbb_record_video', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.hackRecordViewer === null) {
|
|
|
|
const value = getFromMeetingSettings('hack-record-viewer-video', null);
|
|
|
|
this.hackRecordViewer = value ? value.toLowerCase() === 'true' : true;
|
|
|
|
}
|
|
|
|
|
2024-06-14 22:35:53 +08:00
|
|
|
const hackRecord = myRole === ROLE_MODERATOR || this.hackRecordViewer;
|
2024-04-20 04:34:43 +08:00
|
|
|
|
|
|
|
return this.record && hackRecord;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static mirrorOwnWebcam(userId: string | null = null) {
|
2024-05-29 21:26:11 +08:00
|
|
|
const MIRROR_WEBCAM = window.meetingClientSettings.public.app.mirrorOwnWebcam;
|
2024-04-20 04:34:43 +08:00
|
|
|
const isOwnWebcam = userId ? Auth.userID === userId : true;
|
|
|
|
const isEnabledMirroring = getFromUserSettings('bbb_mirror_own_webcam', MIRROR_WEBCAM);
|
|
|
|
return isOwnWebcam && isEnabledMirroring;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static isPinEnabled() {
|
2024-05-29 21:26:11 +08:00
|
|
|
return window.meetingClientSettings.public.kurento.enableVideoPin;
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-08 05:05:36 +08:00
|
|
|
getMyStreamId(deviceId: string, streams: Stream[]) {
|
|
|
|
const videoStream = streams.find(
|
|
|
|
(vs) => this.isLocalStream(vs.stream)
|
|
|
|
&& vs.deviceId === deviceId,
|
|
|
|
);
|
2024-04-20 04:34:43 +08:00
|
|
|
return videoStream ? videoStream.stream : null;
|
|
|
|
}
|
|
|
|
|
2024-05-08 05:05:36 +08:00
|
|
|
isLocalStream(cameraId = '') {
|
|
|
|
return cameraId.startsWith(this.getPrefix());
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static getCameraProfile() {
|
2024-05-29 21:26:11 +08:00
|
|
|
const CAMERA_PROFILES = VideoService.getCameraProfiles();
|
|
|
|
const BBBStorage = getStorageSingletonInstance();
|
2024-04-20 04:34:43 +08:00
|
|
|
const profileId = BBBStorage.getItem('WebcamProfileId') || '';
|
2024-05-02 03:48:12 +08:00
|
|
|
const cameraProfile = CAMERA_PROFILES.find((profile) => profile.id === profileId)
|
|
|
|
|| CAMERA_PROFILES.find((profile) => profile.default)
|
2024-04-20 04:34:43 +08:00
|
|
|
|| CAMERA_PROFILES[0];
|
|
|
|
const deviceId = BBBStorage.getItem('WebcamDeviceId');
|
|
|
|
if (deviceId) {
|
2024-05-02 03:48:12 +08:00
|
|
|
// @ts-expect-error -> Untyped object.
|
2024-04-20 04:34:43 +08:00
|
|
|
cameraProfile.constraints = cameraProfile.constraints || {};
|
2024-05-02 03:48:12 +08:00
|
|
|
// @ts-expect-error -> Untyped object.
|
2024-04-20 04:34:43 +08:00
|
|
|
cameraProfile.constraints.deviceId = { exact: deviceId };
|
|
|
|
}
|
|
|
|
|
|
|
|
return cameraProfile;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static addCandidateToPeer(peer: WebRtcPeer, candidate: Record<string | symbol, unknown>, cameraId: string) {
|
|
|
|
peer.addIceCandidate(candidate).catch((error: Error) => {
|
2024-04-20 04:34:43 +08:00
|
|
|
if (error) {
|
|
|
|
logger.error({
|
|
|
|
logCode: 'video_provider_addicecandidate_error',
|
|
|
|
extraInfo: {
|
|
|
|
cameraId,
|
|
|
|
error,
|
|
|
|
},
|
|
|
|
}, `Adding ICE candidate failed for ${cameraId} due to ${error.message}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static processInboundIceQueue(peer: WebRtcPeer, cameraId: string) {
|
|
|
|
// @ts-expect-error -> Untyped object.
|
2024-04-20 04:34:43 +08:00
|
|
|
while (peer.inboundIceQueue.length) {
|
2024-05-02 03:48:12 +08:00
|
|
|
// @ts-expect-error -> Untyped object.
|
2024-04-20 04:34:43 +08:00
|
|
|
const candidate = peer.inboundIceQueue.shift();
|
2024-05-02 03:48:12 +08:00
|
|
|
VideoService.addCandidateToPeer(peer, candidate, cameraId);
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static getRole(isLocal: boolean) {
|
2024-04-20 04:34:43 +08:00
|
|
|
return isLocal ? 'share' : 'viewer';
|
|
|
|
}
|
|
|
|
|
|
|
|
getUserParameterProfile() {
|
2024-05-29 21:26:11 +08:00
|
|
|
const CAMERA_PROFILES = VideoService.getCameraProfiles();
|
2024-04-20 04:34:43 +08:00
|
|
|
if (this.userParameterProfile === null) {
|
|
|
|
this.userParameterProfile = getFromUserSettings(
|
|
|
|
'bbb_preferred_camera_profile',
|
2024-05-02 03:48:12 +08:00
|
|
|
(CAMERA_PROFILES.find((i) => i.default) || {}).id || null,
|
2024-04-20 04:34:43 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.userParameterProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
isMultipleCamerasEnabled() {
|
2024-05-29 21:26:11 +08:00
|
|
|
const MULTIPLE_CAMERAS = window.meetingClientSettings.public.app.enableMultipleCameras;
|
2024-04-20 04:34:43 +08:00
|
|
|
return MULTIPLE_CAMERAS
|
|
|
|
&& !VideoPreviewService.getSkipVideoPreview()
|
|
|
|
&& !this.isMobile
|
|
|
|
&& !this.isSafari
|
|
|
|
&& this.numberOfDevices > 1;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static isProfileBetter(newProfileId: string, originalProfileId: string) {
|
2024-05-29 21:26:11 +08:00
|
|
|
const CAMERA_PROFILES = VideoService.getCameraProfiles();
|
2024-04-20 04:34:43 +08:00
|
|
|
return CAMERA_PROFILES.findIndex(({ id }) => id === newProfileId)
|
|
|
|
> CAMERA_PROFILES.findIndex(({ id }) => id === originalProfileId);
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static applyBitrate(peer: WebRtcPeer, bitrate: number) {
|
|
|
|
const { peerConnection } = peer;
|
2024-04-20 04:34:43 +08:00
|
|
|
if ('RTCRtpSender' in window
|
|
|
|
&& 'setParameters' in window.RTCRtpSender.prototype
|
|
|
|
&& 'getParameters' in window.RTCRtpSender.prototype) {
|
2024-05-02 03:48:12 +08:00
|
|
|
peerConnection.getSenders().forEach((sender: RTCRtpSender) => {
|
2024-04-20 04:34:43 +08:00
|
|
|
const { track } = sender;
|
|
|
|
if (track && track.kind === 'video') {
|
|
|
|
const parameters = sender.getParameters();
|
|
|
|
const normalizedBitrate = bitrate * 1000;
|
|
|
|
|
|
|
|
if (parameters.encodings == null || parameters.encodings.length === 0) {
|
|
|
|
parameters.encodings = [{}];
|
|
|
|
}
|
|
|
|
|
|
|
|
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}`);
|
|
|
|
})
|
2024-05-02 03:48:12 +08:00
|
|
|
.catch((error) => {
|
2024-04-20 04:34:43 +08:00
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_provider_bitratechange_failed',
|
|
|
|
extraInfo: { bitrate, errorMessage: error.message, errorCode: error.code },
|
2024-05-02 03:48:12 +08:00
|
|
|
}, 'Bitrate change failed.');
|
2024-04-20 04:34:43 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2024-05-02 03:48:12 +08:00
|
|
|
});
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static reapplyResolutionIfNeeded(track: MediaStreamTrack, constraints?: Constraints2) {
|
2024-04-20 04:34:43 +08:00
|
|
|
if (typeof track.getSettings !== 'function') {
|
|
|
|
return constraints;
|
|
|
|
}
|
|
|
|
|
|
|
|
const trackSettings = track.getSettings();
|
|
|
|
|
|
|
|
if (trackSettings.width && trackSettings.height) {
|
|
|
|
return {
|
|
|
|
...constraints,
|
|
|
|
width: trackSettings.width,
|
|
|
|
height: trackSettings.height,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return constraints;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static applyCameraProfile(peer: WebRtcPeer, profileId: string) {
|
2024-05-29 21:26:11 +08:00
|
|
|
const CAMERA_PROFILES = VideoService.getCameraProfiles();
|
2024-04-20 04:34:43 +08:00
|
|
|
const profile = CAMERA_PROFILES.find((targetProfile) => targetProfile.id === profileId);
|
2024-05-29 21:26:11 +08:00
|
|
|
const {
|
|
|
|
applyConstraints: CAMERA_QUALITY_THR_CONSTRAINTS = false,
|
|
|
|
} = window.meetingClientSettings.public.kurento.cameraQualityThresholds;
|
2024-04-20 04:34:43 +08:00
|
|
|
|
|
|
|
if (!profile
|
|
|
|
|| peer == null
|
|
|
|
|| peer.peerConnection == null
|
2024-05-02 03:48:12 +08:00
|
|
|
// @ts-expect-error -> Untyped object.
|
2024-04-20 04:34:43 +08:00
|
|
|
|| peer.currentProfileId === profileId
|
2024-05-02 03:48:12 +08:00
|
|
|
// @ts-expect-error -> Untyped object.
|
|
|
|
|| VideoService.isProfileBetter(profileId, peer.originalProfileId)) {
|
2024-04-20 04:34:43 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { bitrate, constraints } = profile;
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
if (bitrate) VideoService.applyBitrate(peer, bitrate);
|
2024-04-20 04:34:43 +08:00
|
|
|
|
|
|
|
if (CAMERA_QUALITY_THR_CONSTRAINTS
|
|
|
|
&& constraints
|
|
|
|
&& typeof constraints === 'object'
|
|
|
|
) {
|
2024-05-02 03:48:12 +08:00
|
|
|
peer.peerConnection.getSenders().forEach((sender: RTCRtpSender) => {
|
2024-04-20 04:34:43 +08:00
|
|
|
const { track } = sender;
|
|
|
|
if (track && track.kind === 'video' && typeof track.applyConstraints === 'function') {
|
2024-05-02 03:48:12 +08:00
|
|
|
const normalizedVideoConstraints = VideoService.reapplyResolutionIfNeeded(track, constraints);
|
2024-04-20 04:34:43 +08:00
|
|
|
track.applyConstraints(normalizedVideoConstraints)
|
|
|
|
.catch((error) => {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'video_provider_constraintchange_failed',
|
|
|
|
extraInfo: { errorName: error.name, errorCode: error.code },
|
|
|
|
}, 'Error applying camera profile');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info({
|
|
|
|
logCode: 'video_provider_profile_applied',
|
|
|
|
extraInfo: { profileId },
|
|
|
|
}, `New camera profile applied: ${profileId}`);
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
// @ts-expect-error -> Untyped object.
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
2024-04-20 04:34:43 +08:00
|
|
|
peer.currentProfileId = profileId;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
static getThreshold(numberOfPublishers: number) {
|
2024-05-29 21:26:11 +08:00
|
|
|
const {
|
|
|
|
thresholds: CAMERA_QUALITY_THRESHOLDS = [],
|
|
|
|
} = window.meetingClientSettings.public.kurento.cameraQualityThresholds;
|
|
|
|
|
2024-04-20 04:34:43 +08:00
|
|
|
let targetThreshold = { threshold: 0, profile: 'original' };
|
|
|
|
let finalThreshold = { threshold: 0, profile: 'original' };
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
for (let mapIndex = 0; mapIndex < CAMERA_QUALITY_THRESHOLDS.length; mapIndex += 1) {
|
2024-04-20 04:34:43 +08:00
|
|
|
targetThreshold = CAMERA_QUALITY_THRESHOLDS[mapIndex];
|
|
|
|
if (targetThreshold.threshold <= numberOfPublishers) {
|
|
|
|
finalThreshold = targetThreshold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return finalThreshold;
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
getPreloadedStream() {
|
|
|
|
if (this.deviceId == null) return null;
|
2024-04-20 04:34:43 +08:00
|
|
|
return VideoPreviewService.getStream(this.deviceId);
|
|
|
|
}
|
|
|
|
|
2024-05-02 03:48:12 +08:00
|
|
|
updatePeerDictionaryReference(newRef: Record<string, WebRtcPeer>) {
|
2024-04-20 04:34:43 +08:00
|
|
|
this.webRtcPeersRef = newRef;
|
|
|
|
}
|
2024-05-02 20:24:03 +08:00
|
|
|
|
2024-05-02 22:51:14 +08:00
|
|
|
setTrackEnabled(value: boolean) {
|
2024-05-02 20:24:03 +08:00
|
|
|
const localPeers = Object.values(this.webRtcPeersRef).filter(
|
2024-05-02 22:51:14 +08:00
|
|
|
// @ts-expect-error -> Until all codebase is in Typescript.
|
2024-05-02 20:24:03 +08:00
|
|
|
(peer) => peer.isPublisher,
|
|
|
|
);
|
|
|
|
localPeers.forEach((peer) => {
|
|
|
|
const stream = peer.getLocalStream();
|
2024-05-02 22:51:14 +08:00
|
|
|
MediaStreamUtils.getVideoTracks(stream).forEach((track: MediaStreamTrack) => {
|
2024-05-02 20:24:03 +08:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
track.enabled = value;
|
|
|
|
});
|
|
|
|
});
|
2024-05-02 22:51:14 +08:00
|
|
|
}
|
2024-05-08 05:05:36 +08:00
|
|
|
|
|
|
|
getPrefix() {
|
2024-05-30 04:43:17 +08:00
|
|
|
return `${Auth.userID}${TOKEN}${this.clientSessionUUID}`;
|
2024-05-08 05:05:36 +08:00
|
|
|
}
|
2024-07-30 21:20:18 +08:00
|
|
|
|
|
|
|
updateActivePeers(streams: StreamItem[]) {
|
|
|
|
const activePeers: Record<string, RTCPeerConnection> = {};
|
|
|
|
|
|
|
|
streams.forEach((vs) => {
|
|
|
|
if (this.webRtcPeersRef[vs.stream]) {
|
|
|
|
activePeers[vs.stream] = this.webRtcPeersRef[vs.stream].peerConnection;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.activePeers = activePeers;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getStats() {
|
|
|
|
const stats: Record<string, unknown> = {};
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
Object.keys(this.activePeers).map(async (peerId) => {
|
|
|
|
const peerStats = await this.activePeers[peerId].getStats();
|
|
|
|
|
|
|
|
const videoStats: Record<string, unknown> = {};
|
|
|
|
|
|
|
|
peerStats.forEach((stat) => {
|
|
|
|
if (FILTER_VIDEO_STATS.includes(stat.type)) {
|
|
|
|
videoStats[stat.type] = stat;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
stats[peerId] = videoStats;
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
return stats;
|
|
|
|
}
|
2024-04-20 04:34:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const videoService = new VideoService();
|
|
|
|
|
|
|
|
export default {
|
2024-05-02 03:48:12 +08:00
|
|
|
addCandidateToPeer: VideoService.addCandidateToPeer,
|
2024-05-08 05:05:36 +08:00
|
|
|
getMyStreamId: videoService.getMyStreamId.bind(videoService),
|
2024-05-02 03:48:12 +08:00
|
|
|
getAuthenticatedURL: VideoService.getAuthenticatedURL,
|
|
|
|
getRole: VideoService.getRole,
|
|
|
|
getMediaServerAdapter: VideoService.getMediaServerAdapter,
|
|
|
|
getCameraProfile: VideoService.getCameraProfile,
|
|
|
|
getThreshold: VideoService.getThreshold,
|
|
|
|
getPreviousVideoPage: VideoService.getPreviousVideoPage,
|
|
|
|
getNextVideoPage: VideoService.getNextVideoPage,
|
|
|
|
getCurrentVideoPageIndex: VideoService.getCurrentVideoPageIndex,
|
2024-05-08 05:05:36 +08:00
|
|
|
isLocalStream: videoService.isLocalStream.bind(videoService),
|
2024-05-02 03:48:12 +08:00
|
|
|
isPaginationEnabled: VideoService.isPaginationEnabled,
|
|
|
|
mirrorOwnWebcam: VideoService.mirrorOwnWebcam,
|
|
|
|
processInboundIceQueue: VideoService.processInboundIceQueue,
|
2024-05-08 05:05:36 +08:00
|
|
|
storeDeviceIds: videoService.storeDeviceIds.bind(videoService),
|
2024-05-07 04:05:37 +08:00
|
|
|
joinedVideo: () => VideoService.joinedVideo(),
|
2024-05-02 03:48:12 +08:00
|
|
|
exitedVideo: () => videoService.exitedVideo(),
|
|
|
|
getPreloadedStream: () => videoService.getPreloadedStream(),
|
2024-06-14 22:35:53 +08:00
|
|
|
getRecord: (myRole?: string) => videoService.getRecord(myRole),
|
2024-05-29 21:26:11 +08:00
|
|
|
getPageChangeDebounceTime: () => VideoService.getPageChangeDebounceTime(),
|
2024-04-20 04:34:43 +08:00
|
|
|
getUserParameterProfile: () => videoService.getUserParameterProfile(),
|
|
|
|
isMultipleCamerasEnabled: () => videoService.isMultipleCamerasEnabled(),
|
2024-06-14 21:30:48 +08:00
|
|
|
joinVideo: (deviceId: string, isUserLocked: boolean) => videoService.joinVideo(deviceId, isUserLocked),
|
2024-05-02 03:48:12 +08:00
|
|
|
updateNumberOfDevices: (devices: MediaDeviceInfo[]) => videoService.updateNumberOfDevices(devices),
|
|
|
|
stopConnectingStream: videoService.stopConnectingStream,
|
|
|
|
updatePeerDictionaryReference: (
|
|
|
|
newRef: Record<string, WebRtcPeer>,
|
|
|
|
) => videoService.updatePeerDictionaryReference(newRef),
|
2024-07-30 20:35:47 +08:00
|
|
|
getWebRtcPeersRef: () => videoService.webRtcPeersRef,
|
2024-05-02 03:48:12 +08:00
|
|
|
isMobile: videoService.isMobile,
|
|
|
|
notify: (message: string) => notify(message, 'error', 'video'),
|
2024-05-29 21:26:11 +08:00
|
|
|
applyCameraProfile: VideoService.applyCameraProfile,
|
2024-05-02 22:51:14 +08:00
|
|
|
setTrackEnabled: (value: boolean) => videoService.setTrackEnabled(value),
|
2024-05-29 21:26:11 +08:00
|
|
|
getRoleModerator: VideoService.getRoleModerator,
|
|
|
|
getRoleViewer: VideoService.getRoleViewer,
|
2024-05-08 05:05:36 +08:00
|
|
|
getPrefix: videoService.getPrefix.bind(videoService),
|
2024-06-14 21:30:48 +08:00
|
|
|
isPinEnabled: VideoService.isPinEnabled,
|
2024-07-30 21:20:18 +08:00
|
|
|
updateActivePeers: (streams: StreamItem[]) => videoService.updateActivePeers(streams),
|
|
|
|
getStats: () => videoService.getStats(),
|
2024-04-20 04:34:43 +08:00
|
|
|
};
|