mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: throw OPENVIDU_NOT_CONNECTED when Session.connect not called
parent
317b388088
commit
2cef860128
|
@ -15,7 +15,8 @@ module.exports = {
|
|||
"**/OpenViduInternal/WebRtcStats/WebRtcStats.ts",
|
||||
"**/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts",
|
||||
"**/OpenViduInternal/ScreenSharing/**",
|
||||
"**/OpenViduInternal/KurentoUtils/**"
|
||||
"**/OpenViduInternal/KurentoUtils/**",
|
||||
"**/OpenViduInternal/Logger/**",
|
||||
],
|
||||
excludeExternals: true,
|
||||
excludePrivate: true,
|
||||
|
|
|
@ -272,13 +272,20 @@ export class Session extends EventDispatcher {
|
|||
};
|
||||
}
|
||||
|
||||
let completionHandler: (error: Error | undefined) => void;
|
||||
let completionHandler: ((error: Error | undefined) => void) | undefined = undefined;
|
||||
if (!!param3 && (typeof param3 === 'function')) {
|
||||
completionHandler = param3;
|
||||
} else if (!!param4) {
|
||||
completionHandler = param4;
|
||||
}
|
||||
|
||||
if (!this.sessionConnected()) {
|
||||
if (completionHandler !== undefined) {
|
||||
completionHandler(this.notConnectedError());
|
||||
}
|
||||
throw this.notConnectedError();
|
||||
}
|
||||
|
||||
logger.info('Subscribing to ' + stream.connection.connectionId);
|
||||
|
||||
stream.subscribe()
|
||||
|
@ -310,6 +317,10 @@ export class Session extends EventDispatcher {
|
|||
subscribeAsync(stream: Stream, targetElement: string | HTMLElement, properties?: SubscriberProperties): Promise<Subscriber> {
|
||||
return new Promise<Subscriber>((resolve, reject) => {
|
||||
|
||||
if (!this.sessionConnected()) {
|
||||
reject(this.notConnectedError());
|
||||
}
|
||||
|
||||
let subscriber: Subscriber;
|
||||
|
||||
const callback = (error: Error) => {
|
||||
|
@ -341,6 +352,11 @@ export class Session extends EventDispatcher {
|
|||
* See [[VideoElementEvent]] to learn more
|
||||
*/
|
||||
unsubscribe(subscriber: Subscriber): void {
|
||||
|
||||
if (!this.sessionConnected()) {
|
||||
throw this.notConnectedError()
|
||||
}
|
||||
|
||||
const connectionId = subscriber.stream.connection.connectionId;
|
||||
|
||||
logger.info('Unsubscribing from ' + connectionId);
|
||||
|
@ -377,6 +393,11 @@ export class Session extends EventDispatcher {
|
|||
*/
|
||||
publish(publisher: Publisher): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (!this.sessionConnected()) {
|
||||
reject(this.notConnectedError());
|
||||
}
|
||||
|
||||
publisher.session = this;
|
||||
publisher.stream.session = this;
|
||||
|
||||
|
@ -434,6 +455,10 @@ export class Session extends EventDispatcher {
|
|||
*/
|
||||
unpublish(publisher: Publisher): void {
|
||||
|
||||
if (!this.sessionConnected()) {
|
||||
throw this.notConnectedError()
|
||||
}
|
||||
|
||||
const stream = publisher.stream;
|
||||
|
||||
if (!stream.connection) {
|
||||
|
@ -484,6 +509,11 @@ export class Session extends EventDispatcher {
|
|||
*/
|
||||
forceDisconnect(connection: Connection): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (!this.sessionConnected()) {
|
||||
reject(this.notConnectedError());
|
||||
}
|
||||
|
||||
logger.info('Forcing disconnect for connection ' + connection.connectionId);
|
||||
this.openvidu.sendRequest(
|
||||
'forceDisconnect',
|
||||
|
@ -523,6 +553,11 @@ export class Session extends EventDispatcher {
|
|||
*/
|
||||
forceUnpublish(stream: Stream): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (!this.sessionConnected()) {
|
||||
reject(this.notConnectedError());
|
||||
}
|
||||
|
||||
logger.info('Forcing unpublish for stream ' + stream.streamId);
|
||||
this.openvidu.sendRequest(
|
||||
'forceUnpublish',
|
||||
|
@ -560,6 +595,10 @@ export class Session extends EventDispatcher {
|
|||
signal(signal: SignalOptions): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (!this.sessionConnected()) {
|
||||
reject(this.notConnectedError());
|
||||
}
|
||||
|
||||
const signalMessage = {};
|
||||
|
||||
if (signal.to && signal.to.length > 0) {
|
||||
|
@ -1144,6 +1183,9 @@ export class Session extends EventDispatcher {
|
|||
return joinParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
sendVideoData(streamManager: StreamManager, intervalSeconds: number = 1, doInterval: boolean = false, maxLoops: number = 1) {
|
||||
if (
|
||||
platform.isChromeBrowser() || platform.isChromeMobileBrowser() || platform.isOperaBrowser() ||
|
||||
|
@ -1205,6 +1247,20 @@ export class Session extends EventDispatcher {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
sessionConnected() {
|
||||
return this.connection != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
notConnectedError(): OpenViduError {
|
||||
return new OpenViduError(OpenViduErrorName.OPENVIDU_NOT_CONNECTED, "There is no connection to the session. Method 'Session.connect' must be successfully completed first");
|
||||
}
|
||||
|
||||
/* Private methods */
|
||||
|
||||
private connectAux(token: string): Promise<void> {
|
||||
|
|
|
@ -308,6 +308,11 @@ export class Stream extends EventDispatcher {
|
|||
*/
|
||||
applyFilter(type: string, options: Object): Promise<Filter> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (!this.session.sessionConnected()) {
|
||||
reject(this.session.notConnectedError());
|
||||
}
|
||||
|
||||
logger.info('Applying filter to stream ' + this.streamId);
|
||||
options = !!options ? options : {};
|
||||
if (typeof options !== 'string') {
|
||||
|
@ -345,6 +350,11 @@ export class Stream extends EventDispatcher {
|
|||
*/
|
||||
removeFilter(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (!this.session.sessionConnected()) {
|
||||
reject(this.session.notConnectedError());
|
||||
}
|
||||
|
||||
logger.info('Removing filter of stream ' + this.streamId);
|
||||
this.session.openvidu.sendRequest(
|
||||
'removeFilter',
|
||||
|
|
Loading…
Reference in New Issue