From c39e16852f6bf64a5f26d9a5829225f4e6457630 Mon Sep 17 00:00:00 2001 From: csantosm <4a.santos@gmail.com> Date: Fri, 18 Sep 2020 15:15:55 +0200 Subject: [PATCH] openvidu-browser: Network quality - Added networkQualityChanged event --- openvidu-browser/src/OpenVidu/OpenVidu.ts | 1 + openvidu-browser/src/OpenVidu/Session.ts | 18 +++++- .../Events/NetworkQualityChangedEvent.ts | 63 +++++++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 openvidu-browser/src/OpenViduInternal/Events/NetworkQualityChangedEvent.ts diff --git a/openvidu-browser/src/OpenVidu/OpenVidu.ts b/openvidu-browser/src/OpenVidu/OpenVidu.ts index 6a7bb76b..8820a72c 100644 --- a/openvidu-browser/src/OpenVidu/OpenVidu.ts +++ b/openvidu-browser/src/OpenVidu/OpenVidu.ts @@ -777,6 +777,7 @@ export class OpenVidu { recordingStopped: this.session.onRecordingStopped.bind(this.session), sendMessage: this.session.onNewMessage.bind(this.session), streamPropertyChanged: this.session.onStreamPropertyChanged.bind(this.session), + networkQualityChanged: this.session.onNetworkQualityChangedChanged.bind(this.session), filterEventDispatched: this.session.onFilterEventDispatched.bind(this.session), iceCandidate: this.session.recvIceCandidate.bind(this.session), mediaError: this.session.onMediaError.bind(this.session) diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 61f50bc9..f6650a68 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -37,6 +37,7 @@ import { SessionDisconnectedEvent } from '../OpenViduInternal/Events/SessionDisc import { SignalEvent } from '../OpenViduInternal/Events/SignalEvent'; import { StreamEvent } from '../OpenViduInternal/Events/StreamEvent'; import { StreamPropertyChangedEvent } from '../OpenViduInternal/Events/StreamPropertyChangedEvent'; +import { NetworkQualityChangedEvent, NetworkQualityChangedReason } from '../OpenViduInternal/Events/NetworkQualityChangedEvent'; import { OpenViduError, OpenViduErrorName } from '../OpenViduInternal/Enums/OpenViduError'; import { VideoInsertMode } from '../OpenViduInternal/Enums/VideoInsertMode'; @@ -591,7 +592,7 @@ export class Session extends EventDispatcher { /** * See [[EventDispatcher.on]] */ - on(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): EventDispatcher { + on(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent | NetworkQualityChangedEvent) => void): EventDispatcher { super.onAux(type, "Event '" + type + "' triggered by 'Session'", handler); @@ -623,7 +624,7 @@ export class Session extends EventDispatcher { /** * See [[EventDispatcher.once]] */ - once(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): Session { + once(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent | NetworkQualityChangedEvent) => void): Session { super.onceAux(type, "Event '" + type + "' triggered once by 'Session'", handler); @@ -655,7 +656,7 @@ export class Session extends EventDispatcher { /** * See [[EventDispatcher.off]] */ - off(type: string, handler?: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): Session { + off(type: string, handler?: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent | NetworkQualityChangedEvent) => void): Session { super.off(type, handler); @@ -920,6 +921,17 @@ export class Session extends EventDispatcher { } } + + /** + * @hidden + */ + onNetworkQualityChangedChanged(msg): void { + + if (msg.connectionId === this.connection.connectionId) { + this.ee.emitEvent('networkQualityChanged', [new NetworkQualityChangedEvent(this, msg.newValue, msg.oldValue, msg.reason)]); + } + } + /** * @hidden */ diff --git a/openvidu-browser/src/OpenViduInternal/Events/NetworkQualityChangedEvent.ts b/openvidu-browser/src/OpenViduInternal/Events/NetworkQualityChangedEvent.ts new file mode 100644 index 00000000..710950e0 --- /dev/null +++ b/openvidu-browser/src/OpenViduInternal/Events/NetworkQualityChangedEvent.ts @@ -0,0 +1,63 @@ +/* + * (C) Copyright 2017-2020 OpenVidu (https://openvidu.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import { Event } from './Event'; +import { Session } from '../../OpenVidu/Session'; + +/** + * Defines event `networkQualityChangedEvent` dispatched by [[Session]]. + * This event is fired when the network quality of the local connection changes + */ +export class NetworkQualityChangedEvent extends Event { + + /** + * Cause of the change on the neteotk quality event + */ + reason: NetworkQualityChangedReason; + + /** + * New value of the property (after change, current value) + */ + newValue: Object; + + /** + * Previous value of the property (before change) + */ + oldValue: Object; + + /** + * @hidden + */ + constructor(target: Session, newValue: Object, oldValue: Object, reason: NetworkQualityChangedReason) { + super(false, target, 'networkQualityChanged'); + this.newValue = newValue; + this.oldValue = oldValue; + this.reason = reason; + } + + /** + * @hidden + */ + // tslint:disable-next-line:no-empty + callDefaultBehavior() { } + +} + +export enum NetworkQualityChangedReason { + ABOVE_MAX = "above_max", + BELOW_MIN = "below_min" +}