Skip to content

Commit

Permalink
Merge pull request #3 from Temasys/development
Browse files Browse the repository at this point in the history
Major update for AdapterJS including Instlal bar and taking out WebRTCReadyCb Callback function.
  • Loading branch information
serrynaimo committed Sep 9, 2014
2 parents 1a87c7d + 268e1ad commit 12c532d
Show file tree
Hide file tree
Showing 9 changed files with 1,632 additions and 1,192 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ publish
staging
_site
source/config/local.json
node_modules/
demo/
doc/
doc-style/
28 changes: 24 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-replace');

grunt.initConfig({

Expand All @@ -21,8 +22,8 @@ module.exports = function (grunt) {

concat: {
options: {
separator: ';',
stripBanners: true,
separator: '\n',
stripBanners: false,
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */\n\n'
},
Expand All @@ -49,6 +50,25 @@ module.exports = function (grunt) {
}
},

replace: {
dist: {
options: {
variables: {
'version': '<%= pkg.version %>'
},
prefix: '@@'
},
files: [{
expand: true,
flatten: true,
src: [
'<%= production %>/*.js'
],
dest: '<%= production %>/'
}]
}
},

jshint: {
build: {
options: grunt.util._.merge({
Expand Down Expand Up @@ -86,7 +106,7 @@ module.exports = function (grunt) {
grunt.registerTask('publish', [
'clean:production',
'concat:production',
'replace:dist',
'uglify:production_min'
]);

};
};
79 changes: 39 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,12 @@ AdapterJS provides polyfills and cross-browser helpers for WebRTC. It wraps arou

#### Polyfills

`RTCPeerConnection`, `RTCDataChannel` and `navigator.getUserMedia`
`RTCPeerConnection`, `RTCIceCandidate`, `RTCSessionDescription`, `MediaStreamTrack`, `navigator.getUserMedia`, `attachMediaStream`, `reattachMediaStream`

## Using AdapterJS

#### Helper functions

##### `attachMediaStream(videoelement, stream)`

universally adds a stream object to a video element

##### `reattachMediaStream(videoelement, videoelement)`

universally copies a stream object from one video element to another

##### `createIceServer(url, username, password)`

creates a valid iceServer from one url, username and password
Expand All @@ -38,57 +31,63 @@ creates a valid iceServer from one url, username and password

creates a valid iceServers array for the specific browser and version.

##### `checkIceConnectionState(peerID, iceConnectionState, callback, returnStateAlways)`
##### `maybeFixConfiguration(pcConfig)`

Fixes the incompability of `urls` attribute in some browsers.



handles all the iceConnectionState differences cross-browsers. Order of return values are 'checking' > 'connected' > 'completed'.
##### `checkIceConnectionState(peerId, iceConnectionState, callback)`

handles all the iceConnectionState differences cross-browsers. Order of return values are `'checking' > 'connected' > 'completed'`.
tested outcomes in Firefox returns `'checking' > 'connected'` for both offerer and answerer.

Tested outcomes:
- Chrome (offerer) : `'checking' > 'completed' > 'completed'`
- Chrome (answerer) : `'checking' > 'connected'`
- Firefox (offerer) : `'checking' > 'connected'`
- Firefox (answerer) : `'checking' > 'connected'`

```javascript
peerConnection.oniceconnectionstatechange = function () {
checkICEConnectionState(peerID, peerConnection.iceConnectionState, function (iceConnectionState) {
checkICEConnectionState(peerId, peerConnection.iceConnectionState, function (updatedIceConnectionState) {
// do Something every time there's a new state ['checking', 'connected', 'completed']
});
};
```

##### `checkMediaDataChannelSettings(isOffer, peerBrowserAgent, callback, constraints)`
##### `checkMediaDataChannelSettings(peerAgentBrowser, peerAgentVersion, callback, constraints)`

handles all MediaStream and DataChannel differences for interopability cross-browsers.
method has to be called before sending the acknowledge to create the offer and before creating the offer
method has to be called before creating the offer to check if peer should create the offer.

For some older (20+) versions of Firefox and Chrome MediaStream interopability, `MozDontOfferDataChannel` has to be used, and hence Firefox cannot establish a DataChannel connection as an offerer, and results in no DataChannel connection. To achieve both MediaStream and DataChannel connection interopability, Chrome or other browsers has to be the one creating the offer.

```javascript
// Right now we are not yet doing the offer. We are just checking if we should be the offerer instead of
// the other peer
var isOffer = false;
// You may use "webrtcDetectedBrowser" Helper function to get the peer to send browser information
var peerAgentBrowser = peerBrowserName + '|' + peerBrowserVersion;
checkMediaDataChannelSettings(false, peerAgentBrowser, function (beOfferer) {
// Right now we are not yet doing the offer. We are just checking if we should be the offerer instead of the other peer
checkMediaDataChannelSettings(peerAgentBrowser, peerAgentVersion
function (beOfferer, unifiedOfferConstraints) {
if (beOfferer) {
// be the one who does the offer
peerConnection.createOffer(function (offer) {
// success
}, function (error) {
// failure
}, unifiedOfferConstraints);
} else {
// your peer does the offer
// let the other peer do the offer instead.
}
});
}, inputConstraints);
```

```javascript
// We are going to do the offer so we need to check the constraints first.
var isOffer = true;
// You may use "webrtcDetectedBrowser" Helper variable to get the peer to send browser information
var peerAgentBrowser = peerBrowserName + '|' + peerBrowserVersion;
checkMediaDataChannelSettings(isOffer, peerAgentBrowser, function (offerConstraints) {
peerConnection.createOffer(function (offer) {
// success
}, function (error) {
// failure
}, offerConstraints);
}, constraints);
```
#### Helper variables

##### `webrtcDetectedType`

### Helper variables
displays the browser webrtc implementation type.

##### `webrtcDetectedBrowser`
##### `webrtcDetectedDCSupport`

displays all the browser information and the webrtc type of support
displays the browser webrtc datachannel support type.


## Setup this project
Expand Down Expand Up @@ -123,4 +122,4 @@ Tape tests

## License

APACHE 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html
APACHE 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "adapterjs",
"description": "Creating a common API for WebRTC in the browser",
"version": "0.0.2",
"version": "0.9.0",
"homepage": "https://temasys.github.io/",
"author": {
"name": "Temasys Communications Pte. Ltd.",
Expand All @@ -25,6 +25,7 @@
"grunt-contrib-concat": "0.3.0",
"grunt-contrib-jshint": "0.3.0",
"grunt-contrib-uglify": "^0.5.0",
"grunt-replace": "0.7.9",
"tape": "2.12.0"
},
"testling": {
Expand Down
Loading

0 comments on commit 12c532d

Please sign in to comment.