openvidu-browser: Refactored Platform instances

Platform instances are now initialized in the classes constructors
pull/570/head
csantosm 2020-11-26 13:17:55 +01:00
parent 8f7a3f4292
commit 3d6249418c
9 changed files with 30 additions and 16 deletions

View File

@ -33,7 +33,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
/** /**
* @hidden * @hidden
*/ */
const platform: PlatformUtils = PlatformUtils.getInstance(); let platform: PlatformUtils;
/** /**
@ -59,6 +59,7 @@ export class LocalRecorder {
* @hidden * @hidden
*/ */
constructor(private stream: Stream) { constructor(private stream: Stream) {
platform = PlatformUtils.getInstance();
this.connectionId = (!!this.stream.connection) ? this.stream.connection.connectionId : 'default-connection'; this.connectionId = (!!this.stream.connection) ? this.stream.connection.connectionId : 'default-connection';
this.id = this.stream.streamId + '_' + this.connectionId + '_localrecord'; this.id = this.stream.streamId + '_' + this.connectionId + '_localrecord';
this.state = LocalRecorderState.READY; this.state = LocalRecorderState.READY;

View File

@ -57,7 +57,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
/** /**
* @hidden * @hidden
*/ */
const platform: PlatformUtils = PlatformUtils.getInstance(); let platform: PlatformUtils;
/** /**
* Entrypoint of OpenVidu Browser library. * Entrypoint of OpenVidu Browser library.
@ -117,6 +117,7 @@ export class OpenVidu {
ee = new EventEmitter() ee = new EventEmitter()
constructor() { constructor() {
platform = PlatformUtils.getInstance();
this.libraryVersion = packageJson.version; this.libraryVersion = packageJson.version;
logger.info("'OpenVidu' initialized"); logger.info("'OpenVidu' initialized");
logger.info("openvidu-browser version: " + this.libraryVersion); logger.info("openvidu-browser version: " + this.libraryVersion);

View File

@ -38,7 +38,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
/** /**
* @hidden * @hidden
*/ */
const platform: PlatformUtils = PlatformUtils.getInstance(); let platform: PlatformUtils;
/** /**
* Packs local media streams. Participants can publish it to a session. Initialized with [[OpenVidu.initPublisher]] method * Packs local media streams. Participants can publish it to a session. Initialized with [[OpenVidu.initPublisher]] method
@ -96,6 +96,7 @@ export class Publisher extends StreamManager {
*/ */
constructor(targEl: string | HTMLElement, properties: PublisherProperties, openvidu: OpenVidu) { constructor(targEl: string | HTMLElement, properties: PublisherProperties, openvidu: OpenVidu) {
super(new Stream((!!openvidu.session) ? openvidu.session : new Session(openvidu), { publisherProperties: properties, mediaConstraints: {} }), targEl); super(new Stream((!!openvidu.session) ? openvidu.session : new Session(openvidu), { publisherProperties: properties, mediaConstraints: {} }), targEl);
platform = PlatformUtils.getInstance();
this.properties = properties; this.properties = properties;
this.openvidu = openvidu; this.openvidu = openvidu;

View File

@ -53,7 +53,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
/** /**
* @hidden * @hidden
*/ */
const platform: PlatformUtils = PlatformUtils.getInstance(); let platform: PlatformUtils;
/** /**
* Represents a video call. It can also be seen as a videoconference room where multiple users can connect. * Represents a video call. It can also be seen as a videoconference room where multiple users can connect.
@ -149,6 +149,7 @@ export class Session extends EventDispatcher {
*/ */
constructor(openvidu: OpenVidu) { constructor(openvidu: OpenVidu) {
super(); super();
platform = PlatformUtils.getInstance();
this.openvidu = openvidu; this.openvidu = openvidu;
} }
@ -1202,7 +1203,7 @@ export class Session extends EventDispatcher {
} else { } else {
setTimeout(obtainAndSendVideo, intervalSeconds * 1000); setTimeout(obtainAndSendVideo, intervalSeconds * 1000);
} }
} else if (platform.isFirefoxBrowser() || platform.isFirefoxMobileBrowser() || platform.isIonicIos()) { } else if (platform.isFirefoxBrowser() || platform.isFirefoxMobileBrowser() || platform.isIonicIos() || platform.isReactNative()) {
// Basic version for Firefox and Ionic iOS. They do not support stats // Basic version for Firefox and Ionic iOS. They do not support stats
this.openvidu.sendRequest('videoData', { this.openvidu.sendRequest('videoData', {
height: streamManager.stream.videoDimensions.height, height: streamManager.stream.videoDimensions.height,

View File

@ -45,7 +45,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
/** /**
* @hidden * @hidden
*/ */
const platform: PlatformUtils = PlatformUtils.getInstance(); let platform: PlatformUtils;
/** /**
* Represents each one of the media streams available in OpenVidu Server for certain session. * Represents each one of the media streams available in OpenVidu Server for certain session.
@ -215,7 +215,7 @@ export class Stream extends EventDispatcher {
constructor(session: Session, options: InboundStreamOptions | OutboundStreamOptions | {}) { constructor(session: Session, options: InboundStreamOptions | OutboundStreamOptions | {}) {
super(); super();
platform = PlatformUtils.getInstance();
this.session = session; this.session = session;
if (options.hasOwnProperty('id')) { if (options.hasOwnProperty('id')) {

View File

@ -33,7 +33,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
/** /**
* @hidden * @hidden
*/ */
const platform: PlatformUtils = PlatformUtils.getInstance(); let platform: PlatformUtils;
/** /**
* Interface in charge of displaying the media streams in the HTML DOM. This wraps any [[Publisher]] and [[Subscriber]] object. * Interface in charge of displaying the media streams in the HTML DOM. This wraps any [[Publisher]] and [[Subscriber]] object.
@ -106,7 +106,7 @@ export class StreamManager extends EventDispatcher {
*/ */
constructor(stream: Stream, targetElement?: HTMLElement | string) { constructor(stream: Stream, targetElement?: HTMLElement | string) {
super(); super();
platform = PlatformUtils.getInstance();
this.stream = stream; this.stream = stream;
this.stream.streamManager = this; this.stream.streamManager = this;
this.remote = !this.stream.isLocal(); this.remote = !this.stream.isLocal();

View File

@ -1,12 +1,12 @@
import platform = require("platform"); import platform = require("platform");
export class PlatformUtils { export class PlatformUtils {
private static instance: PlatformUtils; protected static instance: PlatformUtils;
private constructor() {} constructor() {}
static getInstance(): PlatformUtils { static getInstance(): PlatformUtils {
if (!PlatformUtils.instance) { if (!this.instance) {
PlatformUtils.instance = new PlatformUtils(); this.instance = new PlatformUtils();
} }
return PlatformUtils.instance; return PlatformUtils.instance;
} }
@ -141,6 +141,13 @@ export class PlatformUtils {
return platform.os!!.family === "iOS" || platform.os!!.family === "Android"; return platform.os!!.family === "iOS" || platform.os!!.family === "Android";
} }
/**
* @hidden
*/
public isReactNative(): boolean {
return false;
}
/** /**
* @hidden * @hidden
*/ */

View File

@ -27,7 +27,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
/** /**
* @hidden * @hidden
*/ */
const platform: PlatformUtils = PlatformUtils.getInstance(); let platform: PlatformUtils;
export interface WebRtcPeerConfiguration { export interface WebRtcPeerConfiguration {
@ -55,6 +55,7 @@ export class WebRtcPeer {
private candidategatheringdone = false; private candidategatheringdone = false;
constructor(protected configuration: WebRtcPeerConfiguration) { constructor(protected configuration: WebRtcPeerConfiguration) {
platform = PlatformUtils.getInstance();
this.configuration.iceServers = (!!this.configuration.iceServers && this.configuration.iceServers.length > 0) ? this.configuration.iceServers : freeice(); this.configuration.iceServers = (!!this.configuration.iceServers && this.configuration.iceServers.length > 0) ? this.configuration.iceServers : freeice();
this.pc = new RTCPeerConnection({ iceServers: this.configuration.iceServers }); this.pc = new RTCPeerConnection({ iceServers: this.configuration.iceServers });

View File

@ -27,7 +27,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
/** /**
* @hidden * @hidden
*/ */
const platform: PlatformUtils = PlatformUtils.getInstance(); let platform: PlatformUtils;
export class WebRtcStats { export class WebRtcStats {
@ -63,7 +63,9 @@ export class WebRtcStats {
} }
}; };
constructor(private stream: Stream) { } constructor(private stream: Stream) {
platform = PlatformUtils.getInstance();
}
public isEnabled(): boolean { public isEnabled(): boolean {
return this.webRtcStatsEnabled; return this.webRtcStatsEnabled;