mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: Node.js platform: Use `globalThis` instead of `window`
While `window` is specific to the web browser, and `global` is specific to Node.js, the standard `globalThis` global variable is common to both platforms. Thus, to make openvidu-browser more portable to Node.js, it's better to use the common name. More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThispull/672/merge
parent
71b0e6ca43
commit
2b70c12be6
|
@ -1,8 +1,8 @@
|
|||
import { OpenVidu } from './OpenVidu/OpenVidu';
|
||||
import { JL } from 'jsnlog';
|
||||
|
||||
if (window) {
|
||||
window['OpenVidu'] = OpenVidu;
|
||||
if (typeof globalThis !== 'undefined') {
|
||||
globalThis['OpenVidu'] = OpenVidu;
|
||||
}
|
||||
|
||||
// Disable jsnlog when library is loaded
|
||||
|
|
|
@ -263,11 +263,11 @@ export class LocalRecorder {
|
|||
a.style.display = 'none';
|
||||
document.body.appendChild(a);
|
||||
|
||||
const url = window.URL.createObjectURL(<any>this.blob);
|
||||
const url = globalThis.URL.createObjectURL(<any>this.blob);
|
||||
a.href = url;
|
||||
a.download = this.id + '.' + Mime.getExtension(this.blob!.type);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
globalThis.URL.revokeObjectURL(url);
|
||||
|
||||
document.body.removeChild(a);
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ export class LocalRecorder {
|
|||
this.blob = new Blob(this.chunks, { type: this.mediaRecorder.mimeType });
|
||||
this.chunks = [];
|
||||
|
||||
this.videoPreviewSrc = window.URL.createObjectURL(this.blob);
|
||||
this.videoPreviewSrc = globalThis.URL.createObjectURL(this.blob);
|
||||
|
||||
this.state = LocalRecorderState.FINISHED;
|
||||
}
|
||||
|
|
|
@ -624,7 +624,7 @@ export class OpenVidu {
|
|||
* @hidden
|
||||
*/
|
||||
onOrientationChanged(handler): void {
|
||||
(<any>window).addEventListener('orientationchange', handler);
|
||||
(globalThis as any).addEventListener('orientationchange', handler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,7 @@ export class OpenViduLogger {
|
|||
private MAX_MSECONDS_BATCH_MESSAGES: number = 5000;
|
||||
private MAX_LENGTH_STRING_JSON: number = 1000;
|
||||
|
||||
private defaultConsoleLogger: ConsoleLogger = new ConsoleLogger(window.console);
|
||||
private defaultConsoleLogger: ConsoleLogger = new ConsoleLogger(globalThis.console);
|
||||
|
||||
private currentAppender: any;
|
||||
|
||||
|
@ -29,7 +29,7 @@ export class OpenViduLogger {
|
|||
static configureJSNLog(openVidu: OpenVidu, token: string) {
|
||||
try {
|
||||
// If dev mode or...
|
||||
if ((window['LOG_JSNLOG_RESULTS']) ||
|
||||
if ((globalThis['LOG_JSNLOG_RESULTS']) ||
|
||||
// If instance is created and it is OpenVidu Pro
|
||||
(this.instance && openVidu.isAtLeastPro
|
||||
// If logs are enabled
|
||||
|
@ -89,7 +89,7 @@ export class OpenViduLogger {
|
|||
const seen = new WeakSet();
|
||||
return (key, value) => {
|
||||
if (typeof value === "object" && value != null) {
|
||||
if (seen.has(value) || (HTMLElement && value instanceof HTMLElement)) {
|
||||
if (seen.has(value) || (globalThis.HTMLElement && value instanceof HTMLElement)) {
|
||||
return;
|
||||
}
|
||||
seen.add(value);
|
||||
|
@ -104,7 +104,7 @@ export class OpenViduLogger {
|
|||
stringifyJson = `${stringifyJson.substring(0, this.instance.MAX_LENGTH_STRING_JSON)}...`;
|
||||
}
|
||||
|
||||
if (window['LOG_JSNLOG_RESULTS']) {
|
||||
if (globalThis['LOG_JSNLOG_RESULTS']) {
|
||||
console.log(stringifyJson);
|
||||
}
|
||||
|
||||
|
@ -193,12 +193,12 @@ export class OpenViduLogger {
|
|||
}
|
||||
|
||||
private replaceWindowConsole() {
|
||||
window.console = this.defaultConsoleLogger.logger;
|
||||
window.console.log = this.getConsoleWithJSNLog().log;
|
||||
window.console.info = this.getConsoleWithJSNLog().info;
|
||||
window.console.debug = this.getConsoleWithJSNLog().debug;
|
||||
window.console.warn = this.getConsoleWithJSNLog().warn;
|
||||
window.console.error = this.getConsoleWithJSNLog().error;
|
||||
globalThis.console = this.defaultConsoleLogger.logger;
|
||||
globalThis.console.log = this.getConsoleWithJSNLog().log;
|
||||
globalThis.console.info = this.getConsoleWithJSNLog().info;
|
||||
globalThis.console.debug = this.getConsoleWithJSNLog().debug;
|
||||
globalThis.console.warn = this.getConsoleWithJSNLog().warn;
|
||||
globalThis.console.error = this.getConsoleWithJSNLog().error;
|
||||
}
|
||||
|
||||
private disableLogger() {
|
||||
|
@ -206,12 +206,12 @@ export class OpenViduLogger {
|
|||
this.isJSNLogSetup = false;
|
||||
this.loggingSessionId = undefined;
|
||||
this.currentAppender = undefined;
|
||||
window.console = this.defaultConsoleLogger.logger;
|
||||
window.console.log = this.defaultConsoleLogger.log;
|
||||
window.console.info = this.defaultConsoleLogger.info;
|
||||
window.console.debug = this.defaultConsoleLogger.debug;
|
||||
window.console.warn = this.defaultConsoleLogger.warn;
|
||||
window.console.error = this.defaultConsoleLogger.error;
|
||||
globalThis.console = this.defaultConsoleLogger.logger;
|
||||
globalThis.console.log = this.defaultConsoleLogger.log;
|
||||
globalThis.console.info = this.defaultConsoleLogger.info;
|
||||
globalThis.console.debug = this.defaultConsoleLogger.debug;
|
||||
globalThis.console.warn = this.defaultConsoleLogger.warn;
|
||||
globalThis.console.error = this.defaultConsoleLogger.error;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ getScreenId(function (error, sourceId, screen_constraints) {
|
|||
}, 'pass second parameter only if you want system audio');
|
||||
*/
|
||||
|
||||
window.getScreenId = function (firefoxString, callback, custom_parameter) {
|
||||
globalThis.getScreenId = function (firefoxString, callback, custom_parameter) {
|
||||
if (navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob)) {
|
||||
// microsoft edge => navigator.getDisplayMedia(screen_constraints).then(onSuccess, onFailure);
|
||||
callback({
|
||||
|
@ -45,7 +45,7 @@ window.getScreenId = function (firefoxString, callback, custom_parameter) {
|
|||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('message', onIFrameCallback);
|
||||
globalThis.addEventListener('message', onIFrameCallback);
|
||||
|
||||
function onIFrameCallback(event) {
|
||||
if (!event.data) return;
|
||||
|
@ -58,14 +58,14 @@ window.getScreenId = function (firefoxString, callback, custom_parameter) {
|
|||
}
|
||||
|
||||
// this event listener is no more needed
|
||||
window.removeEventListener('message', onIFrameCallback);
|
||||
globalThis.removeEventListener('message', onIFrameCallback);
|
||||
}
|
||||
|
||||
if (event.data.chromeExtensionStatus) {
|
||||
callback(event.data.chromeExtensionStatus, null, getScreenConstraints(event.data.chromeExtensionStatus));
|
||||
|
||||
// this event listener is no more needed
|
||||
window.removeEventListener('message', onIFrameCallback);
|
||||
globalThis.removeEventListener('message', onIFrameCallback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,8 +85,8 @@ function getScreenConstraints(error, sourceId, canRequestAudioTrack) {
|
|||
video: {
|
||||
mandatory: {
|
||||
chromeMediaSource: error ? 'screen' : 'desktop',
|
||||
maxWidth: window.screen.width > 1920 ? window.screen.width : 1920,
|
||||
maxHeight: window.screen.height > 1080 ? window.screen.height : 1080
|
||||
maxWidth: globalThis.screen.width > 1920 ? globalThis.screen.width : 1920,
|
||||
maxHeight: globalThis.screen.height > 1080 ? globalThis.screen.height : 1080
|
||||
},
|
||||
optional: []
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ function postGetSourceIdMessage(custom_parameter) {
|
|||
var iframe;
|
||||
|
||||
// this function is used in RTCMultiConnection v3
|
||||
window.getScreenConstraints = function (callback) {
|
||||
globalThis.getScreenConstraints = function (callback) {
|
||||
loadIFrame(function () {
|
||||
getScreenId(function (error, sourceId, screen_constraints) {
|
||||
if (!screen_constraints) {
|
||||
|
@ -178,14 +178,14 @@ function loadIFrame(loadCallback) {
|
|||
(document.body || document.documentElement).appendChild(iframe);
|
||||
}
|
||||
|
||||
window.getChromeExtensionStatus = function (callback) {
|
||||
globalThis.getChromeExtensionStatus = function (callback) {
|
||||
// for Firefox:
|
||||
if (!!navigator.mozGetUserMedia) {
|
||||
callback('installed-enabled');
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('message', onIFrameCallback);
|
||||
globalThis.addEventListener('message', onIFrameCallback);
|
||||
|
||||
function onIFrameCallback(event) {
|
||||
if (!event.data) return;
|
||||
|
@ -194,7 +194,7 @@ window.getChromeExtensionStatus = function (callback) {
|
|||
callback(event.data.chromeExtensionStatus);
|
||||
|
||||
// this event listener is no more needed
|
||||
window.removeEventListener('message', onIFrameCallback);
|
||||
globalThis.removeEventListener('message', onIFrameCallback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,4 +217,4 @@ function postGetChromeExtensionStatusMessage() {
|
|||
}, '*');
|
||||
}
|
||||
|
||||
exports.getScreenId = window.getScreenId;
|
||||
exports.getScreenId = globalThis.getScreenId;
|
||||
|
|
Loading…
Reference in New Issue