mirror of https://github.com/OpenVidu/openvidu.git
stream-added stream-removed updated to streamCreated streamDestroyed
parent
12fdd21315
commit
fe11c04f69
16
README.md
16
README.md
|
@ -155,23 +155,23 @@ For secret "MY_SECRET", the final header would be
|
||||||
> Authorization:Basic T1BFTlZJRFVBUFA6TVlfU0VDUkVU
|
> Authorization:Basic T1BFTlZJRFVBUFA6TVlfU0VDUkVU
|
||||||
|
|
||||||
|
|
||||||
| _GET A SESSION ID_ | _PARAMETERS_ |
|
| _NEW SESSIONID_ | _PARAMETERS_ |
|
||||||
| --------- | -- |
|
| --------- | -- |
|
||||||
| **Operation** | POST |
|
| **Operation** | POST |
|
||||||
| **URL** | https://[YOUR_OPENVIDUSERVER_IP]/sessions |
|
| **URL** | https://[YOUR_OPENVIDUSERVER_IP]/api/sessions |
|
||||||
| **Headers** | Authorization:Basic _EncodeBase64(OPENVIDUAPP:[YOUR_SECRET])_ |
|
| **Headers** | Authorization:Basic _EncodeBase64(OPENVIDUAPP:[YOUR_SECRET])_ |
|
||||||
| **Returns** | {"id": "SESSIONID"} |
|
| **Returns** | {"id": "SESSIONID"} |
|
||||||
|
|
||||||
| _CREATE NEW TOKEN_ | _PARAMETERS_ |
|
| _NEW TOKEN_ | _PARAMETERS_ |
|
||||||
| --------- | -- |
|
| --------- | -- |
|
||||||
| **Operation** | POST |
|
| **Operation** | POST |
|
||||||
| **URL** | https://[YOUR_OPENVIDUSERVER_IP]/tokens |
|
| **URL** | https://[YOUR_OPENVIDUSERVER_IP]/api/tokens |
|
||||||
| **Headers** | Authorization:Basic _EncodeBase64(OPENVIDUAPP:[YOUR_SECRET])_<br/>Content-Type:application/json |
|
| **Headers** | Authorization:Basic _EncodeBase64(OPENVIDUAPP:[YOUR_SECRET])_<br/>Content-Type:application/json |
|
||||||
| **Body** | {"session": "SESSIONID", "role": "ROLE", "data": "DATA"} |
|
| **Body** | {"session": "SESSIONID", "role": "ROLE", "data": "DATA"} |
|
||||||
| **Returns** | {"token": "TOKEN", "session": "SESSIONID", "role": "ROLE", "data": "DATA", "id": "TOKEN"} |
|
| **Returns** | {"token": "TOKEN", "session": "SESSIONID", "role": "ROLE", "data": "DATA", "id": "TOKEN"} |
|
||||||
|
|
||||||
|
|
||||||
> **ROLE** value in Body field of POST to "/newToken" can be:
|
> **ROLE** value in Body field of POST to "/api/tokens" can be:
|
||||||
>
|
>
|
||||||
> - SUBSCRIBER
|
> - SUBSCRIBER
|
||||||
> - PUBLISHER
|
> - PUBLISHER
|
||||||
|
@ -273,13 +273,13 @@ Whatever app you are developing, chances are you will need to pass some data for
|
||||||
session.connect(token, DATA, function (error) { ... });
|
session.connect(token, DATA, function (error) { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- **API REST**: when asking for a token to */newToken*, you can pass data as third parameter in the BODY of the POST request
|
- **API REST**: when asking for a token to */api/tokens*, you can pass data as third parameter in the BODY of the POST request
|
||||||
```
|
```
|
||||||
{“session”: “sessionId”, “role”: “role”, “data”: "DATA"}
|
{“session”: “sessionId”, “role”: “role”, “data”: "DATA"}
|
||||||
```
|
```
|
||||||
|
|
||||||
> **openvidu-backend-client** allows you to pass data when creating a Token object: </br>
|
> Java and Node clients (_openvidu-java-client_ and _openvidu-node-client_) allow you to pass data when creating a Token object: </br>
|
||||||
> `Token t = new TokenOptions.Builder().data("DATA").build();`
|
> `tokenOptions = new TokenOptions.Builder().data("DATA").build();`
|
||||||
|
|
||||||
The result will be that in all clients, *Connection* objects will have in their *data* property the pertinent value you have provided for each user. So, an easy way to get the data associated to any user would be:
|
The result will be that in all clients, *Connection* objects will have in their *data* property the pertinent value you have provided for each user. So, an easy way to get the data associated to any user would be:
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -20,7 +20,7 @@ export class Session {
|
||||||
this.sessionId = session.getSessionId();
|
this.sessionId = session.getSessionId();
|
||||||
|
|
||||||
// Listens to the deactivation of the default behaviour upon the deletion of a Stream object
|
// Listens to the deactivation of the default behaviour upon the deletion of a Stream object
|
||||||
this.session.addEventListener('stream-removed-default', event => {
|
this.session.addEventListener('stream-destroyed-default', event => {
|
||||||
event.stream.removeVideo();
|
event.stream.removeVideo();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -85,62 +85,19 @@ export class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
on(eventName: string, callback) {
|
on(eventName: string, callback) {
|
||||||
let realEventName = '';
|
this.session.addEventListener(eventName, event => {
|
||||||
switch (eventName) {
|
callback(event);
|
||||||
case 'streamCreated':
|
});
|
||||||
realEventName = 'stream-added';
|
|
||||||
break;
|
|
||||||
case 'streamDestroyed':
|
|
||||||
realEventName = 'stream-removed';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (realEventName != '') {
|
|
||||||
this.session.addEventListener(realEventName, event => {
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.session.addEventListener(eventName, event => {
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
once(eventName: string, callback) {
|
once(eventName: string, callback) {
|
||||||
let realEventName = '';
|
this.session.addOnceEventListener(eventName, event => {
|
||||||
switch (eventName) {
|
callback(event);
|
||||||
case 'streamCreated':
|
});
|
||||||
realEventName = 'stream-added';
|
|
||||||
break;
|
|
||||||
case 'streamDestroyed':
|
|
||||||
realEventName = 'stream-removed';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (realEventName != '') {
|
|
||||||
this.session.addOnceEventListener(realEventName, event => {
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.session.addOnceEventListener(eventName, event => {
|
|
||||||
callback(event);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
off(eventName: string, eventHandler) {
|
off(eventName: string, eventHandler) {
|
||||||
let realEventName = '';
|
this.session.removeListener(eventName, eventHandler);
|
||||||
switch (eventName) {
|
|
||||||
case 'streamCreated':
|
|
||||||
realEventName = 'stream-added';
|
|
||||||
break;
|
|
||||||
case 'streamDestroyed':
|
|
||||||
realEventName = 'stream-removed';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (realEventName != '') {
|
|
||||||
this.session.removeListener(realEventName, eventHandler);
|
|
||||||
} else {
|
|
||||||
this.session.removeListener(eventName, eventHandler);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe(stream: Stream, htmlId: string, videoOptions: any): Subscriber;
|
subscribe(stream: Stream, htmlId: string, videoOptions: any): Subscriber;
|
||||||
|
@ -165,13 +122,13 @@ export class Session {
|
||||||
/* Shortcut event API */
|
/* Shortcut event API */
|
||||||
|
|
||||||
onStreamCreated(callback) {
|
onStreamCreated(callback) {
|
||||||
this.session.addEventListener("stream-added", streamEvent => {
|
this.session.addEventListener("streamCreated", streamEvent => {
|
||||||
callback(streamEvent.stream);
|
callback(streamEvent.stream);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onStreamDestroyed(callback) {
|
onStreamDestroyed(callback) {
|
||||||
this.session.addEventListener("stream-removed", streamEvent => {
|
this.session.addEventListener("streamDestroyed", streamEvent => {
|
||||||
callback(streamEvent.stream);
|
callback(streamEvent.stream);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ export class SessionInternal {
|
||||||
|
|
||||||
//if (this.subscribeToStreams) {
|
//if (this.subscribeToStreams) {
|
||||||
for (let stream of roomEvent.streams) {
|
for (let stream of roomEvent.streams) {
|
||||||
this.ee.emitEvent('stream-added', [{ stream }]);
|
this.ee.emitEvent('streamCreated', [{ stream }]);
|
||||||
|
|
||||||
// Adding the remote stream to the OpenVidu object
|
// Adding the remote stream to the OpenVidu object
|
||||||
this.openVidu.getRemoteStreams().push(stream);
|
this.openVidu.getRemoteStreams().push(stream);
|
||||||
|
@ -229,7 +229,7 @@ export class SessionInternal {
|
||||||
if (this.subscribeToStreams) {
|
if (this.subscribeToStreams) {
|
||||||
stream.subscribe();
|
stream.subscribe();
|
||||||
}
|
}
|
||||||
this.ee.emitEvent('stream-added', [{ stream }]);
|
this.ee.emitEvent('streamCreated', [{ stream }]);
|
||||||
// Adding the remote stream to the OpenVidu object
|
// Adding the remote stream to the OpenVidu object
|
||||||
this.openVidu.getRemoteStreams().push(stream);
|
this.openVidu.getRemoteStreams().push(stream);
|
||||||
}
|
}
|
||||||
|
@ -274,11 +274,11 @@ export class SessionInternal {
|
||||||
|
|
||||||
let streams = connection.getStreams();
|
let streams = connection.getStreams();
|
||||||
for (let key in streams) {
|
for (let key in streams) {
|
||||||
this.ee.emitEvent('stream-removed', [{
|
this.ee.emitEvent('streamDestroyed', [{
|
||||||
stream: streams[key],
|
stream: streams[key],
|
||||||
preventDefault: () => { this.ee.removeEvent('stream-removed-default'); }
|
preventDefault: () => { this.ee.removeEvent('stream-destroyed-default'); }
|
||||||
}]);
|
}]);
|
||||||
this.ee.emitEvent('stream-removed-default', [{
|
this.ee.emitEvent('stream-destroyed-default', [{
|
||||||
stream: streams[key]
|
stream: streams[key]
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue