mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: Refactored Platform instances
Platform instances are now initialized in the classes constructorspull/570/head
parent
8f7a3f4292
commit
3d6249418c
|
@ -33,7 +33,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
|||
/**
|
||||
* @hidden
|
||||
*/
|
||||
const platform: PlatformUtils = PlatformUtils.getInstance();
|
||||
let platform: PlatformUtils;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -59,6 +59,7 @@ export class LocalRecorder {
|
|||
* @hidden
|
||||
*/
|
||||
constructor(private stream: Stream) {
|
||||
platform = PlatformUtils.getInstance();
|
||||
this.connectionId = (!!this.stream.connection) ? this.stream.connection.connectionId : 'default-connection';
|
||||
this.id = this.stream.streamId + '_' + this.connectionId + '_localrecord';
|
||||
this.state = LocalRecorderState.READY;
|
||||
|
|
|
@ -57,7 +57,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
|||
/**
|
||||
* @hidden
|
||||
*/
|
||||
const platform: PlatformUtils = PlatformUtils.getInstance();
|
||||
let platform: PlatformUtils;
|
||||
|
||||
/**
|
||||
* Entrypoint of OpenVidu Browser library.
|
||||
|
@ -117,6 +117,7 @@ export class OpenVidu {
|
|||
ee = new EventEmitter()
|
||||
|
||||
constructor() {
|
||||
platform = PlatformUtils.getInstance();
|
||||
this.libraryVersion = packageJson.version;
|
||||
logger.info("'OpenVidu' initialized");
|
||||
logger.info("openvidu-browser version: " + this.libraryVersion);
|
||||
|
|
|
@ -38,7 +38,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
|||
/**
|
||||
* @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
|
||||
|
@ -96,6 +96,7 @@ export class Publisher extends StreamManager {
|
|||
*/
|
||||
constructor(targEl: string | HTMLElement, properties: PublisherProperties, openvidu: OpenVidu) {
|
||||
super(new Stream((!!openvidu.session) ? openvidu.session : new Session(openvidu), { publisherProperties: properties, mediaConstraints: {} }), targEl);
|
||||
platform = PlatformUtils.getInstance();
|
||||
this.properties = properties;
|
||||
this.openvidu = openvidu;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
|||
/**
|
||||
* @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.
|
||||
|
@ -149,6 +149,7 @@ export class Session extends EventDispatcher {
|
|||
*/
|
||||
constructor(openvidu: OpenVidu) {
|
||||
super();
|
||||
platform = PlatformUtils.getInstance();
|
||||
this.openvidu = openvidu;
|
||||
}
|
||||
|
||||
|
@ -1202,7 +1203,7 @@ export class Session extends EventDispatcher {
|
|||
} else {
|
||||
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
|
||||
this.openvidu.sendRequest('videoData', {
|
||||
height: streamManager.stream.videoDimensions.height,
|
||||
|
|
|
@ -45,7 +45,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
|||
/**
|
||||
* @hidden
|
||||
*/
|
||||
const platform: PlatformUtils = PlatformUtils.getInstance();
|
||||
let platform: PlatformUtils;
|
||||
|
||||
/**
|
||||
* 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 | {}) {
|
||||
|
||||
super();
|
||||
|
||||
platform = PlatformUtils.getInstance();
|
||||
this.session = session;
|
||||
|
||||
if (options.hasOwnProperty('id')) {
|
||||
|
|
|
@ -33,7 +33,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
|||
/**
|
||||
* @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.
|
||||
|
@ -106,7 +106,7 @@ export class StreamManager extends EventDispatcher {
|
|||
*/
|
||||
constructor(stream: Stream, targetElement?: HTMLElement | string) {
|
||||
super();
|
||||
|
||||
platform = PlatformUtils.getInstance();
|
||||
this.stream = stream;
|
||||
this.stream.streamManager = this;
|
||||
this.remote = !this.stream.isLocal();
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import platform = require("platform");
|
||||
|
||||
export class PlatformUtils {
|
||||
private static instance: PlatformUtils;
|
||||
private constructor() {}
|
||||
protected static instance: PlatformUtils;
|
||||
constructor() {}
|
||||
|
||||
static getInstance(): PlatformUtils {
|
||||
if (!PlatformUtils.instance) {
|
||||
PlatformUtils.instance = new PlatformUtils();
|
||||
if (!this.instance) {
|
||||
this.instance = new PlatformUtils();
|
||||
}
|
||||
return PlatformUtils.instance;
|
||||
}
|
||||
|
@ -141,6 +141,13 @@ export class PlatformUtils {
|
|||
return platform.os!!.family === "iOS" || platform.os!!.family === "Android";
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public isReactNative(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
|
|
|
@ -27,7 +27,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
|||
/**
|
||||
* @hidden
|
||||
*/
|
||||
const platform: PlatformUtils = PlatformUtils.getInstance();
|
||||
let platform: PlatformUtils;
|
||||
|
||||
|
||||
export interface WebRtcPeerConfiguration {
|
||||
|
@ -55,6 +55,7 @@ export class WebRtcPeer {
|
|||
private candidategatheringdone = false;
|
||||
|
||||
constructor(protected configuration: WebRtcPeerConfiguration) {
|
||||
platform = PlatformUtils.getInstance();
|
||||
this.configuration.iceServers = (!!this.configuration.iceServers && this.configuration.iceServers.length > 0) ? this.configuration.iceServers : freeice();
|
||||
|
||||
this.pc = new RTCPeerConnection({ iceServers: this.configuration.iceServers });
|
||||
|
|
|
@ -27,7 +27,7 @@ const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
|||
/**
|
||||
* @hidden
|
||||
*/
|
||||
const platform: PlatformUtils = PlatformUtils.getInstance();
|
||||
let platform: PlatformUtils;
|
||||
|
||||
export class WebRtcStats {
|
||||
|
||||
|
@ -63,7 +63,9 @@ export class WebRtcStats {
|
|||
}
|
||||
};
|
||||
|
||||
constructor(private stream: Stream) { }
|
||||
constructor(private stream: Stream) {
|
||||
platform = PlatformUtils.getInstance();
|
||||
}
|
||||
|
||||
public isEnabled(): boolean {
|
||||
return this.webRtcStatsEnabled;
|
||||
|
|
Loading…
Reference in New Issue