Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSDK-1510 Implementing the Bandwidth Constraints example app. #25

Merged
merged 5 commits into from Sep 22, 2017

Conversation

manjeshbhargav
Copy link
Collaborator

@markandrus

This PR contains the implementation of the Bandwidth Constraints Example.

Screenshot:
screen shot 2017-09-18 at 5 32 05 pm

README.md Outdated
@@ -45,8 +45,10 @@ video in both the tabs!

## Examples

The project contains some common use-case examples for the Twilio Video JS SDK.
The project contains some common use-case examples for the Twilio Video JS SDK. After running the application
by following the instructions above, click on these links to run the examples.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this indicates we ought to find a way to include these links in the app, e.g. a navigation bar or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markandrus I'll add an examples/index.html page linking to all the examples.

if (!canvas) {
waveformContainer.appendChild(waveform.element);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to start factoring this stuff out, otherwise it will get difficult to maintain, IMO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markandrus I've already moved Waveform to the utils folder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about our "attach"/"detach" helpers? Can these be made common?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markandrus They're not entirely common. In this case, we're also attaching the Track to the Waveform module, whereas in other examples we are not. And I also don't want too much of the app logic to be modularized as it affects the flow of reading the code.

// display the media of the second Participant that will enter
// the Room with bandwidth constraints.
return Video.connect(creds.token, { tracks: [] });
}).then(function(_room) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use async/await now. This also lets us avoid binding _room.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markandrus Do Firefox and Safari support it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, recent versions support it.

resolve(JSON.parse(xhr.responseText));
}
};
xhr.send(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use fetch instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markandrus Do Firefox and Safari support it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@markandrus
Copy link
Contributor

Looks good. What about indicating to the user that the constraints took effect? E.g., by reading getStats? Will it visually be clear enough that the video is at a lower bitrate? Audibly?

@manjeshbhargav
Copy link
Collaborator Author

@markandrus I'm working on adding the bitrate graphs. I'm thinking of leveraging the graph module used by the webrtc sample app demonstrating bandwidth constraints: https://github.com/webrtc/samples/blob/gh-pages/src/js/third_party/graph.js
WDYT?

@manjeshbhargav manjeshbhargav force-pushed the bandwidth-constraints branch 4 times, most recently from da00882 to 94792f0 Compare September 19, 2017 23:04
@manjeshbhargav
Copy link
Collaborator Author

@markandrus I've updated the PR with the following changes:

  1. Used async/await in the Bandwidth Constraints example app.
  2. Used fetch() for getting the Room token.
  3. Added examples/index.html that lists the example apps' links.
  4. Added bitrate graphs in the Bandwidth Constraints example app.

Screenshot of examples/index.html:
screen shot 2017-09-19 at 3 52 55 pm

Screenshot of the bitrate filters:
screen shot 2017-09-19 at 12 38 58 pm

var helpers = require('./helpers');
var waveform = require('../../util/waveform');
var connectWithBandwidthConstraints = helpers.connectWithBandwidthConstraints;
var updateBandwidthConstraints = helpers.updateBandwidthConstraints;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also use const and let instead of var? If async/await is supported, so is const and let.

// Connect to a random Room with no media. This Participant will
// display the media of the second Participant that will enter
// the Room with bandwidth constraints.
var _room = await Video.connect(creds.token, { tracks: [] });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we binding _room instead of assigning to room?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, why not randomRoom or someRoom?

async function connectToOrDisconnectFromRoom(e) {
e.preventDefault();
if (room) {
e.target.value = 'Connect to Room';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have connectOrDisconnect, can you set connectOrDisconnect.value instead of e.target?

/**
* Connect to or disconnect from a Room.
*/
async function connectToOrDisconnectFromRoom(e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think event is better than e here.

}

/**
* Connect to or disconnect from a Room.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to have two functions, connectToRoom, and disconnectFromRoom, then let connectToRoom reassign the "click" event handler of to disconnectFromRoom and vice-versa.

? stats[0].remoteAudioTrackStats[0]
: stats[0].remoteVideoTrackStats[0]
var _bytesReceived = remoteTrackStats.bytesReceived;
var _timestamp = remoteTrackStats.timestamp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we binding _bytesReceiver and _timestamp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markandrus We are not binding these values. These are just the current values, which will be stored in their non-underscored counterpart variables to serve as previous values for the next bitrate calculation.

function getRoomCredentials() {
return fetch('/token').then(function(response) {
return response.json();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use fat-arrow functions and async/await. Basically, I would like us to use all the modern syntax since it is widely available now, e.g.

async function getRoomCredentials() {
  const response = await fetch('/token')
  return response.json();
}

* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add/update our LICENSE.md file. It can take the same form as https://github.com/twilio/twilio-video.js/blob/master/LICENSE.md with a couple changes:

  1. First section: Twilio license
  2. Second section: the WebRTC license

@markandrus
Copy link
Contributor

One comment, otherwise looks good 👍

@manjeshbhargav manjeshbhargav merged commit b77b816 into twilio:master Sep 22, 2017
@manjeshbhargav manjeshbhargav deleted the bandwidth-constraints branch September 22, 2017 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants