mirror of https://github.com/OpenVidu/openvidu.git
openvidu-brower: NO_STREAM_PLAYING_EVENT only for Subscriber
parent
21615755f9
commit
da527b4816
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Stream } from './Stream';
|
import { Stream } from './Stream';
|
||||||
|
import { Subscriber } from './Subscriber';
|
||||||
import { EventDispatcher } from './EventDispatcher';
|
import { EventDispatcher } from './EventDispatcher';
|
||||||
import { StreamManagerVideo } from '../OpenViduInternal/Interfaces/Public/StreamManagerVideo';
|
import { StreamManagerVideo } from '../OpenViduInternal/Interfaces/Public/StreamManagerVideo';
|
||||||
import { Event } from '../OpenViduInternal/Events/Event';
|
import { Event } from '../OpenViduInternal/Events/Event';
|
||||||
|
@ -144,7 +145,10 @@ export class StreamManager extends EventDispatcher {
|
||||||
|
|
||||||
this.canPlayListener = () => {
|
this.canPlayListener = () => {
|
||||||
this.deactivateStreamPlayingEventExceptionTimeout();
|
this.deactivateStreamPlayingEventExceptionTimeout();
|
||||||
if (this.stream.isLocal()) {
|
if (this.remote) {
|
||||||
|
logger.info("Remote 'Stream' with id [" + this.stream.streamId + '] video is now playing');
|
||||||
|
this.ee.emitEvent('videoPlaying', [new VideoElementEvent(this.videos[0].video, this, 'videoPlaying')]);
|
||||||
|
} else {
|
||||||
if (!this.stream.displayMyRemote()) {
|
if (!this.stream.displayMyRemote()) {
|
||||||
logger.info("Your local 'Stream' with id [" + this.stream.streamId + '] video is now playing');
|
logger.info("Your local 'Stream' with id [" + this.stream.streamId + '] video is now playing');
|
||||||
this.ee.emitEvent('videoPlaying', [new VideoElementEvent(this.videos[0].video, this, 'videoPlaying')]);
|
this.ee.emitEvent('videoPlaying', [new VideoElementEvent(this.videos[0].video, this, 'videoPlaying')]);
|
||||||
|
@ -152,9 +156,6 @@ export class StreamManager extends EventDispatcher {
|
||||||
logger.info("Your own remote 'Stream' with id [" + this.stream.streamId + '] video is now playing');
|
logger.info("Your own remote 'Stream' with id [" + this.stream.streamId + '] video is now playing');
|
||||||
this.ee.emitEvent('remoteVideoPlaying', [new VideoElementEvent(this.videos[0].video, this, 'remoteVideoPlaying')]);
|
this.ee.emitEvent('remoteVideoPlaying', [new VideoElementEvent(this.videos[0].video, this, 'remoteVideoPlaying')]);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
logger.info("Remote 'Stream' with id [" + this.stream.streamId + '] video is now playing');
|
|
||||||
this.ee.emitEvent('videoPlaying', [new VideoElementEvent(this.videos[0].video, this, 'videoPlaying')]);
|
|
||||||
}
|
}
|
||||||
this.ee.emitEvent('streamPlaying', [new StreamManagerEvent(this, 'streamPlaying', undefined)]);
|
this.ee.emitEvent('streamPlaying', [new StreamManagerEvent(this, 'streamPlaying', undefined)]);
|
||||||
};
|
};
|
||||||
|
@ -280,7 +281,7 @@ export class StreamManager extends EventDispatcher {
|
||||||
|
|
||||||
this.initializeVideoProperties(video);
|
this.initializeVideoProperties(video);
|
||||||
|
|
||||||
if (this.stream.isLocal() && this.stream.displayMyRemote()) {
|
if (!this.remote && this.stream.displayMyRemote()) {
|
||||||
if (video.srcObject !== this.stream.getMediaStream()) {
|
if (video.srcObject !== this.stream.getMediaStream()) {
|
||||||
video.srcObject = this.stream.getMediaStream();
|
video.srcObject = this.stream.getMediaStream();
|
||||||
}
|
}
|
||||||
|
@ -414,7 +415,7 @@ export class StreamManager extends EventDispatcher {
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
initializeVideoProperties(video: HTMLVideoElement): void {
|
initializeVideoProperties(video: HTMLVideoElement): void {
|
||||||
if (!(this.stream.isLocal() && this.stream.displayMyRemote())) {
|
if (!(!this.remote && this.stream.displayMyRemote())) {
|
||||||
// Avoid setting the MediaStream into the srcObject if remote subscription before publishing
|
// Avoid setting the MediaStream into the srcObject if remote subscription before publishing
|
||||||
if (video.srcObject !== this.stream.getMediaStream()) {
|
if (video.srcObject !== this.stream.getMediaStream()) {
|
||||||
// If srcObject already set don't do it again
|
// If srcObject already set don't do it again
|
||||||
|
@ -566,6 +567,10 @@ export class StreamManager extends EventDispatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
private activateStreamPlayingEventExceptionTimeout() {
|
private activateStreamPlayingEventExceptionTimeout() {
|
||||||
|
if (!this.remote) {
|
||||||
|
// ExceptionEvent NO_STREAM_PLAYING_EVENT is only for subscribers
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.streamPlayingEventExceptionTimeout != null) {
|
if (this.streamPlayingEventExceptionTimeout != null) {
|
||||||
// The timeout is already activated
|
// The timeout is already activated
|
||||||
return;
|
return;
|
||||||
|
@ -575,7 +580,7 @@ export class StreamManager extends EventDispatcher {
|
||||||
this.streamPlayingEventExceptionTimeout = setTimeout(() => {
|
this.streamPlayingEventExceptionTimeout = setTimeout(() => {
|
||||||
const msg = 'StreamManager of Stream ' + this.stream.streamId + ' (' + (this.remote ? 'Subscriber' : 'Publisher') + ') did not trigger "streamPlaying" event in ' + msTimeout + ' ms';
|
const msg = 'StreamManager of Stream ' + this.stream.streamId + ' (' + (this.remote ? 'Subscriber' : 'Publisher') + ') did not trigger "streamPlaying" event in ' + msTimeout + ' ms';
|
||||||
logger.warn(msg);
|
logger.warn(msg);
|
||||||
this.stream.session.emitEvent('exception', [new ExceptionEvent(this.stream.session, ExceptionEventName.NO_STREAM_PLAYING_EVENT, this, msg)]);
|
this.stream.session.emitEvent('exception', [new ExceptionEvent(this.stream.session, ExceptionEventName.NO_STREAM_PLAYING_EVENT, (<any>this) as Subscriber, msg)]);
|
||||||
delete this.streamPlayingEventExceptionTimeout;
|
delete this.streamPlayingEventExceptionTimeout;
|
||||||
}, msTimeout);
|
}, msTimeout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
import { Session } from '../../OpenVidu/Session';
|
import { Session } from '../../OpenVidu/Session';
|
||||||
import { Stream } from '../../OpenVidu/Stream';
|
import { Stream } from '../../OpenVidu/Stream';
|
||||||
import { StreamManager } from '../../OpenVidu/StreamManager';
|
import { Subscriber } from '../../OpenVidu/Subscriber';
|
||||||
import { Event } from './Event';
|
import { Event } from './Event';
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,23 +62,23 @@ export enum ExceptionEventName {
|
||||||
ICE_CONNECTION_DISCONNECTED = 'ICE_CONNECTION_DISCONNECTED',
|
ICE_CONNECTION_DISCONNECTED = 'ICE_CONNECTION_DISCONNECTED',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A [[StreamManager]] object has not fired event `streamPlaying` after certain timeout. `streamPlaying` event belongs to [[StreamManagerEvent]]
|
* A [[Subscriber]] object has not fired event `streamPlaying` after certain timeout. `streamPlaying` event belongs to [[StreamManagerEvent]]
|
||||||
* category. It wraps Web API native event [canplay](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canplay_event).
|
* category. It wraps Web API native event [canplay](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canplay_event).
|
||||||
*
|
*
|
||||||
* OpenVidu Browser can take care of the video players (see [here](/en/latest/cheatsheet/manage-videos/#let-openvidu-take-care-of-the-video-players)),
|
* OpenVidu Browser can take care of the video players (see [here](/en/latest/cheatsheet/manage-videos/#let-openvidu-take-care-of-the-video-players)),
|
||||||
* or you can take care of video players on your own (see [here](/en/latest/cheatsheet/manage-videos/#you-take-care-of-the-video-players)).
|
* or you can take care of video players on your own (see [here](/en/latest/cheatsheet/manage-videos/#you-take-care-of-the-video-players)).
|
||||||
* Either way, whenever a [[Publisher]] or [[Subscriber]] object is commanded to attach its [[Stream]] to a video element, it is supposed to fire
|
* Either way, whenever a [[Subscriber]] object is commanded to attach its [[Stream]] to a video element, it is supposed to fire `streamPlaying`
|
||||||
* `streamPlaying` event shortly after. If it does not, then we can safely assume that something wrong has happened and the application may be notified
|
* event shortly after. If it does not, then we can safely assume that something wrong has happened while playing the remote video and the
|
||||||
* through this specific ExceptionEvent.
|
* application may be notified through this specific ExceptionEvent.
|
||||||
*
|
*
|
||||||
* The timeout can be configured with property [[OpenViduAdvancedConfiguration.noStreamPlayingEventExceptionTimeout]]. By default it is 4000 milliseconds.
|
* The timeout can be configured with property [[OpenViduAdvancedConfiguration.noStreamPlayingEventExceptionTimeout]]. By default it is 4000 milliseconds.
|
||||||
*
|
*
|
||||||
* This is just an informative exception. It only means that a Stream that is supposed to be playing by a video player has not done so
|
* This is just an informative exception. It only means that a remote Stream that is supposed to be playing by a video player has not done so
|
||||||
* in a reasonable time. But the lack of the event can be caused by multiple reasons. If a Subscriber is not playing its Stream, the origin
|
* in a reasonable time. But the lack of the event can be caused by multiple reasons. If a Subscriber is not playing its Stream, the origin
|
||||||
* of the problem could be located at the Publisher side. Or may be caused by a transient network problem. But it also could be a problem with
|
* of the problem could be located at the Publisher side. Or may be caused by a transient network problem. But it also could be a problem with
|
||||||
* autoplay permissions. Bottom line, the cause can be very varied, and depending on the application the lack of the event could even be expected.
|
* autoplay permissions. Bottom line, the cause can be very varied, and depending on the application the lack of the event could even be expected.
|
||||||
*
|
*
|
||||||
* [[ExceptionEvent]] objects with this [[ExceptionEvent.name]] will have as [[ExceptionEvent.origin]] property a [[StreamManager]] object.
|
* [[ExceptionEvent]] objects with this [[ExceptionEvent.name]] will have as [[ExceptionEvent.origin]] property a [[Subscriber]] object.
|
||||||
*/
|
*/
|
||||||
NO_STREAM_PLAYING_EVENT = 'NO_STREAM_PLAYING_EVENT'
|
NO_STREAM_PLAYING_EVENT = 'NO_STREAM_PLAYING_EVENT'
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,8 @@ export enum ExceptionEventName {
|
||||||
/**
|
/**
|
||||||
* Defines event `exception` dispatched by [[Session]] object.
|
* Defines event `exception` dispatched by [[Session]] object.
|
||||||
*
|
*
|
||||||
* This event acts as a global handler for asynchronous errors that may be triggered for multiple reasons and from multiple origins.
|
* This event acts as a global handler for asynchronous errors that may be triggered for multiple reasons and from multiple origins. To see the different
|
||||||
|
* types of exceptions go to [[ExceptionEventName]].
|
||||||
*/
|
*/
|
||||||
export class ExceptionEvent extends Event {
|
export class ExceptionEvent extends Event {
|
||||||
|
|
||||||
|
@ -99,9 +100,9 @@ export class ExceptionEvent extends Event {
|
||||||
* Object affected by the exception. Depending on the [[ExceptionEvent.name]] property:
|
* Object affected by the exception. Depending on the [[ExceptionEvent.name]] property:
|
||||||
* - [[Session]]: `ICE_CANDIDATE_ERROR`
|
* - [[Session]]: `ICE_CANDIDATE_ERROR`
|
||||||
* - [[Stream]]: `ICE_CONNECTION_FAILED`, `ICE_CONNECTION_DISCONNECTED`
|
* - [[Stream]]: `ICE_CONNECTION_FAILED`, `ICE_CONNECTION_DISCONNECTED`
|
||||||
* - [[StreamManager]]: `NO_STREAM_PLAYING_EVENT`
|
* - [[Subscriber]]: `NO_STREAM_PLAYING_EVENT`
|
||||||
*/
|
*/
|
||||||
origin: Session | Stream | StreamManager;
|
origin: Session | Stream | Subscriber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Informative description of the exception
|
* Informative description of the exception
|
||||||
|
@ -116,7 +117,7 @@ export class ExceptionEvent extends Event {
|
||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
constructor(session: Session, name: ExceptionEventName, origin: Session | Stream | StreamManager, message: string, data?: any) {
|
constructor(session: Session, name: ExceptionEventName, origin: Session | Stream | Subscriber, message: string, data?: any) {
|
||||||
super(false, session, 'exception');
|
super(false, session, 'exception');
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
|
|
Loading…
Reference in New Issue