Skip to content

Commit

Permalink
stream-added stream-removed updated to streamCreated streamDestroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Jun 13, 2017
1 parent 12fdd21 commit fe11c04
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 128 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:

Expand Down
78 changes: 16 additions & 62 deletions openvidu-browser/src/main/resources/static/js/OpenVidu.js

Large diffs are not rendered by default.

63 changes: 10 additions & 53 deletions openvidu-browser/src/main/resources/ts/OpenVidu/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down Expand Up @@ -85,62 +85,19 @@ 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);
});
}
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);
});
}
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);
}
this.session.removeListener(eventName, eventHandler);
}

subscribe(stream: Stream, htmlId: string, videoOptions: any): Subscriber;
Expand All @@ -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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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]
}]);

Expand Down

0 comments on commit fe11c04

Please sign in to comment.