openvidu-browser: Network quality

- Added networkQualityChanged event
pull/546/head
csantosm 2020-09-18 15:15:55 +02:00
parent 1bfde64752
commit c39e16852f
3 changed files with 79 additions and 3 deletions

View File

@ -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)

View File

@ -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
*/

View File

@ -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"
}