From b44839f95b20d735861b6f7888372828520c5200 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Mon, 27 Aug 2018 17:06:14 +0200 Subject: [PATCH] openvidu-browser: Filter interface to class --- openvidu-browser/src/OpenVidu/Connection.ts | 2 +- .../Interfaces/Public => OpenVidu}/Filter.ts | 31 ++++++++++++------- openvidu-browser/src/OpenVidu/Session.ts | 8 +++-- openvidu-browser/src/OpenVidu/Stream.ts | 11 ++----- .../OpenViduInternal/Events/FilterEvent.ts | 2 +- .../Private/InboundStreamOptions.ts | 4 +-- .../Interfaces/Private/StreamOptionsServer.ts | 2 +- .../Interfaces/Public/PublisherProperties.ts | 2 +- openvidu-browser/src/index.ts | 2 +- 9 files changed, 35 insertions(+), 29 deletions(-) rename openvidu-browser/src/{OpenViduInternal/Interfaces/Public => OpenVidu}/Filter.ts (74%) diff --git a/openvidu-browser/src/OpenVidu/Connection.ts b/openvidu-browser/src/OpenVidu/Connection.ts index 121c9d36..1b4a4ee5 100644 --- a/openvidu-browser/src/OpenVidu/Connection.ts +++ b/openvidu-browser/src/OpenVidu/Connection.ts @@ -130,7 +130,7 @@ export class Connection { typeOfVideo: opts.typeOfVideo, frameRate: opts.frameRate, videoDimensions: !!opts.videoDimensions ? JSON.parse(opts.videoDimensions) : undefined, - filter: !!opts.filter ? opts.filter : {} + filter: !!opts.filter ? opts.filter : undefined }; const stream = new Stream(this.session, streamOptions); diff --git a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/Filter.ts b/openvidu-browser/src/OpenVidu/Filter.ts similarity index 74% rename from openvidu-browser/src/OpenViduInternal/Interfaces/Public/Filter.ts rename to openvidu-browser/src/OpenVidu/Filter.ts index 2572aa73..be82edd0 100644 --- a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/Filter.ts +++ b/openvidu-browser/src/OpenVidu/Filter.ts @@ -16,39 +16,48 @@ */ /** - * **WARNING**: experimental option. This interface may change in the near future. See [[Stream.filter]] + * **WARNING**: experimental option. This interface may change in the near future + * + * Video/audio filter applied to a Stream. See [[Stream.applyFilter]] */ -export interface Filter { +export class Filter { /** * Type of filter applied. This is the name of the remote class identifying the filter to apply in Kurento Media Server. * For example: `"FaceOverlayFilter"`, `"GStreamerFilter"`. * - * You can get this property in `*.kmd.json` files defining the Kurento filters: for GStreamerFilter that's + * You can get this property in `*.kmd.json` files defining the Kurento filters. For example, for GStreamerFilter that's * [here](https://github.com/Kurento/kms-filters/blob/53a452fac71d61795952e3d2202156c6b00f6d65/src/server/interface/filters.GStreamerFilter.kmd.json#L4) */ - type?: string; + type: string; /** - * Parameters used to initialized the filter. + * Parameters used to initialize the filter. * These correspond to the constructor parameters used in the filter in Kurento Media Server (except for `mediaPipeline` parameter, which is never needed). * * For example: for `filter.type = "GStreamerFilter"` could be `filter.options = {"command": "videobalance saturation=0.0"}` * - * You can get this property in `*.kmd.json` files defining the Kurento filters: for GStreamerFilter that's + * You can get this property in `*.kmd.json` files defining the Kurento filters. For example, for GStreamerFilter that's * [here](https://github.com/Kurento/kms-filters/blob/53a452fac71d61795952e3d2202156c6b00f6d65/src/server/interface/filters.GStreamerFilter.kmd.json#L13-L31) */ - options?: Object; + options: Object; /** - * Value passed the last time [[Session.execFilterMethod]] or [[Session.forceExecFilterMethod]] were called - * for the Stream owning this filter. If `undefined` those methods have not been called yet. + * Value passed the last time [[Filter.execMethod]] was called. If `undefined` this method has not been called yet. * * You can use this value to know the current status of any applied filter */ lastExecMethod?: { - method: string, - params: Object + method: string, params: Object }; + + /** + * @hidden + */ + constructor(type: string, options: Object) { + this.type = type; + this.options = options; + } + } \ No newline at end of file diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 37baebd8..5be6913d 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -16,6 +16,7 @@ */ import { Connection } from './Connection'; +import { Filter } from './Filter'; import { OpenVidu } from './OpenVidu'; import { Publisher } from './Publisher'; import { Stream } from './Stream'; @@ -513,8 +514,8 @@ export class Session implements EventDispatcher { } } else { console.info('Filter successfully applied on Stream ' + stream.streamId); - const oldValue = JSON.parse(JSON.stringify(stream.filter)); - stream.filter = { type, options }; + const oldValue: Filter = stream.filter; + stream.filter = new Filter(type, options); this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, stream, 'filter', stream.filter, oldValue, 'applyFilter')]); stream.streamManager.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(stream.streamManager, stream, 'filter', stream.filter, oldValue, 'applyFilter')]); resolve(); @@ -580,7 +581,7 @@ export class Session implements EventDispatcher { } else { console.info('Filter successfully removed from Stream ' + stream.streamId); const oldValue = JSON.parse(JSON.stringify(stream.filter)); - stream.filter = new Object(); + delete stream.filter; this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, stream, 'filter', stream.filter, oldValue, 'applyFilter')]); stream.streamManager.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(stream.streamManager, stream, 'filter', stream.filter, oldValue, 'applyFilter')]); resolve(); @@ -937,6 +938,7 @@ export class Session implements EventDispatcher { break; case 'filter': oldValue = stream.filter; + msg.newValue = (Object.keys(msg.newValue).length > 0) ? msg.newValue : undefined; stream.filter = msg.newValue; break; } diff --git a/openvidu-browser/src/OpenVidu/Stream.ts b/openvidu-browser/src/OpenVidu/Stream.ts index efed8c21..afb97d56 100644 --- a/openvidu-browser/src/OpenVidu/Stream.ts +++ b/openvidu-browser/src/OpenVidu/Stream.ts @@ -17,6 +17,7 @@ import { Connection } from './Connection'; import { Event } from '../OpenViduInternal/Events/Event'; +import { Filter } from './Filter'; import { Session } from './Session'; import { StreamManager } from './StreamManager'; import { EventDispatcher } from '../OpenViduInternal/Interfaces/Public/EventDispatcher'; @@ -109,13 +110,7 @@ export class Stream implements EventDispatcher { * [[Session.execFilterMethod]] and remove it with [[Session.removeFilter]]. Be aware that the client calling this methods must have the * necessary permissions: the token owned by the client must have been initialized with the appropriated `allowedFilters` array. */ - filter: { - type?: string, - options?: Object, - lastExecMethod?: { - method: string, params: Object - } - } = {}; + filter: Filter; /** * @hidden @@ -180,7 +175,7 @@ export class Stream implements EventDispatcher { this.frameRate = (this.inboundStreamOpts.frameRate === -1) ? undefined : this.inboundStreamOpts.frameRate; this.videoDimensions = this.inboundStreamOpts.videoDimensions; } - if (!!this.inboundStreamOpts.filter) { + if (!!this.inboundStreamOpts.filter && (Object.keys(this.inboundStreamOpts.filter).length > 0)) { if (!!this.inboundStreamOpts.filter.lastExecMethod && Object.keys(this.inboundStreamOpts.filter.lastExecMethod).length === 0) { delete this.inboundStreamOpts.filter.lastExecMethod; } diff --git a/openvidu-browser/src/OpenViduInternal/Events/FilterEvent.ts b/openvidu-browser/src/OpenViduInternal/Events/FilterEvent.ts index 868e1dbb..84eaef6f 100644 --- a/openvidu-browser/src/OpenViduInternal/Events/FilterEvent.ts +++ b/openvidu-browser/src/OpenViduInternal/Events/FilterEvent.ts @@ -17,7 +17,7 @@ import { Event } from './Event'; import { Stream } from '../../OpenVidu/Stream'; -import { Filter } from '../Interfaces/Public/Filter'; +import { Filter } from '../../OpenVidu/Filter'; /** diff --git a/openvidu-browser/src/OpenViduInternal/Interfaces/Private/InboundStreamOptions.ts b/openvidu-browser/src/OpenViduInternal/Interfaces/Private/InboundStreamOptions.ts index 918e7b79..5f81ce0a 100644 --- a/openvidu-browser/src/OpenViduInternal/Interfaces/Private/InboundStreamOptions.ts +++ b/openvidu-browser/src/OpenViduInternal/Interfaces/Private/InboundStreamOptions.ts @@ -16,7 +16,7 @@ */ import { Connection } from '../../../OpenVidu/Connection'; -import { Filter } from '../Public/Filter'; +import { Filter } from '../../../OpenVidu/Filter'; export interface InboundStreamOptions { id: string; @@ -28,5 +28,5 @@ export interface InboundStreamOptions { typeOfVideo: string; frameRate: number; videoDimensions: { width: number, height: number }; - filter: Filter; + filter?: Filter; } \ No newline at end of file diff --git a/openvidu-browser/src/OpenViduInternal/Interfaces/Private/StreamOptionsServer.ts b/openvidu-browser/src/OpenViduInternal/Interfaces/Private/StreamOptionsServer.ts index 48717d75..d3bfce4c 100644 --- a/openvidu-browser/src/OpenViduInternal/Interfaces/Private/StreamOptionsServer.ts +++ b/openvidu-browser/src/OpenViduInternal/Interfaces/Private/StreamOptionsServer.ts @@ -15,7 +15,7 @@ * */ -import { Filter } from '../Public/Filter'; +import { Filter } from '../../../OpenVidu/Filter'; export interface StreamOptionsServer { id: string; diff --git a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/PublisherProperties.ts b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/PublisherProperties.ts index 687c89ad..55df2229 100644 --- a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/PublisherProperties.ts +++ b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/PublisherProperties.ts @@ -15,7 +15,7 @@ * */ -import { Filter } from './Filter'; +import { Filter } from '../../../OpenVidu/Filter'; import { VideoInsertMode } from '../../Enums/VideoInsertMode'; /** diff --git a/openvidu-browser/src/index.ts b/openvidu-browser/src/index.ts index ec11f32d..498f6729 100644 --- a/openvidu-browser/src/index.ts +++ b/openvidu-browser/src/index.ts @@ -6,6 +6,7 @@ export { StreamManager } from './OpenVidu/StreamManager'; export { Stream } from './OpenVidu/Stream'; export { Connection } from './OpenVidu/Connection'; export { LocalRecorder } from './OpenVidu/LocalRecorder'; +export { Filter } from './OpenVidu/Filter'; export { LocalRecorderState } from './OpenViduInternal/Enums/LocalRecorderState'; export { OpenViduError } from './OpenViduInternal/Enums/OpenViduError'; @@ -26,7 +27,6 @@ export { FilterEvent } from './OpenViduInternal/Events/FilterEvent'; export { Capabilities } from './OpenViduInternal/Interfaces/Public/Capabilities'; export { Device } from './OpenViduInternal/Interfaces/Public/Device'; export { EventDispatcher } from './OpenViduInternal/Interfaces/Public/EventDispatcher'; -export { Filter } from './OpenViduInternal/Interfaces/Public/Filter'; export { OpenViduAdvancedConfiguration } from './OpenViduInternal/Interfaces/Public/OpenViduAdvancedConfiguration'; export { PublisherProperties } from './OpenViduInternal/Interfaces/Public/PublisherProperties'; export { SignalOptions } from './OpenViduInternal/Interfaces/Public/SignalOptions';