Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sdp-jingle-json

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sdp-jingle-json - npm Package Compare versions

Comparing version 1.3.0 to 2.0.0

lib/senders.js

29

lib/tojson.js

@@ -0,4 +1,6 @@

var SENDERS = require('./senders');
var parsers = require('./parsers');
var idCounter = Math.random();
exports._setIdCounter = function (counter) {

@@ -8,3 +10,8 @@ idCounter = counter;

exports.toSessionJSON = function (sdp, creator) {
exports.toSessionJSON = function (sdp, opts) {
var creator = opts.creator || 'initiator';
var role = opts.role || 'initiator';
var direction = opts.direction || 'outgoing';
// Divide the SDP into session and media sections.

@@ -24,3 +31,3 @@ var media = sdp.split('\r\nm=');

media.forEach(function (m) {
contents.push(exports.toMediaJSON(m, session, creator));
contents.push(exports.toMediaJSON(m, session, opts));
});

@@ -37,3 +44,7 @@ parsed.contents = contents;

exports.toMediaJSON = function (media, session, creator) {
exports.toMediaJSON = function (media, session, opts) {
var creator = opts.creator || 'initiator';
var role = opts.role || 'initiator';
var direction = opts.direction || 'outgoing';
var lines = parsers.lines(media);

@@ -80,5 +91,5 @@ var sessionLines = parsers.lines(session);

} else if (parsers.findLine('a=sendonly', lines, sessionLines)) {
content.senders = 'initiator';
content.senders = SENDERS[role][direction].sendonly;
} else if (parsers.findLine('a=recvonly', lines, sessionLines)) {
content.senders = 'responder';
content.senders = SENDERS[role][direction].recvonly;
} else if (parsers.findLine('a=inactive', lines, sessionLines)) {

@@ -135,9 +146,3 @@ content.senders = 'none';

var senders = {
sendonly: 'responder',
recvonly: 'initiator',
sendrecv: 'both',
inactive: 'none'
};
ext.senders = senders[ext.senders];
ext.senders = SENDERS[role][direction][ext.senders];

@@ -144,0 +149,0 @@ desc.headerExtensions.push(ext);

@@ -1,17 +0,13 @@

var senders = {
'initiator': 'sendonly',
'responder': 'recvonly',
'both': 'sendrecv',
'none': 'inactive',
'sendonly': 'initator',
'recvonly': 'responder',
'sendrecv': 'both',
'inactive': 'none'
};
var SENDERS = require('./senders');
exports.toSessionSDP = function (session, sid, time) {
exports.toSessionSDP = function (session, opts) {
var role = opts.role || 'initiator';
var direction = opts.direction || 'outgoing';
var sid = opts.sid || session.sid || Date.now();
var time = opts.time || Date.now();
var sdp = [
'v=0',
'o=- ' + (sid || session.sid || Date.now()) + ' ' + (time || Date.now()) + ' IN IP4 0.0.0.0',
'o=- ' + sid + ' ' + time + ' IN IP4 0.0.0.0',
's=-',

@@ -28,3 +24,3 @@ 't=0 0'

contents.forEach(function (content) {
sdp.push(exports.toMediaSDP(content));
sdp.push(exports.toMediaSDP(content, opts));
});

@@ -35,5 +31,8 @@

exports.toMediaSDP = function (content) {
exports.toMediaSDP = function (content, opts) {
var sdp = [];
var role = opts.role || 'initiator';
var direction = opts.direction || 'outgoing';
var desc = content.description;

@@ -102,3 +101,3 @@ var transport = content.transport;

if (desc.descType == 'rtp') {
sdp.push('a=' + (senders[content.senders] || 'sendrecv'));
sdp.push('a=' + (SENDERS[role][direction][content.senders] || 'sendrecv'));
}

@@ -159,3 +158,3 @@ sdp.push('a=mid:' + content.name);

hdrExts.forEach(function (hdr) {
sdp.push('a=extmap:' + hdr.id + (hdr.senders ? '/' + senders[hdr.senders] : '') + ' ' + hdr.uri);
sdp.push('a=extmap:' + hdr.id + (hdr.senders ? '/' + SENDERS[role][direction][hdr.senders] : '') + ' ' + hdr.uri);
});

@@ -162,0 +161,0 @@

{
"name": "sdp-jingle-json",
"version": "1.3.0",
"version": "2.0.0",
"description": "A parser/serializer for SDP to JSON. Useful for converting SDP to other formats like Jingle for WebRTC signalling",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -47,6 +47,13 @@ # SDP-Jingle-JSON

// I have SDP, but want JSON:
var json = sjj.toSessionJSON(sdpBlob, 'initiator'); // or 'responder'
var json = sjj.toSessionJSON(sdpBlob, {
creator: 'initiator', // Who created the media contents
role: 'inititator', // Which side of the offer/answer are we acting as
direction: 'outgoing' // Are we parsing SDP that we are sending or receiving?
});
// I have JSON (a dictionary of session and content descriptions), but want SDP:
var sdp = sjj.toSessionSDP(jsonSession);
var sdp = sjj.toSessionSDP(jsonSession, {
role: 'responder',
direction: 'incoming'
});
```

@@ -53,0 +60,0 @@

@@ -18,3 +18,7 @@ "use strict";

tojson._setIdCounter(0);
var json = SJJ.toSessionJSON(sdpData, 'initiator');
var json = SJJ.toSessionJSON(sdpData, {
creator: 'initiator',
role: 'initiator',
direction: 'outgoing'
});

@@ -26,3 +30,9 @@ t.deepEqual(json, jsonData);

test('to sdp', function (t) {
var sdp = SJJ.toSessionSDP(jsonData, sid, time);
var sdp = SJJ.toSessionSDP(jsonData, {
role: 'initiator',
direction: 'outgoing',
sid: sid,
time: time
});
t.deepEqual(sdp, sdpData);

@@ -36,8 +46,26 @@ t.end();

tojson._setIdCounter(0);
var json1 = SJJ.toSessionJSON(sdpData, 'initiator');
var sdp1 = SJJ.toSessionSDP(json1, sid, time);
var json1 = SJJ.toSessionJSON(sdpData, {
creator: 'initiator',
role: 'initiator',
direction: 'outgoing'
});
var sdp1 = SJJ.toSessionSDP(json1, {
role: 'initiator',
direction: 'outgoing',
sid: sid,
time: time
});
tojson._setIdCounter(0);
var json2 = SJJ.toSessionJSON(sdp1, 'initiator');
var sdp2 = SJJ.toSessionSDP(json2, sid, time);
var json2 = SJJ.toSessionJSON(sdp1, {
creator: 'initiator',
role: 'initiator',
direction: 'outgoing'
});
var sdp2 = SJJ.toSessionSDP(json2, {
role: 'initiator',
direction: 'outgoing',
sid: sid,
time: time
});

@@ -44,0 +72,0 @@ t.deepEqual(json2, jsonData);

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc