Socket
Socket
Sign inDemoInstall

ice-breaker

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 0.0.6

0

lib/constants.js

@@ -0,0 +0,0 @@ 'use strict';

71

lib/ice-breaker.js

@@ -9,2 +9,29 @@ 'use strict';

function _validateSDPTransportFilter(_filter) {
var filter = _filter;
if (!filter) return false;
if (typeof filter === 'string') {
filter = [filter];
}
if (Array.isArray(filter)) {
var validTransports = Object.keys(Constants.transport).map(function (k) {
return Constants.transport[k];
});
var isValid = filter.every(function (f) {
return validTransports.indexOf(f) > -1;
});
return isValid ? filter : false;
}
return false;
}
function _getTransportFilterRegexp(filter) {
var filterRegexp = void 0;
filter.forEach(function (f) {
if (!filterRegexp) filterRegexp = '\\b(' + f + ')';else filterRegexp += '|(' + f + ')';
});
filterRegexp += '\\b';
return new RegExp(filterRegexp);
}
var IceBreaker = function () {

@@ -20,2 +47,3 @@ function IceBreaker() {

/**
* @deprecated Use candidateToJson instead.
* Parses the received ICE candidate string into a JSON object

@@ -26,2 +54,15 @@ * @param {string} iceCandidate

value: function toJson(iceCandidate) {
console.warn('This method is deprecated since version 0.0.6. Use `candidateToJson` instead.');
return this.candidateToJson(iceCandidate);
}
/**
* Parses the received ICE candidate string into a JSON object
* @param {string} iceCandidate
* @returns {object} ICE candidate parsed
*/
}, {
key: 'candidateToJson',
value: function candidateToJson(iceCandidate) {
var iceCandidateJson = null;

@@ -56,2 +97,30 @@

}
/**
* Returns a new SDP containing only the ICE candidates that match the
* transport protocol provided in the filter.
* - 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).
* - The SDP will remain the same if it is not a string or no filter
* is provided.
*
* @param {string} SDP to filter, with every field in a new line
* @param {string|Array} filter IceBreaker.transport (UDP|TCP)
*/
}, {
key: 'filterSDPCandidatesByTransport',
value: function filterSDPCandidatesByTransport(sdp, _filter) {
var filteredSdp = sdp;
var filter = _validateSDPTransportFilter(_filter);
if (typeof sdp === 'string' && filter) {
var transportRegex = _getTransportFilterRegexp(filter);
var sdpLines = sdp.split('\n');
var filteredSdpLines = sdpLines.filter(function (l) {
return l.indexOf('a=candidate') > -1 && l.search(transportRegex) > -1 || l.indexOf('a=candidate') < 0;
});
filteredSdp = filteredSdpLines.join('\n');
}
return filteredSdp;
}
}]);

@@ -62,2 +131,4 @@

IceBreaker.transport = Constants.transport;
module.exports = IceBreaker;

13

package.json
{
"name": "ice-breaker",
"version": "0.0.5",
"version": "0.0.6",
"description": "Parse WebRTC ICE Candidates string",

@@ -12,3 +12,3 @@ "main": "lib/ice-breaker.js",

"test": "nyc mocha --reporter spec",
"compile": "babel --presets es2015 -d lib/ src/",
"compile": "babel --presets env -d lib/ src/",
"prepublish": "npm run compile"

@@ -21,3 +21,6 @@ },

"stun",
"turn"
"turn",
"sdp",
"tcp",
"udp"
],

@@ -28,3 +31,3 @@ "author": "Maria Fernandez <mariafehe@gmail.com>",

"babel-cli": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-env": "^1.6.1",
"chai": "^4.0.2",

@@ -48,4 +51,6 @@ "eslint": "^3.19.0",

"nyc": "^11.0.2",
"sinon": "^4.5.0",
"sinon-chai": "^3.0.0",
"yargs": "^8.0.1"
}
}
Ice-Breaker
=========
Ice-Breaker is a helper to parse WebRTC ICE candidate strings.
Ice-Breaker is a set of helper methods to ease the WebRTC Media connection process.
Context
-----
**WebRTC (Web Real-Time Communication)** is a collection of communications protocols and application programming interfaces that enable real-time communication over peer-to-peer connections. In order for these peers on different networks to locate one another, a form of discovery and media format negotiation must take place. This process is called signaling, and is where the ICE candidates enter the game.
**WebRTC (Web Real-Time Communication)** is a collection of communications protocols and application programming interfaces that enable real-time communication over peer-to-peer connections. In order for these peers on different networks to locate one another, a form of discovery and media format negotiation must take place. Each peer will need to provide ICE candidates to the remote peer. The Session Description Protocol is used in this signaling process ([RFC-4566](https://tools.ietf.org/html/rfc4566)).

@@ -16,10 +16,13 @@ Each ICE candidate describes a method which the originating peer is able to communicate, and each peer sends candidates in the order of discovery, until it runs out of suggestions. Once the two peers suggest a compatible candidate, media begins to flow.

```
**Ice-Breaker** provides a method to parse this string into an object so the different fields can be easily inspected.
**Ice-Breaker** provides methods to parse this string into an object so the different fields can be easily inspected, to filter SDP files so only candidates using a specific transport protocol are used, etc.
How to use
----
#### `candidateToJson`: convert ICE Candidates to a JSON object
```javascript
var IceBreaker = require('ice-breaker');
var parsedCandidate = IceBreaker.toJson('candidate:7 1 UDP 1677722111 13.93.207.159 43399 typ srflx raddr 11.1.221.7 rport 43399');
var parsedCandidate = IceBreaker.candidateToJson('candidate:7 1 UDP 1677722111 13.93.207.159 43399 typ srflx raddr 11.1.221.7 rport 43399');

@@ -39,3 +42,21 @@ console.log('>>> My parsed ICE candidate: ', parsedCandidate);

```
#### `filterSDPCandidatesByTransport`: filter ICE candidates in an SDP file by transport protocol
```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 filteredSdp = IceBreaker.filterSDPCandidatesByTransport(sdp, 'TCP');
console.log('>>> My filtered SDP: ', filteredSdp);
/* Should print:
>>> My filtered SDP: a=sendonly
a=candidate:2 1 TCP 1019217151 1111::222:3aff:1111:4983 9 typ host tcptype active
*/
```
Thank you for using this module! Feel free to contribute :)

@@ -42,0 +63,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc