diff --git a/openvidu-browser/src/OpenVidu/Connection.ts b/openvidu-browser/src/OpenVidu/Connection.ts index 6c13c9ba..72ad4e32 100644 --- a/openvidu-browser/src/OpenVidu/Connection.ts +++ b/openvidu-browser/src/OpenVidu/Connection.ts @@ -51,6 +51,23 @@ export class Connection { */ data: string; + /** + * Role of the connection. + * - `SUBSCRIBER`: can subscribe to published Streams of other users by calling [[Session.subscribe]] + * - `PUBLISHER`: SUBSCRIBER permissions + can publish their own Streams by calling [[Session.publish]] + * - `MODERATOR`: SUBSCRIBER + PUBLISHER permissions + can force the unpublishing or disconnection over a third-party Stream or Connection by call [[Session.forceUnpublish]] and [[Session.forceDisconnect]] + * + * **Only defined for the local connection. In remote connections will be `undefined`** + */ + role: string; + + /** + * Whether the streams published by this connection will be recorded or not. This only affects [INDIVIDUAL recording](/en/stable/advanced-features/recording#selecting-streams-to-be-recorded) PRO + * + * **Only defined for the local connection. In remote connections will be `undefined`** + */ + record: boolean; + /** * @hidden */ @@ -88,6 +105,8 @@ export class Connection { this.creationTime = this.localOptions.createdAt; this.data = this.localOptions.metadata; this.rpcSessionId = this.localOptions.sessionId; + this.role = this.localOptions.role; + this.record = this.localOptions.record; msg += '(local)'; } else { // Connection is remote diff --git a/openvidu-browser/src/OpenVidu/OpenVidu.ts b/openvidu-browser/src/OpenVidu/OpenVidu.ts index 3b5d80c1..d4f01140 100644 --- a/openvidu-browser/src/OpenVidu/OpenVidu.ts +++ b/openvidu-browser/src/OpenVidu/OpenVidu.ts @@ -759,6 +759,7 @@ export class OpenVidu { recordingStopped: this.session.onRecordingStopped.bind(this.session), sendMessage: this.session.onNewMessage.bind(this.session), streamPropertyChanged: this.session.onStreamPropertyChanged.bind(this.session), + connectionPropertyChanged: this.session.onConnectionPropertyChanged.bind(this.session), networkQualityLevelChanged: this.session.onNetworkQualityLevelChangedChanged.bind(this.session), filterEventDispatched: this.session.onFilterEventDispatched.bind(this.session), iceCandidate: this.session.recvIceCandidate.bind(this.session), diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index dc09d650..450213f2 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -38,6 +38,7 @@ import { SessionDisconnectedEvent } from '../OpenViduInternal/Events/SessionDisc import { SignalEvent } from '../OpenViduInternal/Events/SignalEvent'; import { StreamEvent } from '../OpenViduInternal/Events/StreamEvent'; import { StreamPropertyChangedEvent } from '../OpenViduInternal/Events/StreamPropertyChangedEvent'; +import { ConnectionPropertyChangedEvent } from '../OpenViduInternal/Events/ConnectionPropertyChangedEvent'; import { NetworkQualityLevelChangedEvent } from '../OpenViduInternal/Events/NetworkQualityLevelChangedEvent'; import { OpenViduError, OpenViduErrorName } from '../OpenViduInternal/Enums/OpenViduError'; import { VideoInsertMode } from '../OpenViduInternal/Enums/VideoInsertMode'; @@ -63,6 +64,7 @@ const platform: PlatformUtils = PlatformUtils.getInstance(); * * - connectionCreated ([[ConnectionEvent]]) * - connectionDestroyed ([[ConnectionEvent]]) + * - connectionPropertyChanged ([[ConnectionPropertyChangedEvent]]) PRO * - sessionDisconnected ([[SessionDisconnectedEvent]]) * - streamCreated ([[StreamEvent]]) * - streamDestroyed ([[StreamEvent]]) @@ -95,7 +97,7 @@ export class Session extends 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. + * Object defining the methods that the client is able to call. These are defined by the [[Connection.role]]. * This object is only defined after [[Session.connect]] has been successfully resolved */ capabilities: Capabilities; @@ -930,6 +932,26 @@ export class Session extends EventDispatcher { } } + /** + * @hidden + */ + onConnectionPropertyChanged(msg): void { + let oldValue; + switch (msg.property) { + case 'role': + oldValue = this.connection.role.slice(); + this.connection.role = msg.newValue; + this.connection.localOptions!.role = msg.newValue; + break; + case 'record': + oldValue = this.connection.record; + msg.newValue = msg.newValue === 'true'; + this.connection.record = msg.newValue; + this.connection.localOptions!.record = msg.newValue; + break; + } + this.ee.emitEvent('connectionPropertyChanged', [new ConnectionPropertyChangedEvent(this, this.connection, msg.property, msg.newValue, oldValue)]); + } /** * @hidden diff --git a/openvidu-browser/src/OpenViduInternal/Events/ConnectionPropertyChangedEvent.ts b/openvidu-browser/src/OpenViduInternal/Events/ConnectionPropertyChangedEvent.ts new file mode 100644 index 00000000..2747925e --- /dev/null +++ b/openvidu-browser/src/OpenViduInternal/Events/ConnectionPropertyChangedEvent.ts @@ -0,0 +1,74 @@ +/* + * (C) Copyright 2017-2020 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. + * + */ + +import { Connection } from '../../OpenVidu/Connection'; +import { Session } from '../../OpenVidu/Session'; +import { Event } from './Event'; + +/** + * **This feature is part of OpenVidu Pro tier** PRO + * + * Defines event `connectionPropertyChanged` dispatched by [[Session]] object. + * This event is fired when any property of the local [[Connection]] object changes. + * The properties that may change are [[Connection.role]] and [[Connection.record]]. + * + * The only way the Connection properties may change is by updating them through: + * + * - [API REST](/en/stable/reference-docs/REST-API/#patch-openviduapisessionsltsession_idgtconnectionltconnection_idgt) + * - [openvidu-java-client](/en/stable/reference-docs/openvidu-java-client/#update-a-connection) + * - [openvidu-node-client](/en/stable/reference-docs/openvidu-node-client/#update-a-connection)

+ */ +export class ConnectionPropertyChangedEvent extends Event { + + /** + * The Connection whose property has changed + */ + connection: Connection; + + /** + * The property of the stream that changed. This value is either `"role"` or `"record"` + */ + changedProperty: string; + + /** + * New value of the property (after change, current value) + */ + newValue: Object; + + /** + * Previous value of the property (before change) + */ + oldValue: Object; + + /** + * @hidden + */ + constructor(target: Session, connection: Connection, changedProperty: string, newValue: Object, oldValue: Object) { + super(false, target, 'connectionPropertyChanged'); + this.connection = connection; + this.changedProperty = changedProperty; + this.newValue = newValue; + this.oldValue = oldValue; + } + + /** + * @hidden + */ + // tslint:disable-next-line:no-empty + callDefaultBehavior() { } + +} \ No newline at end of file diff --git a/openvidu-browser/src/OpenViduInternal/Events/NetworkQualityLevelChangedEvent.ts b/openvidu-browser/src/OpenViduInternal/Events/NetworkQualityLevelChangedEvent.ts index a9eba26b..0dbfdc95 100644 --- a/openvidu-browser/src/OpenViduInternal/Events/NetworkQualityLevelChangedEvent.ts +++ b/openvidu-browser/src/OpenViduInternal/Events/NetworkQualityLevelChangedEvent.ts @@ -20,8 +20,10 @@ import { Session } from '../../OpenVidu/Session'; import { Connection } from '../../OpenVidu/Connection'; /** + * **This feature is part of OpenVidu Pro tier** PRO + * * Defines event `networkQualityLevelChanged` dispatched by [[Session]]. - * This event is fired when the network quality level of a [[Connection]] changes. + * This event is fired when the network quality level of a [[Connection]] changes. See [network quality](/en/stable/advanced-features/network-quality/) */ export class NetworkQualityLevelChangedEvent extends Event { diff --git a/openvidu-browser/src/OpenViduInternal/Interfaces/Private/LocalConnectionOptions.ts b/openvidu-browser/src/OpenViduInternal/Interfaces/Private/LocalConnectionOptions.ts index 27cbd8be..b53c4940 100644 --- a/openvidu-browser/src/OpenViduInternal/Interfaces/Private/LocalConnectionOptions.ts +++ b/openvidu-browser/src/OpenViduInternal/Interfaces/Private/LocalConnectionOptions.ts @@ -25,6 +25,7 @@ export interface LocalConnectionOptions { session: string; // OpenVidu Session identifier sessionId: string; // JSON-RPC session identifier role: string; + record: boolean; coturnIp: string; turnUsername: string; turnCredential: string; diff --git a/openvidu-browser/src/index.ts b/openvidu-browser/src/index.ts index a2d82dda..8576b022 100644 --- a/openvidu-browser/src/index.ts +++ b/openvidu-browser/src/index.ts @@ -22,6 +22,7 @@ export { StreamEvent } from './OpenViduInternal/Events/StreamEvent'; export { StreamManagerEvent } from './OpenViduInternal/Events/StreamManagerEvent'; export { VideoElementEvent } from './OpenViduInternal/Events/VideoElementEvent'; export { StreamPropertyChangedEvent } from './OpenViduInternal/Events/StreamPropertyChangedEvent'; +export { ConnectionPropertyChangedEvent } from './OpenViduInternal/Events/ConnectionPropertyChangedEvent'; export { FilterEvent } from './OpenViduInternal/Events/FilterEvent'; export { NetworkQualityLevelChangedEvent } from './OpenViduInternal/Events/NetworkQualityLevelChangedEvent'; diff --git a/openvidu-client/src/main/java/io/openvidu/client/internal/ProtocolElements.java b/openvidu-client/src/main/java/io/openvidu/client/internal/ProtocolElements.java index 2d5afd0d..52c6145d 100644 --- a/openvidu-client/src/main/java/io/openvidu/client/internal/ProtocolElements.java +++ b/openvidu-client/src/main/java/io/openvidu/client/internal/ProtocolElements.java @@ -93,6 +93,10 @@ public class ProtocolElements { public static final String STREAMPROPERTYCHANGED_NEWVALUE_PARAM = "newValue"; public static final String STREAMPROPERTYCHANGED_REASON_PARAM = "reason"; + public static final String CONNECTIONPERTYCHANGED_METHOD = "connectionPropertyChanged"; + public static final String CONNECTIONROPERTYCHANGED_PROPERTY_PARAM = "property"; + public static final String CONNECTIONPROPERTYCHANGED_NEWVALUE_PARAM = "newValue"; + public static final String NETWORKQUALITYLEVELCHANGED_METHOD = "networkQualityLevelChanged"; public static final String NETWORKQUALITYCHANGED_CONNECTIONID_PARAM = "connectionId"; public static final String NETWORKQUALITYCHANGED_QUALITYLEVEL_PARAM = "qualityLevel"; @@ -125,7 +129,7 @@ public class ProtocolElements { public static final String RECONNECTSTREAM_METHOD = "reconnectStream"; public static final String RECONNECTSTREAM_STREAM_PARAM = "stream"; public static final String RECONNECTSTREAM_SDPOFFER_PARAM = "sdpOffer"; - + public static final String VIDEODATA_METHOD = "videoData"; // ---------------------------- SERVER RESPONSES & EVENTS ----------------- diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java index b45e9e4f..1682f006 100644 --- a/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java +++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java @@ -463,9 +463,12 @@ public class Session { } /** - * Updates the properties of a Connection with a - * {@link io.openvidu.java.client.ConnectionProperties} object. Only these - * properties can be updated: + * PRO Updates the properties of a Connection with a + * {@link io.openvidu.java.client.ConnectionProperties} object. Only these properties can be updated: *