Comparing version
@@ -6,2 +6,3 @@ # 1.6.x API Reference | ||
- [`prepareSession(opts, [req])`](#preparesessionopts-req) | ||
- [`performTieBreak(existingSession, req)`](#performtiebreakexistingsession-req) | ||
- [`Jingle` Methods](#jingle-methods) | ||
@@ -35,2 +36,3 @@ - [`jingle.addICEServer(info)`](#jingleaddiceserverinfo) | ||
- `prepareSession` - [See below for how `prepareSession` works](#preparesessionopts-req) | ||
- `performTieBreak` - [See below for how `performTieBreak` works](#performtiebreakexistingsession-req) | ||
@@ -82,2 +84,16 @@ ```js | ||
#### `performTieBreak(existingSession, req)` | ||
- `existingSession` - A Session object. | ||
- `req` - The incoming session initiation request that triggered the tie break check. | ||
A tie break check is performed when receiving a `session-initiate` if: | ||
- A session in the `pending` state already exists for the peer. | ||
- The existing pending session ID is greater than the one used by the incoming session request | ||
The `performTieBreak()` method allows you to control whether or not the session request is declined to resolve the tie. In some applications, you may wish to allow two simultaneous sessions (e.g., multiple uni-directional video sessions). In others you may wish to allow the tie break to force the use of a single session (e.g., a bidirectional video session). | ||
Returning `true` will trigger the tie break and deny the request; returning `false` will allow the session request to proceed. | ||
### `Jingle` Methods | ||
@@ -84,0 +100,0 @@ #### `jingle.addICEServer(info)` |
32
index.js
@@ -31,2 +31,14 @@ var util = require('util'); | ||
this.performTieBreak = conf.performTieBreak || function (sess, req) { | ||
var descriptionTypes = req.jingle.contents.map(function (content) { | ||
if (content.description) { | ||
return content.description.descType; | ||
} | ||
}); | ||
var matching = intersect(sess.pendingDescriptionTypes, descriptionTypes); | ||
return matching.length > 0; | ||
}; | ||
this.screenSharingSupport = webrtc.screenSharing; | ||
@@ -327,3 +339,3 @@ | ||
if (session.pending) { | ||
if (this.selfID > session.peerID) { | ||
if (this.selfID > session.peerID && this.performTieBreak(session, req)) { | ||
this._log('error', 'Tie break new session because of duplicate sids'); | ||
@@ -349,14 +361,8 @@ return this._sendError(sender, rid, { | ||
var sess = this.peers[sender][i]; | ||
if (sess && sess.pending) { | ||
if (intersect(descriptionTypes, sess.pendingDescriptionTypes).length) { | ||
// We already have a pending session request for this content type. | ||
if (sess.sid > sid) { | ||
// We won the tie breaker | ||
this._log('info', 'Tie break'); | ||
return this._sendError(sender, rid, { | ||
condition: 'conflict', | ||
jingleCondition: 'tie-break' | ||
}); | ||
} | ||
} | ||
if (sess && sess.pending && sess.sid > sid && this.performTieBreak(sess, req)) { | ||
this._log('info', 'Tie break session-initiate'); | ||
return this._sendError(sender, rid, { | ||
condition: 'conflict', | ||
jingleCondition: 'tie-break' | ||
}); | ||
} | ||
@@ -363,0 +369,0 @@ } |
{ | ||
"name": "jingle", | ||
"description": "Generic Jingle via WebRTC session manager.", | ||
"version": "1.6.3", | ||
"version": "1.7.0", | ||
"author": "Lance Stout <lance@andyet.net>", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/otalk/jingle.js/issues", |
@@ -22,2 +22,3 @@ var test = require('tape'); | ||
sess.state = 'pending'; | ||
sess.pendingDescriptionTypes = ['test']; | ||
@@ -24,0 +25,0 @@ jingle.on('send', function (data) { |
62294
2.1%1568
0.26%