Skip to content

Commit

Permalink
hardware disconnection event (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
kekkokk authored and jcague committed Apr 19, 2017
1 parent c0edb59 commit 0a0ebb1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
51 changes: 26 additions & 25 deletions doc/client_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ The attributes variable is usually a JSON object.

```
var stream = Erizo.Stream({audio:true, video:false, data: true, attributes: {name:'myStream', type:'public'}});
var attributes = stream.getAttributes();
if(attributes.type === 'public') {
console.log(attributes.name);
Expand Down Expand Up @@ -256,19 +256,19 @@ The client can get the bitmap raw data from the video streams. The Stream return
var bitmap;
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
canvas.id = "testCanvas";
document.body.appendChild(canvas);
setInterval(function() {
bitmap = stream.getVideoFrame();
canvas.width = bitmap.width;
canvas.height = bitmap.height;
context.putImageData(bitmap, 0, 0);
}, 100);
```

Expand All @@ -288,13 +288,13 @@ You can update the maximun bandwidth of video and audio. These values are define

```
var config = {maxVideoBW: 300, maxAudioBW: 300};
localstream.updateConfiguration(config, function(result) {
console.log(result);
});
// We can update options also on a remote stream
remoteStream.updateConfiguration({slideShowMode:true}, function (result){
console.log(result);
});
Expand Down Expand Up @@ -750,6 +750,7 @@ There are the different types of Stream events:
- `streamEvent.bandwidth` is the available bandwidth reported by that stream.
- `streamEvent.msg` the status of that stream, depends on the adaptation [scheme](#schemes).
- *stream-failed*: A stream has failed, either in the connection establishment or during the communication.
- *stream-ended*: A track of the stream (specified in the msg. es.audio/video) is ended, probably caused by an hardware disconnection. Emitted only once

They all are dispatched by Room objects.

Expand All @@ -775,11 +776,11 @@ room.addEventListener("stream-removed", function(evt){...});

```
stream.addEventListener("access-accepted", function(evt){...});
stream.addEventListener("stream-data", function(evt){
console.log('Received data ', evt.msg, 'from stream ', evt.stream.getAttributes().name);
});
room.addEventListener("stream-attributes-update", function(evt){...});
```

Expand All @@ -799,14 +800,14 @@ In this example we will make a basic videoconference application. Every client t
<title>Licode Basic Example</title>
<script type="text/javascript" src="erizo.js"></script>
<script type="text/javascript">
window.onload = function () {
var localStream = Erizo.Stream({audio: true, video: true, data: true});
var room = Erizo.Room({token: "af54/=gopknosdvmgiufhgadf=="});
localStream.addEventListener("access-accepted", function () {
var subscribeToStreams = function (streams) {
for (var index in streams) {
var stream = streams[index];
Expand All @@ -815,29 +816,29 @@ In this example we will make a basic videoconference application. Every client t
}
}
};
room.addEventListener("room-connected", function (roomEvent) {
room.publish(localStream);
subscribeToStreams(roomEvent.streams);
});
room.addEventListener("stream-subscribed", function(streamEvent) {
var stream = streamEvent.stream;
var div = document.createElement('div');
div.setAttribute("style", "width: 320px; height: 240px;");
div.setAttribute("id", "test" + stream.getID());
document.body.appendChild(div);
stream.play("test" + stream.getID());
});
room.addEventListener("stream-added", function (streamEvent) {
var streams = [];
streams.push(streamEvent.stream);
subscribeToStreams(streams);
});
room.addEventListener("stream-removed", function (streamEvent) {
// Remove stream from DOM
var stream = streamEvent.stream;
Expand All @@ -846,15 +847,15 @@ In this example we will make a basic videoconference application. Every client t
document.body.removeChild(element);
}
});
room.connect();
localStream.play("myVideo");
});
localStream.init();
};
</script>
</head>
<body>
<div id="myVideo" style="width:320px; height: 240px;">
</div>
Expand All @@ -879,4 +880,4 @@ You can also use Erizo Client Logger for managing log levels, etc.
```
var L = require('.erizofc').L;
L.Logger.setLogLevel(2);
```
```
12 changes: 12 additions & 0 deletions erizo_controller/erizoClient/src/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ Erizo.Stream = function (spec) {
streamEvent = Erizo.StreamEvent({type: 'access-accepted'});
that.dispatchEvent(streamEvent);

that.stream.getTracks().forEach(function(track) {
track.onended = function() {
that.stream.getTracks().forEach(function(track) {
track.onended = null;
});
streamEvent = Erizo.StreamEvent({type: 'stream-ended', stream: that,
msg: track.kind});
that.dispatchEvent(streamEvent);
};
});

}, function (error) {
L.Logger.error('Failed to get access to local media. Error code was ' +
error.code + '.');
Expand Down Expand Up @@ -153,6 +164,7 @@ Erizo.Stream = function (spec) {
that.hide();
if (that.stream !== undefined) {
that.stream.getTracks().forEach(function (track) {
track.onended = null;
track.stop();
});
}
Expand Down

0 comments on commit 0a0ebb1

Please sign in to comment.