mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: StreamManager#updatePublisherSpeakingEventsOptions
parent
61134c5b96
commit
acdfef3e21
|
@ -614,7 +614,9 @@ export class OpenVidu {
|
|||
* Set OpenVidu advanced configuration options. Currently `configuration` is an object with the following optional properties (see [[OpenViduAdvancedConfiguration]] for more details):
|
||||
* - `iceServers`: set custom STUN/TURN servers to be used by OpenVidu Browser
|
||||
* - `screenShareChromeExtension`: url to a custom screen share extension for Chrome to be used instead of the default one, based on ours [https://github.com/OpenVidu/openvidu-screen-sharing-chrome-extension](https://github.com/OpenVidu/openvidu-screen-sharing-chrome-extension)
|
||||
* - `publisherSpeakingEventsOptions`: custom configuration for the [[PublisherSpeakingEvent]] feature
|
||||
* - `publisherSpeakingEventsOptions`: custom configuration for the [[PublisherSpeakingEvent]] feature and the [StreamManagerEvent.streamAudioVolumeChange](/api/openvidu-browser/classes/streammanagerevent.html) feature
|
||||
*
|
||||
* Call this method to override previous values at any moment.
|
||||
*/
|
||||
setAdvancedConfiguration(configuration: OpenViduAdvancedConfiguration): void {
|
||||
this.advancedConfiguration = configuration;
|
||||
|
|
|
@ -188,6 +188,10 @@ export class Stream implements EventDispatcher {
|
|||
* @hidden
|
||||
*/
|
||||
volumeChangeEventEnabledOnce = false;
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
harkOptions;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -768,8 +772,8 @@ export class Stream implements EventDispatcher {
|
|||
private setSpeechEventIfNotExists(): boolean {
|
||||
if (!!this.mediaStream) {
|
||||
if (!this.speechEvent) {
|
||||
const harkOptions = this.session.openvidu.advancedConfiguration.publisherSpeakingEventsOptions || {};
|
||||
harkOptions.interval = (typeof harkOptions.interval === 'number') ? harkOptions.interval : 50;
|
||||
const harkOptions = !!this.harkOptions ? this.harkOptions : (this.session.openvidu.advancedConfiguration.publisherSpeakingEventsOptions || {});
|
||||
harkOptions.interval = (typeof harkOptions.interval === 'number') ? harkOptions.interval : 100;
|
||||
harkOptions.threshold = (typeof harkOptions.threshold === 'number') ? harkOptions.threshold : -50;
|
||||
this.speechEvent = hark(this.mediaStream, harkOptions);
|
||||
}
|
||||
|
|
|
@ -343,6 +343,33 @@ export class StreamManager implements EventDispatcher {
|
|||
return video;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current configuration for the [[PublisherSpeakingEvent]] feature and the [StreamManagerEvent.streamAudioVolumeChange](/api/openvidu-browser/classes/streammanagerevent.html) feature for this specific
|
||||
* StreamManager audio stream, overriding the global options set with [[OpenVidu.setAdvancedConfiguration]]. This way you can customize the audio events options
|
||||
* for each specific StreamManager and change them dynamically.
|
||||
*
|
||||
* @param publisherSpeakingEventsOptions New options to be applied to this StreamManager's audio stream. It is an object which includes the following optional properties:
|
||||
* - `interval`: (number) how frequently the analyser polls the audio stream to check if speaking has started/stopped or audio volume has changed. Default **100** (ms)
|
||||
* - `threshold`: (number) the volume at which _publisherStartSpeaking_, _publisherStopSpeaking_ events will be fired. Default **-50** (dB)
|
||||
*/
|
||||
updatePublisherSpeakingEventsOptions(publisherSpeakingEventsOptions): void {
|
||||
const currentHarkOptions = !!this.stream.harkOptions ? this.stream.harkOptions : (this.stream.session.openvidu.advancedConfiguration.publisherSpeakingEventsOptions || {});
|
||||
const newInterval = (typeof publisherSpeakingEventsOptions.interval === 'number') ?
|
||||
publisherSpeakingEventsOptions.interval : ((typeof currentHarkOptions.interval === 'number') ? currentHarkOptions.interval : 100);
|
||||
const newThreshold = (typeof publisherSpeakingEventsOptions.threshold === 'number') ?
|
||||
publisherSpeakingEventsOptions.threshold : ((typeof currentHarkOptions.threshold === 'number') ? currentHarkOptions.threshold : -50);
|
||||
this.stream.harkOptions = {
|
||||
interval: newInterval,
|
||||
threshold: newThreshold
|
||||
};
|
||||
if (!!this.stream.speechEvent) {
|
||||
this.stream.speechEvent.setInterval(newInterval);
|
||||
this.stream.speechEvent.setThreshold(newThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
/* Hidden methods */
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
|
@ -458,6 +485,8 @@ export class StreamManager implements EventDispatcher {
|
|||
this.ee.emitEvent(type, eventArray);
|
||||
}
|
||||
|
||||
/* Private methods */
|
||||
|
||||
private pushNewStreamManagerVideo(streamManagerVideo: StreamManagerVideo) {
|
||||
this.videos.push(streamManagerVideo);
|
||||
this.addPlayEventToFirstVideo();
|
||||
|
|
|
@ -27,8 +27,6 @@ import { Session } from '../..';
|
|||
*
|
||||
* More information:
|
||||
* - This events will only be triggered for **remote streams that have audio tracks** ([[Stream.hasAudio]] must be true)
|
||||
* - Both events share the same lifecycle. That means that you can subscribe to only one of them if you want, but if you call `Session.off('publisherStopSpeaking')`,
|
||||
* keep in mind that this will also internally remove any 'publisherStartSpeaking' event
|
||||
* - You can further configure how the events are dispatched by setting property `publisherSpeakingEventsOptions` in the call of [[OpenVidu.setAdvancedConfiguration]]
|
||||
*/
|
||||
export class PublisherSpeakingEvent extends Event {
|
||||
|
|
|
@ -24,7 +24,7 @@ import { StreamManager } from '../../OpenVidu/StreamManager';
|
|||
* and has begun to play). This event will be dispatched when these 3 conditions are met 1) The StreamManager has no video associated in the DOM 2) It is associated to one video 3) That video starts playing
|
||||
* - `streamAudioVolumeChange`: dispatched by [[StreamManager]] ([[Publisher]] and [[Subscriber]]) when the volume of its Stream's audio track
|
||||
* changes. Only applies if [[Stream.hasAudio]] is `true`. The frequency this event is fired with is defined by property `interval` of
|
||||
* [[OpenViduAdvancedConfiguration.publisherSpeakingEventsOptions]] (default 50ms)
|
||||
* [[OpenViduAdvancedConfiguration.publisherSpeakingEventsOptions]] (default 100ms)
|
||||
*/
|
||||
export class StreamManagerEvent extends Event {
|
||||
|
||||
|
|
|
@ -33,9 +33,11 @@ export interface OpenViduAdvancedConfiguration {
|
|||
screenShareChromeExtension?: string;
|
||||
|
||||
/**
|
||||
* Custom configuration for the [[PublisherSpeakingEvent]] feature. It is an object which includes the following optional properties:
|
||||
* - `interval`: (number) how frequently the analyser polls the audio stream to check if speaking has started or stopped. Default **50** (ms)
|
||||
* Custom configuration for the [[PublisherSpeakingEvent]] feature and the [StreamManagerEvent.streamAudioVolumeChange](/api/openvidu-browser/classes/streammanagerevent.html) feature. It is an object which includes the following optional properties:
|
||||
* - `interval`: (number) how frequently the analyser polls the audio stream to check if speaking has started/stopped or audio volume has changed. Default **100** (ms)
|
||||
* - `threshold`: (number) the volume at which _publisherStartSpeaking_ and _publisherStopSpeaking_ events will be fired. Default **-50** (dB)
|
||||
*
|
||||
* This sets the global default configuration that will affect all streams, but you can later customize these values for each specific stream by calling [[StreamManager.updatePublisherSpeakingEventsOptions]]
|
||||
*/
|
||||
publisherSpeakingEventsOptions?: any;
|
||||
|
||||
|
|
Loading…
Reference in New Issue