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/WebRtcStats/WebRtcStats.ts",
|
||||||
"**/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts",
|
"**/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts",
|
||||||
"**/OpenViduInternal/ScreenSharing/**",
|
"**/OpenViduInternal/ScreenSharing/**",
|
||||||
"**/OpenViduInternal/KurentoUtils/**"
|
"**/OpenViduInternal/KurentoUtils/**",
|
||||||
|
"**/OpenViduInternal/Logger/**",
|
||||||
],
|
],
|
||||||
excludeExternals: true,
|
excludeExternals: true,
|
||||||
excludePrivate: 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')) {
|
if (!!param3 && (typeof param3 === 'function')) {
|
||||||
completionHandler = param3;
|
completionHandler = param3;
|
||||||
} else if (!!param4) {
|
} else if (!!param4) {
|
||||||
completionHandler = param4;
|
completionHandler = param4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.sessionConnected()) {
|
||||||
|
if (completionHandler !== undefined) {
|
||||||
|
completionHandler(this.notConnectedError());
|
||||||
|
}
|
||||||
|
throw this.notConnectedError();
|
||||||
|
}
|
||||||
|
|
||||||
logger.info('Subscribing to ' + stream.connection.connectionId);
|
logger.info('Subscribing to ' + stream.connection.connectionId);
|
||||||
|
|
||||||
stream.subscribe()
|
stream.subscribe()
|
||||||
|
@ -310,6 +317,10 @@ export class Session extends EventDispatcher {
|
||||||
subscribeAsync(stream: Stream, targetElement: string | HTMLElement, properties?: SubscriberProperties): Promise<Subscriber> {
|
subscribeAsync(stream: Stream, targetElement: string | HTMLElement, properties?: SubscriberProperties): Promise<Subscriber> {
|
||||||
return new Promise<Subscriber>((resolve, reject) => {
|
return new Promise<Subscriber>((resolve, reject) => {
|
||||||
|
|
||||||
|
if (!this.sessionConnected()) {
|
||||||
|
reject(this.notConnectedError());
|
||||||
|
}
|
||||||
|
|
||||||
let subscriber: Subscriber;
|
let subscriber: Subscriber;
|
||||||
|
|
||||||
const callback = (error: Error) => {
|
const callback = (error: Error) => {
|
||||||
|
@ -341,6 +352,11 @@ export class Session extends EventDispatcher {
|
||||||
* See [[VideoElementEvent]] to learn more
|
* See [[VideoElementEvent]] to learn more
|
||||||
*/
|
*/
|
||||||
unsubscribe(subscriber: Subscriber): void {
|
unsubscribe(subscriber: Subscriber): void {
|
||||||
|
|
||||||
|
if (!this.sessionConnected()) {
|
||||||
|
throw this.notConnectedError()
|
||||||
|
}
|
||||||
|
|
||||||
const connectionId = subscriber.stream.connection.connectionId;
|
const connectionId = subscriber.stream.connection.connectionId;
|
||||||
|
|
||||||
logger.info('Unsubscribing from ' + connectionId);
|
logger.info('Unsubscribing from ' + connectionId);
|
||||||
|
@ -377,6 +393,11 @@ export class Session extends EventDispatcher {
|
||||||
*/
|
*/
|
||||||
publish(publisher: Publisher): Promise<void> {
|
publish(publisher: Publisher): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
if (!this.sessionConnected()) {
|
||||||
|
reject(this.notConnectedError());
|
||||||
|
}
|
||||||
|
|
||||||
publisher.session = this;
|
publisher.session = this;
|
||||||
publisher.stream.session = this;
|
publisher.stream.session = this;
|
||||||
|
|
||||||
|
@ -434,6 +455,10 @@ export class Session extends EventDispatcher {
|
||||||
*/
|
*/
|
||||||
unpublish(publisher: Publisher): void {
|
unpublish(publisher: Publisher): void {
|
||||||
|
|
||||||
|
if (!this.sessionConnected()) {
|
||||||
|
throw this.notConnectedError()
|
||||||
|
}
|
||||||
|
|
||||||
const stream = publisher.stream;
|
const stream = publisher.stream;
|
||||||
|
|
||||||
if (!stream.connection) {
|
if (!stream.connection) {
|
||||||
|
@ -484,6 +509,11 @@ export class Session extends EventDispatcher {
|
||||||
*/
|
*/
|
||||||
forceDisconnect(connection: Connection): Promise<void> {
|
forceDisconnect(connection: Connection): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
if (!this.sessionConnected()) {
|
||||||
|
reject(this.notConnectedError());
|
||||||
|
}
|
||||||
|
|
||||||
logger.info('Forcing disconnect for connection ' + connection.connectionId);
|
logger.info('Forcing disconnect for connection ' + connection.connectionId);
|
||||||
this.openvidu.sendRequest(
|
this.openvidu.sendRequest(
|
||||||
'forceDisconnect',
|
'forceDisconnect',
|
||||||
|
@ -523,6 +553,11 @@ export class Session extends EventDispatcher {
|
||||||
*/
|
*/
|
||||||
forceUnpublish(stream: Stream): Promise<void> {
|
forceUnpublish(stream: Stream): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
if (!this.sessionConnected()) {
|
||||||
|
reject(this.notConnectedError());
|
||||||
|
}
|
||||||
|
|
||||||
logger.info('Forcing unpublish for stream ' + stream.streamId);
|
logger.info('Forcing unpublish for stream ' + stream.streamId);
|
||||||
this.openvidu.sendRequest(
|
this.openvidu.sendRequest(
|
||||||
'forceUnpublish',
|
'forceUnpublish',
|
||||||
|
@ -560,6 +595,10 @@ export class Session extends EventDispatcher {
|
||||||
signal(signal: SignalOptions): Promise<void> {
|
signal(signal: SignalOptions): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
if (!this.sessionConnected()) {
|
||||||
|
reject(this.notConnectedError());
|
||||||
|
}
|
||||||
|
|
||||||
const signalMessage = {};
|
const signalMessage = {};
|
||||||
|
|
||||||
if (signal.to && signal.to.length > 0) {
|
if (signal.to && signal.to.length > 0) {
|
||||||
|
@ -1144,6 +1183,9 @@ export class Session extends EventDispatcher {
|
||||||
return joinParams;
|
return joinParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hidden
|
||||||
|
*/
|
||||||
sendVideoData(streamManager: StreamManager, intervalSeconds: number = 1, doInterval: boolean = false, maxLoops: number = 1) {
|
sendVideoData(streamManager: StreamManager, intervalSeconds: number = 1, doInterval: boolean = false, maxLoops: number = 1) {
|
||||||
if (
|
if (
|
||||||
platform.isChromeBrowser() || platform.isChromeMobileBrowser() || platform.isOperaBrowser() ||
|
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 methods */
|
||||||
|
|
||||||
private connectAux(token: string): Promise<void> {
|
private connectAux(token: string): Promise<void> {
|
||||||
|
|
|
@ -308,6 +308,11 @@ export class Stream extends EventDispatcher {
|
||||||
*/
|
*/
|
||||||
applyFilter(type: string, options: Object): Promise<Filter> {
|
applyFilter(type: string, options: Object): Promise<Filter> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
if (!this.session.sessionConnected()) {
|
||||||
|
reject(this.session.notConnectedError());
|
||||||
|
}
|
||||||
|
|
||||||
logger.info('Applying filter to stream ' + this.streamId);
|
logger.info('Applying filter to stream ' + this.streamId);
|
||||||
options = !!options ? options : {};
|
options = !!options ? options : {};
|
||||||
if (typeof options !== 'string') {
|
if (typeof options !== 'string') {
|
||||||
|
@ -345,6 +350,11 @@ export class Stream extends EventDispatcher {
|
||||||
*/
|
*/
|
||||||
removeFilter(): Promise<void> {
|
removeFilter(): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
if (!this.session.sessionConnected()) {
|
||||||
|
reject(this.session.notConnectedError());
|
||||||
|
}
|
||||||
|
|
||||||
logger.info('Removing filter of stream ' + this.streamId);
|
logger.info('Removing filter of stream ' + this.streamId);
|
||||||
this.session.openvidu.sendRequest(
|
this.session.openvidu.sendRequest(
|
||||||
'removeFilter',
|
'removeFilter',
|
||||||
|
|
Loading…
Reference in New Issue