ice-breaker
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -110,3 +110,3 @@ 'use strict'; | ||
/** | ||
* Returns an array of the ICE candidates present in the provided sdp. | ||
* Returns an array of the ICE candidates (as objects) present in the provided sdp. | ||
* - The SDP must be a string, with every field in a new line. (See RFC-4566 - | ||
@@ -137,2 +137,30 @@ * https://tools.ietf.org/html/rfc4566 for SDP details). | ||
} | ||
/** | ||
* Returns an array of the ICE candidates (as strings) present in the provided sdp. | ||
* - The SDP must be a string, with every field in a new line. (See RFC-4566 - | ||
* https://tools.ietf.org/html/rfc4566 for SDP details). | ||
* | ||
* @param {string} SDP, with every field in a new line | ||
* @returns {Array} ICE candidates present in the provided sdp (returned as strings) | ||
*/ | ||
}, { | ||
key: 'getUnparsedCandidatesFromSDP', | ||
value: function getUnparsedCandidatesFromSDP(sdp) { | ||
var iceCandidates = []; | ||
if (typeof sdp === 'string') { | ||
var sdpLines = sdp.split('\n'); | ||
var iceCandidatesLines = sdpLines.filter(function (l) { | ||
return l.indexOf('a=candidate') > -1; | ||
}); | ||
iceCandidates = iceCandidatesLines.map(function (l) { | ||
// remove 'a=' | ||
var candidate = l.substr(2).replace('\r', ''); | ||
return candidate; | ||
}); | ||
} | ||
return iceCandidates; | ||
} | ||
}]); | ||
@@ -139,0 +167,0 @@ |
{ | ||
"name": "ice-breaker", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Set of helper methods to ease the WebRTC Media connection process.", | ||
@@ -5,0 +5,0 @@ "main": "lib/ice-breaker.js", |
@@ -1,2 +0,2 @@ | ||
Ice-Breaker | ||
Ice-Breaker [![npm version](https://badge.fury.io/js/ice-breaker.svg)](https://badge.fury.io/js/ice-breaker) | ||
========= | ||
@@ -60,3 +60,3 @@ | ||
#### `getCandidatesFromSDP`: get an array of the ICE candidates present in an SDP file | ||
#### `getCandidatesFromSDP`: get an array of the ICE candidates (as objects) present in an SDP file | ||
@@ -92,2 +92,22 @@ ```javascript | ||
#### `getUnparsedCandidatesFromSDP`: get an array of the ICE candidates (as strings) present in an SDP file | ||
```javascript | ||
var IceBreaker = require('ice-breaker'); | ||
// Please notice this is just a section of an SDP file | ||
var sdp = 'a=sendonly\r\n' + | ||
'a=candidate:1 1 UDP 2013266431 1111::222:3aff:1111:4983 50791 typ host\r\n' + | ||
'a=candidate:2 1 TCP 1019217151 1111::222:3aff:1111:4983 9 typ host tcptype active\r\n'; | ||
var iceCandidates = IceBreaker.getUnparsedCandidatesFromSDP(sdp); | ||
console.log('>>> Unparsed ICE Candidates in my SDP file: ', iceCandidates); | ||
/* Should print: | ||
>>> ICE Candidates in my SDP file: [ 'candidate:1 1 UDP 2013266431 1111::222:3aff:1111:4983 50791 typ host', | ||
'candidate:2 1 TCP 1019217151 1111::222:3aff:1111:4983 9 typ host tcptype active' ] | ||
*/ | ||
``` | ||
--- | ||
@@ -94,0 +114,0 @@ Thank you for using this module! Feel free to contribute :) |
18827
259
118