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
|
||||
|
||||
|
||||
| _GET A SESSION ID_ | _PARAMETERS_ |
|
||||
| _NEW SESSIONID_ | _PARAMETERS_ |
|
||||
| --------- | -- |
|
||||
| **Operation** | POST |
|
||||
| **URL** | https://[YOUR_OPENVIDUSERVER_IP]/sessions |
|
||||
| **URL** | https://[YOUR_OPENVIDUSERVER_IP]/api/sessions |
|
||||
| **Headers** | Authorization:Basic _EncodeBase64(OPENVIDUAPP:[YOUR_SECRET])_ |
|
||||
| **Returns** | {"id": "SESSIONID"} |
|
||||
|
||||
| _CREATE NEW TOKEN_ | _PARAMETERS_ |
|
||||
| _NEW TOKEN_ | _PARAMETERS_ |
|
||||
| --------- | -- |
|
||||
| **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 |
|
||||
| **Body** | {"session": "SESSIONID", "role": "ROLE", "data": "DATA"} |
|
||||
| **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
|
||||
> - 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) { ... });
|
||||
```
|
||||
|
||||
- **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"}
|
||||
```
|
||||
|
||||
> **openvidu-backend-client** allows you to pass data when creating a Token object: </br>
|
||||
> `Token t = new TokenOptions.Builder().data("DATA").build();`
|
||||
> Java and Node clients (_openvidu-java-client_ and _openvidu-node-client_) allow you to pass data when creating a Token object: </br>
|
||||
> `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:
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -20,7 +20,7 @@ export class Session {
|
|||
this.sessionId = session.getSessionId();
|
||||
|
||||
// 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();
|
||||
});
|
||||
|
||||
|
@ -85,63 +85,20 @@ export class Session {
|
|||
}
|
||||
|
||||
on(eventName: string, callback) {
|
||||
let realEventName = '';
|
||||
switch (eventName) {
|
||||
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) {
|
||||
let realEventName = '';
|
||||
switch (eventName) {
|
||||
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) {
|
||||
let realEventName = '';
|
||||
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): Subscriber;
|
||||
|
@ -165,13 +122,13 @@ export class Session {
|
|||
/* Shortcut event API */
|
||||
|
||||
onStreamCreated(callback) {
|
||||
this.session.addEventListener("stream-added", streamEvent => {
|
||||
this.session.addEventListener("streamCreated", streamEvent => {
|
||||
callback(streamEvent.stream);
|
||||
});
|
||||
}
|
||||
|
||||
onStreamDestroyed(callback) {
|
||||
this.session.addEventListener("stream-removed", streamEvent => {
|
||||
this.session.addEventListener("streamDestroyed", streamEvent => {
|
||||
callback(streamEvent.stream);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ export class SessionInternal {
|
|||
|
||||
//if (this.subscribeToStreams) {
|
||||
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
|
||||
this.openVidu.getRemoteStreams().push(stream);
|
||||
|
@ -229,7 +229,7 @@ export class SessionInternal {
|
|||
if (this.subscribeToStreams) {
|
||||
stream.subscribe();
|
||||
}
|
||||
this.ee.emitEvent('stream-added', [{ stream }]);
|
||||
this.ee.emitEvent('streamCreated', [{ stream }]);
|
||||
// Adding the remote stream to the OpenVidu object
|
||||
this.openVidu.getRemoteStreams().push(stream);
|
||||
}
|
||||
|
@ -274,11 +274,11 @@ export class SessionInternal {
|
|||
|
||||
let streams = connection.getStreams();
|
||||
for (let key in streams) {
|
||||
this.ee.emitEvent('stream-removed', [{
|
||||
this.ee.emitEvent('streamDestroyed', [{
|
||||
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]
|
||||
}]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue