mediaproxy-webrtc
Version:
WebRTC interface for node-mediaproxy
120 lines (107 loc) • 3.67 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var MediaProxyMediaStream, SDP, request;
SDP = require('sdp');
request = require('superagent');
MediaProxyMediaStream = (function() {
/* Typical @constraints value:
media:
address: # IP address of mediaproxy Media
proxy_base: # base URI for access to MediaProxy
description:
type: 'audio'
formats: [ 3 ] # actually may be GSM, GSM-EFR, or GSM-HR-08; for now GSM
attributes: [
## rtpmap is optional since the format (3) is well-known.
# { key: 'rtpmap', value: '3 GSM/8000' }
{ key: 'ptime', value: 20 }
]
*/
function MediaProxyMediaStream(constraints) {
this.constraints = constraints;
this.id = new uuid();
}
MediaProxyMediaStream.prototype.get = function(success, failure) {
var options,
_this = this;
options = {
sip_leg: {
local: {
address: constraints.media.address,
port: null
}
}
};
return request.put("" + this.constraints.media.proxy_base + "/proxy/" + this.id, options, function(err, res) {
var leg, _ref;
if (err != null) {
return failure(err);
}
leg = res != null ? (_ref = res.body) != null ? _ref.sip_leg : void 0 : void 0;
if (leg == null) {
return failure('Unable to build leg');
}
if (leg.error != null) {
return failure(leg.error);
}
_this.description.port = leg.local.port;
_this.description.numberOfPorts = 1;
_this.description.proto = 'RTP/AVP';
_this.description.connection = {
netType: 'IN',
addrType: 'IP4',
address: leg.local.address
};
return success(_this);
});
};
MediaProxyMediaStream.prototype.setRemoteSession = function(session, success, failure) {
var _this = this;
return mediaproxy.get("" + this.constraints.media.proxy_base + "/proxy/" + this.id, function(err, res) {
var options, _ref, _ref1, _ref2;
if (err != null) {
return failure(err);
}
options = res != null ? res.body : void 0;
if (options == null) {
return failure('Could not set options');
}
if (options.sip_leg == null) {
options.sip_leg = {};
}
options.sip_leg.remote = {
address: (_ref = (_ref1 = session.connection) != null ? _ref1.address : void 0) != null ? _ref : (_ref2 = _this.description.connection) != null ? _ref2.address : void 0,
port: first_audio_media.port
};
return mediaproxy.put("" + _this.constraints.media.proxy_base + "/proxy/" + _this.id, options, function(err, res) {
if (err != null) {
return failure(err);
}
return success();
});
});
};
MediaProxyMediaStream.prototype.stop = function() {
var _this = this;
return request["delete"]("" + this.constraints.media.proxy_base + "/proxy/" + this.id, options, function(err, res) {
if (err != null) {
throw new Error(err);
}
});
};
return MediaProxyMediaStream;
})();
module.exports = {
getUserMedia: function(constraints, success, failure) {
var media;
media = new MediaProxyMediaStream(constraints);
return media.get(success, failure);
},
RTCPeerConnection: require('rtc-peer-connection'),
RTCSessionDescription: require('rtc-session-description'),
isSupported: true
};
}).call(this);
/*
//@ sourceMappingURL=index.map
*/