openvidu-browser: add new StreamPropertyChanged for audioTrack and videoTrack

pull/748/head
pabloFuente 2022-11-02 12:11:01 +01:00
parent 48f20ec64f
commit 0e9ae092e5
4 changed files with 15 additions and 6 deletions

View File

@ -717,9 +717,10 @@ export class OpenVidu {
/** /**
* @hidden * @hidden
*/ */
sendTrackChangedEvent(publisher: Publisher, reason: string, oldLabel: string, newLabel: string, propertyType: string) { sendTrackChangedEvent(publisher: Publisher, oldLabel: string, newLabel: string, propertyType: string) {
const oldValue = { label: oldLabel }; const oldValue = { label: oldLabel };
const newValue = { label: newLabel }; const newValue = { label: newLabel };
const reason = 'trackReplaced';
if (publisher.stream.isLocalStreamPublished) { if (publisher.stream.isLocalStreamPublished) {
this.sendRequest( this.sendRequest(
@ -727,7 +728,7 @@ export class OpenVidu {
{ {
streamId: publisher.stream.streamId, streamId: publisher.stream.streamId,
property: propertyType, property: propertyType,
newValue: JSON.stringify({ newLabel }), newValue: newValue,
reason reason
}, },
(error, response) => { (error, response) => {

View File

@ -811,12 +811,12 @@ export class Publisher extends StreamManager {
}; };
if (track.kind === 'video' && updateLastConstraints) { if (track.kind === 'video' && updateLastConstraints) {
this.openvidu.sendNewVideoDimensionsIfRequired(this, 'trackReplaced', 50, 30); this.openvidu.sendNewVideoDimensionsIfRequired(this, 'trackReplaced', 50, 30);
this.openvidu.sendTrackChangedEvent(this, 'trackReplaced', trackInfo.oldLabel, trackInfo.newLabel, 'videoActive'); this.openvidu.sendTrackChangedEvent(this, trackInfo.oldLabel, trackInfo.newLabel, 'videoTrack');
if (this.stream.isLocalStreamPublished) { if (this.stream.isLocalStreamPublished) {
this.session.sendVideoData(this.stream.streamManager, 5, true, 5); this.session.sendVideoData(this.stream.streamManager, 5, true, 5);
} }
} else if (track.kind === 'audio' && updateLastConstraints) { } else if (track.kind === 'audio' && updateLastConstraints) {
this.openvidu.sendTrackChangedEvent(this, 'trackReplaced', trackInfo.oldLabel, trackInfo.newLabel, 'audioActive'); this.openvidu.sendTrackChangedEvent(this, trackInfo.oldLabel, trackInfo.newLabel, 'audioTrack');
} }
if (track.kind === 'audio') { if (track.kind === 'audio') {
this.stream.disableHarkSpeakingEvent(false); this.stream.disableHarkSpeakingEvent(false);

View File

@ -649,7 +649,7 @@ export class Session extends EventDispatcher {
* when speech is detected in its audio track. * when speech is detected in its audio track.
* *
* @param stream - The Stream for which you want to start receiving [[SpeechToTextEvent]]. * @param stream - The Stream for which you want to start receiving [[SpeechToTextEvent]].
* @þaram lang - The language of the Stream's audio track. It must be a valid [BCP-47](https://tools.ietf.org/html/bcp47) language tag like "en-US" or "es-ES". * @param lang - The language of the Stream's audio track. It must be a valid [BCP-47](https://tools.ietf.org/html/bcp47) language tag like "en-US" or "es-ES".
* *
* @returns A Promise (to which you can optionally subscribe to) that is resolved if the speech-to-text subscription * @returns A Promise (to which you can optionally subscribe to) that is resolved if the speech-to-text subscription
* was successful and rejected with an Error object if not. * was successful and rejected with an Error object if not.
@ -990,6 +990,12 @@ export class Session extends EventDispatcher {
event.newValue = event.newValue === 'true'; event.newValue = event.newValue === 'true';
stream.videoActive = event.newValue; stream.videoActive = event.newValue;
break; break;
case 'videoTrack':
event.newValue = JSON.parse(event.newValue);
break;
case 'audioTrack':
event.newValue = JSON.parse(event.newValue);
break;
case 'videoDimensions': case 'videoDimensions':
oldValue = stream.videoDimensions; oldValue = stream.videoDimensions;
event.newValue = JSON.parse(JSON.parse(event.newValue)); event.newValue = JSON.parse(JSON.parse(event.newValue));

View File

@ -30,7 +30,7 @@ export class StreamPropertyChangedEvent extends Event {
stream: Stream; stream: Stream;
/** /**
* The property of the stream that changed. This value is either `"videoActive"`, `"audioActive"`, `"videoDimensions"` or `"filter"` * The property of the stream that changed. This value is either `"videoActive"`, `"audioActive"`, `"videoTrack"`, `"audioTrack"`, `"videoDimensions"` or `"filter"`
*/ */
changedProperty: string; changedProperty: string;
@ -38,6 +38,8 @@ export class StreamPropertyChangedEvent extends Event {
* Cause of the change on the stream's property: * Cause of the change on the stream's property:
* - For `videoActive`: `"publishVideo"` * - For `videoActive`: `"publishVideo"`
* - For `audioActive`: `"publishAudio"` * - For `audioActive`: `"publishAudio"`
* - For `videoTrack`: `"trackReplaced"`
* - For `audioTrack`: `"trackReplaced"`
* - For `videoDimensions`: `"deviceRotated"`, `"screenResized"` or `"trackReplaced"` * - For `videoDimensions`: `"deviceRotated"`, `"screenResized"` or `"trackReplaced"`
* - For `filter`: `"applyFilter"`, `"execFilterMethod"` or `"removeFilter"` * - For `filter`: `"applyFilter"`, `"execFilterMethod"` or `"removeFilter"`
*/ */