openvidu-browser: Publisher publishAudio and publishVideo may be called without a Session

pull/173/head
pabloFuente 2018-12-07 11:47:22 +01:00
parent 5f1565cac0
commit 2a85971dfa
1 changed files with 40 additions and 32 deletions

View File

@ -90,6 +90,8 @@ export class Publisher extends StreamManager {
* *
* #### Events dispatched * #### Events dispatched
* *
* > _Only if `Session.publish(Publisher)` has been called for this Publisher_
*
* The [[Session]] object of the local participant will dispatch a `streamPropertyChanged` event with `changedProperty` set to `"audioActive"` and `reason` set to `"publishAudio"` * The [[Session]] object of the local participant will dispatch a `streamPropertyChanged` event with `changedProperty` set to `"audioActive"` and `reason` set to `"publishAudio"`
* The [[Publisher]] object of the local participant will also dispatch the exact same event * The [[Publisher]] object of the local participant will also dispatch the exact same event
* *
@ -105,6 +107,7 @@ export class Publisher extends StreamManager {
this.stream.getMediaStream().getAudioTracks().forEach((track) => { this.stream.getMediaStream().getAudioTracks().forEach((track) => {
track.enabled = value; track.enabled = value;
}); });
if (!!this.session && !!this.stream.streamId) {
this.session.openvidu.sendRequest( this.session.openvidu.sendRequest(
'streamPropertyChanged', 'streamPropertyChanged',
{ {
@ -121,6 +124,7 @@ export class Publisher extends StreamManager {
this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, this.stream, 'audioActive', value, !value, 'publishAudio')]); this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, this.stream, 'audioActive', value, !value, 'publishAudio')]);
} }
}); });
}
this.stream.audioActive = value; this.stream.audioActive = value;
console.info("'Publisher' has " + (value ? 'published' : 'unpublished') + ' its audio stream'); console.info("'Publisher' has " + (value ? 'published' : 'unpublished') + ' its audio stream');
} }
@ -132,6 +136,8 @@ export class Publisher extends StreamManager {
* *
* #### Events dispatched * #### Events dispatched
* *
* > _Only if `Session.publish(Publisher)` has been called for this Publisher_
*
* The [[Session]] object of the local participant will dispatch a `streamPropertyChanged` event with `changedProperty` set to `"videoActive"` and `reason` set to `"publishVideo"` * The [[Session]] object of the local participant will dispatch a `streamPropertyChanged` event with `changedProperty` set to `"videoActive"` and `reason` set to `"publishVideo"`
* The [[Publisher]] object of the local participant will also dispatch the exact same event * The [[Publisher]] object of the local participant will also dispatch the exact same event
* *
@ -147,6 +153,7 @@ export class Publisher extends StreamManager {
this.stream.getMediaStream().getVideoTracks().forEach((track) => { this.stream.getMediaStream().getVideoTracks().forEach((track) => {
track.enabled = value; track.enabled = value;
}); });
if (!!this.session && !!this.stream.streamId) {
this.session.openvidu.sendRequest( this.session.openvidu.sendRequest(
'streamPropertyChanged', 'streamPropertyChanged',
{ {
@ -163,6 +170,7 @@ export class Publisher extends StreamManager {
this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, this.stream, 'videoActive', value, !value, 'publishVideo')]); this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, this.stream, 'videoActive', value, !value, 'publishVideo')]);
} }
}); });
}
this.stream.videoActive = value; this.stream.videoActive = value;
console.info("'Publisher' has " + (value ? 'published' : 'unpublished') + ' its video stream'); console.info("'Publisher' has " + (value ? 'published' : 'unpublished') + ' its video stream');
} }