From f8305fce6e5899a24b1f46d96311ea6f77794874 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Wed, 4 Jul 2018 15:04:47 +0200 Subject: [PATCH] openvidu-browser: Session.capabilities property defined --- openvidu-browser/src/OpenVidu/Session.ts | 13 ++++++++ .../Interfaces/Public/Capabilities.ts | 33 +++++++++++++++++++ openvidu-browser/src/index.ts | 1 + 3 files changed, 47 insertions(+) create mode 100644 openvidu-browser/src/OpenViduInternal/Interfaces/Public/Capabilities.ts diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 33d13959..4fd087f9 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -21,6 +21,7 @@ import { Publisher } from './Publisher'; import { Stream } from './Stream'; import { StreamManager } from './StreamManager'; import { Subscriber } from './Subscriber'; +import { Capabilities } from '../OpenViduInternal/Interfaces/Public/Capabilities'; import { EventDispatcher } from '../OpenViduInternal/Interfaces/Public/EventDispatcher'; import { SignalOptions } from '../OpenViduInternal/Interfaces/Public/SignalOptions'; import { SubscriberProperties } from '../OpenViduInternal/Interfaces/Public/SubscriberProperties'; @@ -63,6 +64,12 @@ export class Session implements EventDispatcher { */ streamManagers: StreamManager[] = []; + /** + * Object defining the methods that the client is able to call. These are defined by the role of the token used to connect to the Session. + * This object is only defined after [[Session.connect]] has been successfully resolved + */ + capabilities: Capabilities; + // This map is only used to avoid race condition between 'joinRoom' response and 'onParticipantPublished' notification /** * @hidden @@ -889,6 +896,12 @@ export class Session implements EventDispatcher { reject(error); } else { + // Initialize capabilities object with the role + this.capabilities = { + subscribe: 1, + publish: this.openvidu.role !== 'SUBSCRIBER' ? 1 : 0 + }; + // Initialize local Connection object with values returned by openvidu-server this.connection = new Connection(this); this.connection.connectionId = response.id; diff --git a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/Capabilities.ts b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/Capabilities.ts new file mode 100644 index 00000000..3afac332 --- /dev/null +++ b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/Capabilities.ts @@ -0,0 +1,33 @@ +/* + * (C) Copyright 2017-2018 OpenVidu (https://openvidu.io/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * See [[Session.capabilities]] + */ +export interface Capabilities { + + /** + * 1 if the client can call [[Session.publish]], 0 if not + */ + publish: number; + + /** + * 1 if the client can call [[Session.subscribe]], 0 if not (1 for every user for now) + */ + subscribe: number; + +} \ No newline at end of file diff --git a/openvidu-browser/src/index.ts b/openvidu-browser/src/index.ts index a50c8dcf..d7dac65a 100644 --- a/openvidu-browser/src/index.ts +++ b/openvidu-browser/src/index.ts @@ -22,6 +22,7 @@ export { StreamManagerEvent } from './OpenViduInternal/Events/StreamManagerEvent export { VideoElementEvent } from './OpenViduInternal/Events/VideoElementEvent'; export { StreamPropertyChangedEvent } from './OpenViduInternal/Events/StreamPropertyChangedEvent'; +export { Capabilities } from './OpenViduInternal/Interfaces/Public/Capabilities'; export { Device } from './OpenViduInternal/Interfaces/Public/Device'; export { EventDispatcher } from './OpenViduInternal/Interfaces/Public/EventDispatcher'; export { OpenViduAdvancedConfiguration } from './OpenViduInternal/Interfaces/Public/OpenViduAdvancedConfiguration';