openvidu-browser: add Types for Events

pull/761/head
pabloFuente 2022-11-15 15:28:55 +01:00
parent a61fb64707
commit fc93566e04
11 changed files with 89 additions and 36 deletions

View File

@ -29,6 +29,7 @@ import { OpenViduError, OpenViduErrorName } from '../OpenViduInternal/Enums/Open
import { VideoInsertMode } from '../OpenViduInternal/Enums/VideoInsertMode';
import { OpenViduLogger } from '../OpenViduInternal/Logger/OpenViduLogger';
import { PlatformUtils } from '../OpenViduInternal/Utils/Platform';
import { StreamPropertyChangedEventReason, ChangedPropertyType } from '../OpenViduInternal/Events/Types/Types';
import * as screenSharingAuto from '../OpenViduInternal/ScreenSharing/Screen-Capturing-Auto';
import * as screenSharing from '../OpenViduInternal/ScreenSharing/Screen-Capturing';
@ -219,8 +220,8 @@ export class OpenVidu {
typeof MediaStreamTrack !== 'undefined' && properties.videoSource instanceof MediaStreamTrack
? undefined
: typeof properties.frameRate !== 'undefined'
? properties.frameRate
: undefined,
? properties.frameRate
: undefined,
insertMode:
typeof properties.insertMode !== 'undefined'
? typeof properties.insertMode === 'string'
@ -234,8 +235,8 @@ export class OpenVidu {
typeof MediaStreamTrack !== 'undefined' && properties.videoSource instanceof MediaStreamTrack
? undefined
: typeof properties.resolution !== 'undefined'
? properties.resolution
: '640x480',
? properties.resolution
: '640x480',
videoSource: typeof properties.videoSource !== 'undefined' ? properties.videoSource : undefined,
videoSimulcast: properties.videoSimulcast,
filter: properties.filter
@ -642,7 +643,7 @@ export class OpenVidu {
/**
* @hidden
*/
sendNewVideoDimensionsIfRequired(publisher: Publisher, reason: string, WAIT_INTERVAL: number, MAX_ATTEMPTS: number) {
sendNewVideoDimensionsIfRequired(publisher: Publisher, reason: StreamPropertyChangedEventReason, WAIT_INTERVAL: number, MAX_ATTEMPTS: number) {
let attempts = 0;
const oldWidth = publisher?.stream?.videoDimensions?.width || 0;
const oldHeight = publisher?.stream?.videoDimensions?.height || 0;
@ -666,7 +667,7 @@ export class OpenVidu {
*/
sendVideoDimensionsChangedEvent(
publisher: Publisher,
reason: string,
reason: StreamPropertyChangedEventReason,
oldWidth: number,
oldHeight: number,
newWidth: number,
@ -717,7 +718,7 @@ export class OpenVidu {
/**
* @hidden
*/
sendTrackChangedEvent(publisher: Publisher, oldLabel: string, newLabel: string, propertyType: string) {
sendTrackChangedEvent(publisher: Publisher, oldLabel: string, newLabel: string, propertyType: ChangedPropertyType) {
const oldValue = { label: oldLabel };
const newValue = { label: newLabel };
const reason = 'trackReplaced';
@ -1028,9 +1029,9 @@ export class OpenVidu {
const error = new OpenViduError(
OpenViduErrorName.SCREEN_SHARING_NOT_SUPPORTED,
'You can only screen share in desktop Chrome, Firefox, Opera, Safari (>=13.0), Edge (>= 80) or Electron. Detected client: ' +
platform.getName() +
' ' +
platform.getVersion()
platform.getName() +
' ' +
platform.getVersion()
);
logger.error(error);
return reject(error);

View File

@ -28,6 +28,7 @@ import { VideoInsertMode } from '../OpenViduInternal/Enums/VideoInsertMode';
import { OpenViduLogger } from '../OpenViduInternal/Logger/OpenViduLogger';
import { PlatformUtils } from '../OpenViduInternal/Utils/Platform';
import { TypeOfVideo } from '../OpenViduInternal/Enums/TypeOfVideo';
import { StreamEventReason } from '../OpenViduInternal/Events/Types/Types';
/**
* @hidden
@ -92,7 +93,7 @@ export class Publisher extends StreamManager {
this.properties = properties;
this.openvidu = openvidu;
this.stream.ee.on('local-stream-destroyed', (reason: string) => {
this.stream.ee.on('local-stream-destroyed', (reason: StreamEventReason) => {
this.stream.isLocalStreamPublished = false;
const streamEvent = new StreamEvent(true, this, 'streamDestroyed', this.stream, reason);
this.emitEvent('streamDestroyed', [streamEvent]);

View File

@ -44,6 +44,7 @@ import { OpenViduError, OpenViduErrorName } from '../OpenViduInternal/Enums/Open
import { VideoInsertMode } from '../OpenViduInternal/Enums/VideoInsertMode';
import { OpenViduLogger } from '../OpenViduInternal/Logger/OpenViduLogger';
import { PlatformUtils } from '../OpenViduInternal/Utils/Platform';
import { StreamPropertyChangedEventReason, ChangedPropertyType, RecordingEventReason, ConnectionEventReason, StreamEventReason } from '../OpenViduInternal/Events/Types/Types';
/**
* @hidden
*/
@ -833,7 +834,7 @@ export class Session extends EventDispatcher {
/**
* @hidden
*/
onParticipantLeft(event: { connectionId: string; reason: string }): void {
onParticipantLeft(event: { connectionId: string; reason: ConnectionEventReason }): void {
this.getRemoteConnection(event.connectionId, 'onParticipantLeft')
.then((connection) => {
if (!!connection.stream) {
@ -897,7 +898,7 @@ export class Session extends EventDispatcher {
/**
* @hidden
*/
onParticipantUnpublished(event: { connectionId: string; reason: string }): void {
onParticipantUnpublished(event: { connectionId: string; reason: StreamEventReason }): void {
if (event.connectionId === this.connection.connectionId) {
// Your stream has been forcedly unpublished from the session
this.stopPublisherStream(event.reason);
@ -925,7 +926,7 @@ export class Session extends EventDispatcher {
/**
* @hidden
*/
onParticipantEvicted(event: { connectionId: string; reason: string }): void {
onParticipantEvicted(event: { connectionId: string; reason: ConnectionEventReason }): void {
if (event.connectionId === this.connection.connectionId) {
// You have been evicted from the session
if (!!this.sessionId && !this.connection.disposed) {
@ -975,7 +976,7 @@ export class Session extends EventDispatcher {
/**
* @hidden
*/
onStreamPropertyChanged(event: { connectionId: string; streamId: string; property: string; newValue: any; reason: string }): void {
onStreamPropertyChanged(event: { connectionId: string; streamId: string; property: ChangedPropertyType; newValue: any; reason: StreamPropertyChangedEventReason }): void {
const callback = (connection: Connection) => {
if (!!connection.stream && connection.stream.streamId === event.streamId) {
const stream = connection.stream;
@ -1159,7 +1160,7 @@ export class Session extends EventDispatcher {
/**
* @hidden
*/
onLostConnection(reason: string): void {
onLostConnection(reason: ConnectionEventReason): void {
logger.warn('Lost connection in Session ' + this.sessionId);
if (!!this.sessionId && !!this.connection && !this.connection.disposed) {
this.leave(true, reason);
@ -1202,7 +1203,7 @@ export class Session extends EventDispatcher {
/**
* @hidden
*/
onRecordingStopped(event: { id: string; name: string; reason: string }): void {
onRecordingStopped(event: { id: string; name: string; reason: RecordingEventReason }): void {
this.ee.emitEvent('recordingStopped', [new RecordingEvent(this, 'recordingStopped', event.id, event.name, event.reason)]);
}
@ -1354,7 +1355,7 @@ export class Session extends EventDispatcher {
/**
* @hidden
*/
leave(forced: boolean, reason: string): void {
leave(forced: boolean, reason: ConnectionEventReason): void {
forced = !!forced;
logger.info('Leaving Session (forced=' + forced + ')');
this.stopVideoDataIntervals();
@ -1636,7 +1637,7 @@ export class Session extends EventDispatcher {
});
}
private stopPublisherStream(reason: string) {
private stopPublisherStream(reason: StreamEventReason) {
if (!!this.connection.stream) {
// Dispose Publisher's local stream
this.connection.stream.disposeWebRtcPeer();

View File

@ -18,6 +18,7 @@
import { Event } from './Event';
import { Connection } from '../../OpenVidu/Connection';
import { Session } from '../../OpenVidu/Session';
import { ConnectionEventReason } from './Types/Types';
/**
* Triggered by:
@ -41,12 +42,12 @@ export class ConnectionEvent extends Event {
*
* For `connectionCreated` event an empty string
*/
reason: string;
reason: ConnectionEventReason;
/**
* @hidden
*/
constructor(cancelable: boolean, target: Session, type: string, connection: Connection, reason: string) {
constructor(cancelable: boolean, target: Session, type: string, connection: Connection, reason: ConnectionEventReason) {
super(cancelable, target, type);
this.connection = connection;
this.reason = reason;
@ -56,5 +57,5 @@ export class ConnectionEvent extends Event {
* @hidden
*/
// tslint:disable-next-line:no-empty
callDefaultBehavior() {}
callDefaultBehavior() { }
}

View File

@ -17,6 +17,7 @@
import { Event } from './Event';
import { Session } from '../../OpenVidu/Session';
import { RecordingEventReason } from './Types/Types';
/**
* Triggered by:
@ -48,12 +49,12 @@ export class RecordingEvent extends Event {
*
* For 'recordingStarted' empty string
*/
reason?: string;
reason?: RecordingEventReason;
/**
* @hidden
*/
constructor(target: Session, type: string, id: string, name: string, reason?: string) {
constructor(target: Session, type: string, id: string, name: string, reason?: RecordingEventReason) {
super(false, target, type);
this.id = id;
if (name !== id) {
@ -66,5 +67,5 @@ export class RecordingEvent extends Event {
* @hidden
*/
// tslint:disable-next-line:no-empty
callDefaultBehavior() {}
callDefaultBehavior() { }
}

View File

@ -18,6 +18,7 @@
import { Event } from './Event';
import { Session } from '../../OpenVidu/Session';
import { OpenViduLogger } from '../Logger/OpenViduLogger';
import { ConnectionEventReason } from './Types/Types';
/**
* @hidden
@ -40,12 +41,12 @@ export class SessionDisconnectedEvent extends Event {
* - "nodeCrashed": a node has crashed in the server side. You can use this reason to ask your application's backend to reconnect
* to a new session to replace the crashed one
*/
reason: string;
reason: ConnectionEventReason;
/**
* @hidden
*/
constructor(target: Session, reason: string) {
constructor(target: Session, reason: ConnectionEventReason) {
super(true, target, 'sessionDisconnected');
this.reason = reason;
}

View File

@ -18,6 +18,7 @@
import { Event } from './Event';
import { Connection } from '../../OpenVidu/Connection';
import { Session } from '../../OpenVidu/Session';
import { SpeechToTextEventReason } from './Types/Types';
/**
* Triggered by [[SessionEventMap.speechToTextMessage]]
@ -38,7 +39,7 @@ export class SpeechToTextEvent extends Event {
/**
* All speech-to-text events are generated
*/
reason: 'recognizing' | 'recognized';
reason: SpeechToTextEventReason;
/**
* The original event from the speech to text engine. This can vary depending on the engine
@ -54,7 +55,7 @@ export class SpeechToTextEvent extends Event {
/**
* @hidden
*/
constructor(target: Session, connection: Connection, text: string, reason: 'recognizing' | 'recognized', raw: string, lang: string) {
constructor(target: Session, connection: Connection, text: string, reason: SpeechToTextEventReason, raw: string, lang: string) {
super(false, target, 'speechToTextMessage');
this.connection = connection;
this.text = text;

View File

@ -20,6 +20,7 @@ import { Publisher } from '../../OpenVidu/Publisher';
import { Session } from '../../OpenVidu/Session';
import { Stream } from '../../OpenVidu/Stream';
import { OpenViduLogger } from '../Logger/OpenViduLogger';
import { StreamEventReason } from './Types/Types';
/**
* @hidden
@ -51,12 +52,12 @@ export class StreamEvent extends Event {
*
* For 'streamCreated' empty string
*/
reason: string;
reason: StreamEventReason;
/**
* @hidden
*/
constructor(cancelable: boolean, target: Session | Publisher, type: string, stream: Stream, reason: string) {
constructor(cancelable: boolean, target: Session | Publisher, type: string, stream: Stream, reason: StreamEventReason) {
super(cancelable, target, type);
this.stream = stream;
this.reason = reason;

View File

@ -19,6 +19,7 @@ import { Event } from './Event';
import { Session } from '../../OpenVidu/Session';
import { Stream } from '../../OpenVidu/Stream';
import { StreamManager } from '../../OpenVidu/StreamManager';
import { StreamPropertyChangedEventReason, ChangedPropertyType } from './Types/Types';
/**
* Triggered by `streamPropertyChanged` (available for [Session](/en/stable/api/openvidu-browser/interfaces/SessionEventMap.html#streamPropertyChanged) and [StreamManager](/en/stable/api/openvidu-browser/interfaces/StreamManagerEventMap.html#streamPropertyChanged) objects)
@ -32,7 +33,7 @@ export class StreamPropertyChangedEvent extends Event {
/**
* The property of the stream that changed. This value is either `"videoActive"`, `"audioActive"`, `"videoTrack"`, `"audioTrack"`, `"videoDimensions"` or `"filter"`
*/
changedProperty: string;
changedProperty: ChangedPropertyType;
/**
* Cause of the change on the stream's property:
@ -43,7 +44,7 @@ export class StreamPropertyChangedEvent extends Event {
* - For `videoDimensions`: `"deviceRotated"`, `"screenResized"` or `"trackReplaced"`
* - For `filter`: `"applyFilter"`, `"execFilterMethod"` or `"removeFilter"`
*/
reason: string;
reason: StreamPropertyChangedEventReason;
/**
* New value of the property (after change, current value)
@ -61,10 +62,10 @@ export class StreamPropertyChangedEvent extends Event {
constructor(
target: Session | StreamManager,
stream: Stream,
changedProperty: string,
changedProperty: ChangedPropertyType,
newValue: Object,
oldValue: Object,
reason: string
reason: StreamPropertyChangedEventReason
) {
super(false, target, 'streamPropertyChanged');
this.stream = stream;
@ -78,5 +79,5 @@ export class StreamPropertyChangedEvent extends Event {
* @hidden
*/
// tslint:disable-next-line:no-empty
callDefaultBehavior() {}
callDefaultBehavior() { }
}

View File

@ -0,0 +1,42 @@
export type ChangedPropertyType =
'videoActive' |
'audioActive' |
'videoTrack' |
'audioTrack' |
'videoDimensions' |
'filter';
export type StreamPropertyChangedEventReason =
'publishVideo' |
'publishAudio' |
'trackReplaced' |
'deviceRotated' |
'screenResized' |
'applyFilter' |
'execFilterMethod' |
'removeFilter';
export type ConnectionEventReason =
'disconnect' |
'forceDisconnectByUser' |
'forceDisconnectByServer' |
'sessionClosedByServer' |
'networkDisconnect' |
'nodeCrashed' |
'';
export type StreamEventReason =
ConnectionEventReason |
'unpublish' |
'forceUnpublishByUser' |
'forceUnpublishByServer';
export type RecordingEventReason =
'recordingStoppedByServer' |
'sessionClosedByServer' |
'automaticStop' |
'nodeCrashed';
export type SpeechToTextEventReason =
'recognizing' |
'recognized';

View File

@ -45,5 +45,7 @@ export { SessionEventMap } from './OpenViduInternal/Events/EventMap/SessionEvent
export { StreamManagerEventMap } from './OpenViduInternal/Events/EventMap/StreamManagerEventMap';
export { PublisherEventMap } from './OpenViduInternal/Events/EventMap/PublisherEventMap';
export * from './OpenViduInternal/Events/Types/Types';
// Disable jsnlog when library is loaded
JL.setOptions({ enabled: false });