@messagebird/client
Advanced tools
Comparing version 1.0.0-next.2 to 1.0.0-next.3
@@ -0,1 +1,80 @@ | ||
# [1.0.0-next.2](https://git.messagebird.io/frontend/javascript-webrtc-sdk/compare/v1.0.0-next.1...v1.0.0-next.2) (2020-04-21) | ||
### Bug Fixes | ||
* absolute imports ([3dc28ce](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/3dc28ce2915d8921101cb37585115754f12093c2)) | ||
* trigger release ([fe133ad](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/fe133ad59a307773fad3673e0f104f315a7e796a)) | ||
* trigger version ([c71020e](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/c71020ed3213cca3a2d382d1b47be52548b71439)) | ||
### chore | ||
* rename session to call ([b5c7a33](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/b5c7a33a9e491d3577c3210a9ce877e7ccabd609)) | ||
### Code Refactoring | ||
* change MediaSources API ([e688971](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/e688971397cf7b470c653d2ad411d1860ff532b8)) | ||
### Features | ||
* trigger release ([139cf50](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/139cf50ad7ff75e1b9bd0c83b657a4caedf2c720)) | ||
### BREAKING CHANGES | ||
* session is now renamed to call | ||
* media sources API is directly on Session | ||
# [1.0.0-next.2](https://git.messagebird.io/frontend/javascript-webrtc-sdk/compare/v1.0.0-next.1...v1.0.0-next.2) (2020-04-21) | ||
### Bug Fixes | ||
* absolute imports ([3dc28ce](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/3dc28ce2915d8921101cb37585115754f12093c2)) | ||
* trigger release ([fe133ad](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/fe133ad59a307773fad3673e0f104f315a7e796a)) | ||
* trigger version ([c71020e](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/c71020ed3213cca3a2d382d1b47be52548b71439)) | ||
### chore | ||
* rename session to call ([b5c7a33](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/b5c7a33a9e491d3577c3210a9ce877e7ccabd609)) | ||
### Code Refactoring | ||
* change MediaSources API ([e688971](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/e688971397cf7b470c653d2ad411d1860ff532b8)) | ||
### BREAKING CHANGES | ||
* session is now renamed to call | ||
* media sources API is directly on Session | ||
# [1.0.0-next.2](https://git.messagebird.io/frontend/javascript-webrtc-sdk/compare/v1.0.0-next.1...v1.0.0-next.2) (2020-04-21) | ||
### Bug Fixes | ||
* absolute imports ([3dc28ce](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/3dc28ce2915d8921101cb37585115754f12093c2)) | ||
* trigger version ([c71020e](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/c71020ed3213cca3a2d382d1b47be52548b71439)) | ||
### chore | ||
* rename session to call ([b5c7a33](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/b5c7a33a9e491d3577c3210a9ce877e7ccabd609)) | ||
### Code Refactoring | ||
* change MediaSources API ([e688971](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/e688971397cf7b470c653d2ad411d1860ff532b8)) | ||
### BREAKING CHANGES | ||
* session is now renamed to call | ||
* media sources API is directly on Session | ||
# [1.0.0-next.1](https://git.messagebird.io/frontend/javascript-webrtc-sdk/compare/v0.16.0-next.2...v1.0.0-next.1) (2020-04-20) | ||
@@ -2,0 +81,0 @@ |
@@ -20,4 +20,2 @@ 'use strict'; | ||
var _slicedToArray = _interopDefault(require('@babel/runtime/helpers/slicedToArray')); | ||
var incomingMessageHeaders = require('incomingMessageHeaders'); | ||
var failureCauses = require('failureCauses'); | ||
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator')); | ||
@@ -84,3 +82,3 @@ var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator')); | ||
function getSDKVersionHeader() { | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "c71020ed" ; | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "01296074" ; | ||
return "SDK-Version: ".concat(version); | ||
@@ -122,11 +120,11 @@ } | ||
(function (SessionStatus) { | ||
SessionStatus["Initial"] = "initial"; | ||
SessionStatus["Ringing"] = "ringing"; | ||
SessionStatus["Connecting"] = "connecting"; | ||
SessionStatus["Failed"] = "failed"; | ||
SessionStatus["Accepted"] = "accepted"; | ||
SessionStatus["Confirmed"] = "confirmed"; | ||
SessionStatus["Disconnected"] = "disconnected"; | ||
})(exports.SessionStatus || (exports.SessionStatus = {})); | ||
(function (CallStatus) { | ||
CallStatus["Initial"] = "initial"; | ||
CallStatus["Ringing"] = "ringing"; | ||
CallStatus["Connecting"] = "connecting"; | ||
CallStatus["Failed"] = "failed"; | ||
CallStatus["Accepted"] = "accepted"; | ||
CallStatus["Confirmed"] = "confirmed"; | ||
CallStatus["Disconnected"] = "disconnected"; | ||
})(exports.CallStatus || (exports.CallStatus = {})); | ||
@@ -263,2 +261,8 @@ (function (ClientStatus) { | ||
_defineProperty(this, "handleNewSession", function (session) { | ||
if (session.originator === 'remote') { | ||
_this.eventEmitter.emit('session', session); | ||
} | ||
}); | ||
_defineProperty(this, "call", function (options) { | ||
@@ -330,9 +334,2 @@ return _this.sipUA.call(_this.sipAddress, options); | ||
}, { | ||
key: "handleNewSession", | ||
value: function handleNewSession(session) { | ||
if (session.originator === 'remote') { | ||
this.eventEmitter.emit('session', session); | ||
} | ||
} | ||
}, { | ||
key: "sendMessage", | ||
@@ -382,246 +379,44 @@ value: function sendMessage(message, options) { | ||
var MediaManager = function MediaManager(streamTargets, rtcPeerConnection) { | ||
var _this = this; | ||
var IncomingMessageHeaders; | ||
_classCallCheck(this, MediaManager); | ||
(function (IncomingMessageHeaders) { | ||
IncomingMessageHeaders["Via"] = "Via"; | ||
IncomingMessageHeaders["RecordRoute"] = "Record-Route"; | ||
IncomingMessageHeaders["CallID"] = "Call-ID"; | ||
IncomingMessageHeaders["From"] = "From"; | ||
IncomingMessageHeaders["To"] = "To"; | ||
IncomingMessageHeaders["CSeq"] = "CSeq"; | ||
IncomingMessageHeaders["Warning"] = "Warning"; | ||
IncomingMessageHeaders["Server"] = "Server"; | ||
IncomingMessageHeaders["ContentLength"] = "Content-Length"; | ||
})(IncomingMessageHeaders || (IncomingMessageHeaders = {})); | ||
this.streamTargets = streamTargets; | ||
this.rtcPeerConnection = rtcPeerConnection; | ||
var FailureCauses; | ||
_defineProperty(this, "eventEmitter", new events.EventEmitter()); | ||
(function (FailureCauses) { | ||
FailureCauses["ConnectionError"] = "Connection Error"; | ||
FailureCauses["RequestTimeout"] = "Request Timeout"; | ||
FailureCauses["SIPFailureCode"] = "SIP Failure Code"; | ||
FailureCauses["InternalError"] = "Internal Error"; | ||
FailureCauses["Busy"] = "Busy"; | ||
FailureCauses["Rejected"] = "Rejected"; | ||
FailureCauses["Redirected"] = "Redirected"; | ||
FailureCauses["Unavailable"] = "Unavailable"; | ||
FailureCauses["NotFound"] = "Not Found"; | ||
FailureCauses["AddressIncomplete"] = "Address Incomplete"; | ||
FailureCauses["IncompatibleSDP"] = "Incompatible SDP"; | ||
FailureCauses["MissingSDP"] = "Received a request/response that should have SDP body but did not."; | ||
FailureCauses["AuthenticationError"] = "Authentication Error"; | ||
FailureCauses["InvalidSDPDescriptor"] = "399 SIP \"Invalid SDP descriptor (PJMEDIA_SDP_EINSDP)\""; | ||
FailureCauses["Bye"] = "Terminated"; | ||
FailureCauses["Canceled"] = "Canceled"; | ||
FailureCauses["NoAnswer"] = "No Answer"; | ||
FailureCauses["Expires"] = "Expires"; | ||
FailureCauses["NoACK"] = "No ACK"; | ||
FailureCauses["DialogError"] = "Dialog Error"; | ||
FailureCauses["UserDeniedMediaAccess"] = "User Denied Media Access"; | ||
FailureCauses["BadMediaDescription"] = "Bad Media Description"; | ||
FailureCauses["RTPTimeout"] = "RTP Timeout"; | ||
})(FailureCauses || (FailureCauses = {})); | ||
_defineProperty(this, "_handleDeviceChange", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var devices; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return _this.get(); | ||
case 2: | ||
devices = _context.sent; | ||
_this.eventEmitter.emit('devicechange', devices); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))); | ||
_defineProperty(this, "get", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
var data, devices; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
data = { | ||
inputs: { | ||
audio: [], | ||
video: [] | ||
}, | ||
outputs: { | ||
audio: [] | ||
} | ||
}; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return navigator.mediaDevices.enumerateDevices(); | ||
case 4: | ||
devices = _context2.sent; | ||
devices.forEach(function (device) { | ||
var _device$kind$split = device.kind.split(/(input|output)/gi), | ||
_device$kind$split2 = _slicedToArray(_device$kind$split, 2), | ||
kind = _device$kind$split2[0], | ||
type = _device$kind$split2[1]; | ||
type === 'input' ? data.inputs[kind].push(device) : data.outputs[kind].push(device); | ||
}); | ||
_context2.next = 10; | ||
break; | ||
case 8: | ||
_context2.prev = 8; | ||
_context2.t0 = _context2["catch"](1); | ||
case 10: | ||
return _context2.abrupt("return", data); | ||
case 11: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[1, 8]]); | ||
}))); | ||
_defineProperty(this, "on", function (eventName, cb) { | ||
_this.eventEmitter.on(eventName, cb); | ||
}); | ||
_defineProperty(this, "off", function (eventName, cb) { | ||
_this.eventEmitter.off(eventName, cb); | ||
}); | ||
_defineProperty(this, "set", /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(constraints) { | ||
var senders, nextStream, nextTracks, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _sender$track, sender, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, track; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
if (!(!_this.streamTargets || !_this.rtcPeerConnection)) { | ||
_context3.next = 2; | ||
break; | ||
} | ||
throw new Error('Unable to set user media source. An active RTC connection is required.'); | ||
case 2: | ||
// Get the A/V track senders | ||
senders = _this.rtcPeerConnection.getSenders(); // Apply the desired media constraints | ||
_context3.next = 5; | ||
return navigator.mediaDevices.getUserMedia(constraints); | ||
case 5: | ||
nextStream = _context3.sent; | ||
_context3.next = 8; | ||
return nextStream.getTracks(); | ||
case 8: | ||
nextTracks = _context3.sent; // Iterate through the list of track senders | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_context3.prev = 12; | ||
_iterator = senders[Symbol.iterator](); | ||
case 14: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context3.next = 46; | ||
break; | ||
} | ||
sender = _step.value; // Stop each existing track | ||
(_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.stop(); // Replace the tracks that this sender is | ||
// using with the newly specified ones. | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context3.prev = 20; | ||
_iterator2 = nextTracks[Symbol.iterator](); | ||
case 22: | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
_context3.next = 29; | ||
break; | ||
} | ||
track = _step2.value; | ||
_context3.next = 26; | ||
return sender.replaceTrack(track); | ||
case 26: | ||
_iteratorNormalCompletion2 = true; | ||
_context3.next = 22; | ||
break; | ||
case 29: | ||
_context3.next = 35; | ||
break; | ||
case 31: | ||
_context3.prev = 31; | ||
_context3.t0 = _context3["catch"](20); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context3.t0; | ||
case 35: | ||
_context3.prev = 35; | ||
_context3.prev = 36; | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
} | ||
case 38: | ||
_context3.prev = 38; | ||
if (!_didIteratorError2) { | ||
_context3.next = 41; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 41: | ||
return _context3.finish(38); | ||
case 42: | ||
return _context3.finish(35); | ||
case 43: | ||
_iteratorNormalCompletion = true; | ||
_context3.next = 14; | ||
break; | ||
case 46: | ||
_context3.next = 52; | ||
break; | ||
case 48: | ||
_context3.prev = 48; | ||
_context3.t1 = _context3["catch"](12); | ||
_didIteratorError = true; | ||
_iteratorError = _context3.t1; | ||
case 52: | ||
_context3.prev = 52; | ||
_context3.prev = 53; | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
} | ||
case 55: | ||
_context3.prev = 55; | ||
if (!_didIteratorError) { | ||
_context3.next = 58; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 58: | ||
return _context3.finish(55); | ||
case 59: | ||
return _context3.finish(52); | ||
case 60: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, null, [[12, 48, 52, 60], [20, 31, 35, 43], [36,, 38, 42], [53,, 55, 59]]); | ||
})); | ||
return function (_x) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}()); | ||
navigator.mediaDevices.ondevicechange = this._handleDeviceChange; | ||
}; | ||
function createStreamTarget(stream) { | ||
@@ -1014,10 +809,12 @@ var video = document.createElement('video'); | ||
var COLLECTION_INTERVAL = 5000; | ||
var RTCSession = /*#__PURE__*/function () { | ||
function RTCSession(sipRtcSession) { | ||
var Call = /*#__PURE__*/function () { | ||
function Call(rtcSession) { | ||
var _this = this; | ||
_classCallCheck(this, RTCSession); | ||
_classCallCheck(this, Call); | ||
_defineProperty(this, "_status", exports.SessionStatus.Connecting); | ||
this.rtcSession = rtcSession; | ||
_defineProperty(this, "_status", exports.CallStatus.Connecting); | ||
_defineProperty(this, "_lastError", null); | ||
@@ -1027,14 +824,14 @@ | ||
_defineProperty(this, "sipRTCSession", void 0); | ||
_defineProperty(this, "_callId", null); | ||
_defineProperty(this, "_callId", void 0); | ||
_defineProperty(this, "statsTimeout", 0); | ||
_defineProperty(this, "statsTimeout", void 0); | ||
_defineProperty(this, "streamTargets", []); | ||
_defineProperty(this, "mediaSources", void 0); | ||
_defineProperty(this, "addTrackListener", function () { | ||
if (!_this.rtcSession.connection) { | ||
throw new Error('Connection is not ready to add track listener'); | ||
} | ||
_defineProperty(this, "addTrackListener", function () { | ||
_this.sipRTCSession.connection.addEventListener('track', _this.handleAddTrack); | ||
_this.rtcSession.connection.addEventListener('track', _this.handleAddTrack); | ||
}); | ||
@@ -1055,3 +852,3 @@ | ||
_this.sipRTCSession.sendDTMF(keys); | ||
_this.rtcSession.sendDTMF(keys); | ||
}); | ||
@@ -1062,5 +859,8 @@ | ||
return removeStreamTarget(target); | ||
}); | ||
}); // FIXME: which statuses to allow this? Prevent jssip error | ||
_this.sipRTCSession.terminate(); | ||
if (_this.status !== exports.CallStatus.Failed) { | ||
_this.rtcSession.terminate(); | ||
} | ||
}); | ||
@@ -1081,3 +881,3 @@ | ||
_this.setStatus(exports.SessionStatus.Accepted); | ||
_this.setStatus(exports.CallStatus.Accepted); | ||
}); | ||
@@ -1090,3 +890,3 @@ | ||
_this.setStatus(exports.SessionStatus.Confirmed); | ||
_this.setStatus(exports.CallStatus.Confirmed); | ||
}); | ||
@@ -1097,14 +897,6 @@ | ||
_this.setStatus(exports.SessionStatus.Disconnected); | ||
_this.setStatus(exports.CallStatus.Disconnected); | ||
}); | ||
_defineProperty(this, "handleFailed", function (data) { | ||
if (_this.sipRTCSession) { | ||
try { | ||
_this.getAndSendStats(); | ||
} finally { | ||
clearTimeout(_this.statsTimeout); | ||
} | ||
} | ||
var error; // TODO: Handle specific errors. | ||
@@ -1117,3 +909,3 @@ | ||
_this.setStatus(exports.SessionStatus.Failed); | ||
_this.setStatus(exports.CallStatus.Failed); | ||
@@ -1125,3 +917,3 @@ _this.setError(error); | ||
if (data.originator === 'remote' && data.response.status_code === exports.SipStatusCodes.Ringing) { | ||
_this.setStatus(exports.SessionStatus.Ringing); | ||
_this.setStatus(exports.CallStatus.Ringing); | ||
@@ -1138,7 +930,7 @@ _this._callId = data.response.call_id; | ||
if (muted) { | ||
_this.sipRTCSession.mute({ | ||
_this.rtcSession.mute({ | ||
audio: true | ||
}); | ||
} else { | ||
_this.sipRTCSession.unmute({ | ||
_this.rtcSession.unmute({ | ||
audio: true | ||
@@ -1149,14 +941,14 @@ }); | ||
this.sipRTCSession = sipRtcSession; | ||
this.sipRTCSession.on('accepted', this.handleAccepted); | ||
this.sipRTCSession.on('confirmed', this.handleConfirmed); | ||
this.sipRTCSession.on('ended', this.handleEnded); | ||
this.sipRTCSession.on('failed', this.handleFailed); | ||
this.sipRTCSession.on('progress', this.handleProgress); | ||
this.sipRTCSession.on('muted', this.handleMuteUnmute); | ||
this.sipRTCSession.on('unmuted', this.handleMuteUnmute); | ||
this.mediaSources = new MediaManager(this.streamTargets, sipRtcSession.connection); | ||
rtcSession.on('accepted', this.handleAccepted); | ||
rtcSession.on('confirmed', this.handleConfirmed); | ||
rtcSession.on('ended', this.handleEnded); | ||
rtcSession.on('failed', this.handleFailed); | ||
rtcSession.on('progress', this.handleProgress); | ||
rtcSession.on('muted', this.handleMuteUnmute); | ||
rtcSession.on('unmuted', this.handleMuteUnmute); // Default eventEmitter behavior is to throw when there's no listeners | ||
this.eventEmitter.on('error', function () {}); | ||
} | ||
_createClass(RTCSession, [{ | ||
_createClass(Call, [{ | ||
key: "on", | ||
@@ -1174,8 +966,8 @@ value: function on(name, cb) { | ||
value: function answer(options) { | ||
return this.sipRTCSession.answer(options); | ||
return this.rtcSession.answer(options); | ||
} | ||
}, { | ||
key: "terminate", | ||
value: function terminate() { | ||
return this.sipRTCSession.terminate(); | ||
key: "endCall", | ||
value: function endCall() { | ||
return this.rtcSession.terminate(); | ||
} | ||
@@ -1185,3 +977,3 @@ }, { | ||
value: function setError(error) { | ||
this._lastError = exports.SessionStatus.Failed; | ||
this._lastError = error; | ||
this.eventEmitter.emit('error', error); | ||
@@ -1192,12 +984,6 @@ } | ||
value: function sendInfoMessage(message) { | ||
this.sipRTCSession.sendInfo('application/json', JSON.stringify(message)); | ||
if (this.status === exports.CallStatus.Failed) return; | ||
this.rtcSession.sendInfo('application/json', JSON.stringify(message)); | ||
} | ||
}, { | ||
key: "getStatsReport", | ||
value: function getStatsReport() { | ||
return this.sipRTCSession.connection.getStats().then(function (report) { | ||
return new StatsReport(report); | ||
}); | ||
} | ||
}, { | ||
key: "getAndSendStats", | ||
@@ -1207,4 +993,10 @@ value: function getAndSendStats() { | ||
return this.getStatsReport().then(function (stats) { | ||
return _this2.sendInfoMessage(stats.data); | ||
if (!this.rtcSession.isEstablished()) { | ||
return Promise.reject(new Error('RTC Session was not established')); | ||
} | ||
return this.rtcSession.connection.getStats().then(function (report) { | ||
var statsReport = new StatsReport(report); | ||
_this2.sendInfoMessage(statsReport); | ||
}); | ||
@@ -1222,8 +1014,10 @@ } | ||
case 0: | ||
this.statsTimeout = setTimeout(function () { | ||
var isEstablished = _this3.sipRTCSession.isEstablished(); | ||
this.statsTimeout = window.setTimeout(function () { | ||
var isEstablished = _this3.rtcSession.isEstablished(); | ||
if (!isEstablished) return; | ||
_this3.getAndSendStats()["finally"](function () { | ||
_this3.getAndSendStats()["catch"](function () { | ||
window.clearTimeout(_this3.statsTimeout); | ||
})["finally"](function () { | ||
return _this3.getConnectionStats(); | ||
@@ -1248,2 +1042,159 @@ }); | ||
}, { | ||
key: "setInputSource", | ||
value: function () { | ||
var _setInputSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(constraints) { | ||
var senders, nextStream, nextTracks, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _sender$track, sender, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, track; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (this.rtcSession.connection) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
throw new Error('Could not set media sources. No active call ongoing.'); | ||
case 2: | ||
// Get the A/V track senders | ||
senders = this.rtcSession.connection.getSenders(); // Apply the desired media constraints | ||
_context2.next = 5; | ||
return navigator.mediaDevices.getUserMedia(constraints); | ||
case 5: | ||
nextStream = _context2.sent; | ||
_context2.next = 8; | ||
return nextStream.getTracks(); | ||
case 8: | ||
nextTracks = _context2.sent; // Iterate through the list of track senders | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_context2.prev = 12; | ||
_iterator = senders[Symbol.iterator](); | ||
case 14: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context2.next = 46; | ||
break; | ||
} | ||
sender = _step.value; // Stop each existing track | ||
(_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.stop(); // Replace the tracks that this sender is | ||
// using with the newly specified ones. | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context2.prev = 20; | ||
_iterator2 = nextTracks[Symbol.iterator](); | ||
case 22: | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
_context2.next = 29; | ||
break; | ||
} | ||
track = _step2.value; | ||
_context2.next = 26; | ||
return sender.replaceTrack(track); | ||
case 26: | ||
_iteratorNormalCompletion2 = true; | ||
_context2.next = 22; | ||
break; | ||
case 29: | ||
_context2.next = 35; | ||
break; | ||
case 31: | ||
_context2.prev = 31; | ||
_context2.t0 = _context2["catch"](20); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context2.t0; | ||
case 35: | ||
_context2.prev = 35; | ||
_context2.prev = 36; | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
} | ||
case 38: | ||
_context2.prev = 38; | ||
if (!_didIteratorError2) { | ||
_context2.next = 41; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 41: | ||
return _context2.finish(38); | ||
case 42: | ||
return _context2.finish(35); | ||
case 43: | ||
_iteratorNormalCompletion = true; | ||
_context2.next = 14; | ||
break; | ||
case 46: | ||
_context2.next = 52; | ||
break; | ||
case 48: | ||
_context2.prev = 48; | ||
_context2.t1 = _context2["catch"](12); | ||
_didIteratorError = true; | ||
_iteratorError = _context2.t1; | ||
case 52: | ||
_context2.prev = 52; | ||
_context2.prev = 53; | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
} | ||
case 55: | ||
_context2.prev = 55; | ||
if (!_didIteratorError) { | ||
_context2.next = 58; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 58: | ||
return _context2.finish(55); | ||
case 59: | ||
return _context2.finish(52); | ||
case 60: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this, [[12, 48, 52, 60], [20, 31, 35, 43], [36,, 38, 42], [53,, 55, 59]]); | ||
})); | ||
function setInputSource(_x) { | ||
return _setInputSource.apply(this, arguments); | ||
} | ||
return setInputSource; | ||
}() | ||
}, { | ||
key: "status", | ||
@@ -1266,14 +1217,16 @@ get: function get() { | ||
get: function get() { | ||
return this.sipRTCSession.isMuted().audio; | ||
var _ref, _this$rtcSession$isMu; | ||
return (_ref = (_this$rtcSession$isMu = this.rtcSession.isMuted()) === null || _this$rtcSession$isMu === void 0 ? void 0 : _this$rtcSession$isMu.audio) !== null && _ref !== void 0 ? _ref : false; | ||
} | ||
}]); | ||
return RTCSession; | ||
return Call; | ||
}(); | ||
var OutgoingSession = /*#__PURE__*/function () { | ||
function OutgoingSession(ua, options) { | ||
var OutgoingCall = /*#__PURE__*/function () { | ||
function OutgoingCall(ua, options) { | ||
var _this = this; | ||
_classCallCheck(this, OutgoingSession); | ||
_classCallCheck(this, OutgoingCall); | ||
@@ -1287,3 +1240,3 @@ this.ua = ua; | ||
_defineProperty(this, "rtcSession", void 0); | ||
_defineProperty(this, "_call", void 0); | ||
@@ -1300,4 +1253,4 @@ _defineProperty(this, "eventEmitter", new events.EventEmitter()); | ||
var warningMessage = data.message.getHeader(incomingMessageHeaders.IncomingMessageHeaders.Warning); | ||
var shouldRetry = warningMessage === failureCauses.FailureCauses.InvalidSDPDescriptor && _this.connectionAttempt < 3; | ||
var warningMessage = data.message.getHeader(IncomingMessageHeaders.Warning); | ||
var shouldRetry = warningMessage === FailureCauses.InvalidSDPDescriptor && _this.connectionAttempt < 3; | ||
@@ -1309,3 +1262,3 @@ if (shouldRetry) { | ||
_this.rtcSession = nextSession; | ||
_this._call = nextSession; | ||
@@ -1358,10 +1311,10 @@ _this.eventEmitter.emit('session', nextSession); | ||
this.rtcSession = this.startOutgoingSession(); | ||
this._call = this.startOutgoingSession(); | ||
} | ||
_createClass(OutgoingSession, [{ | ||
_createClass(OutgoingCall, [{ | ||
key: "startOutgoingSession", | ||
value: function startOutgoingSession() { | ||
var params = this.options.params; | ||
var sipSession = this.ua.call({ | ||
var rtcSession = this.ua.call({ | ||
mediaConstraints: { | ||
@@ -1377,6 +1330,6 @@ audio: true, | ||
}); | ||
sipSession.on('sending', this.handleSending); | ||
sipSession.on('progress', this.handleProgress); | ||
sipSession.on('failed', this.handleFailed); | ||
var session = new RTCSession(sipSession); | ||
rtcSession.on('sending', this.handleSending); | ||
rtcSession.on('progress', this.handleProgress); | ||
rtcSession.on('failed', this.handleFailed); | ||
var session = new Call(rtcSession); | ||
session.addTrackListener(); | ||
@@ -1391,15 +1344,22 @@ return session; | ||
}, { | ||
key: "session", | ||
key: "removeEventListener", | ||
value: function removeEventListener(name, cb) { | ||
this.eventEmitter.removeListener(name, cb); | ||
} | ||
}, { | ||
key: "call", | ||
get: function get() { | ||
return this.rtcSession; | ||
return this._call; | ||
} | ||
}]); | ||
return OutgoingSession; | ||
return OutgoingCall; | ||
}(); | ||
var IncomingSession = /*#__PURE__*/function () { | ||
function IncomingSession(ua, sipSession) { | ||
_classCallCheck(this, IncomingSession); | ||
var IncomingCall = /*#__PURE__*/function () { | ||
function IncomingCall(ua, rtcSession) { | ||
var _this = this; | ||
_classCallCheck(this, IncomingCall); | ||
this.ua = ua; | ||
@@ -1411,10 +1371,16 @@ | ||
_defineProperty(this, "session", void 0); | ||
_defineProperty(this, "call", void 0); | ||
this.session = new RTCSession(sipSession.session); | ||
this._displayName = sipSession.request.from.display_name; | ||
sipSession.session.on('failed', this.handleFailed); | ||
_defineProperty(this, "handleFailed", function () { | ||
// Historically, we would always emit canceled when a session failed. Maybe we need better error handling | ||
// In the future, because "failed" may be sent at more points in time | ||
_this.eventEmitter.emit('failed', _this); | ||
}); | ||
this.call = new Call(rtcSession.session); | ||
this._displayName = rtcSession.request.from.display_name; | ||
rtcSession.session.on('failed', this.handleFailed); | ||
} | ||
_createClass(IncomingSession, [{ | ||
_createClass(IncomingCall, [{ | ||
key: "on", | ||
@@ -1425,12 +1391,5 @@ value: function on(name, cb) { | ||
}, { | ||
key: "handleFailed", | ||
value: function handleFailed() { | ||
// Historically, we would always emit canceled when a session failed. Maybe we need better error handling | ||
// In the future, because "failed" may be sent at more points in time | ||
this.eventEmitter.emit('failed', this); | ||
} | ||
}, { | ||
key: "accept", | ||
value: function accept() { | ||
this.session.answer({ | ||
this.call.answer({ | ||
extraHeaders: [], | ||
@@ -1441,4 +1400,4 @@ pcConfig: { | ||
}); | ||
this.session.addTrackListener(); | ||
return this.session; | ||
this.call.addTrackListener(); | ||
return this.call; | ||
} | ||
@@ -1448,3 +1407,3 @@ }, { | ||
value: function reject() { | ||
this.session.terminate(); | ||
this.call.endCall(); | ||
} | ||
@@ -1458,3 +1417,3 @@ }, { | ||
return IncomingSession; | ||
return IncomingCall; | ||
}(); | ||
@@ -1483,3 +1442,3 @@ | ||
_defineProperty(this, "handleNewSession", function (sessionEvent) { | ||
var incomingSession = new IncomingSession(_this.userAgent, sessionEvent); | ||
var incomingSession = new IncomingCall(_this.userAgent, sessionEvent); | ||
incomingSession.on('failed', function () { | ||
@@ -1534,4 +1493,4 @@ _this.eventEmitter.emit('canceled', incomingSession); | ||
}, { | ||
key: "startSession", | ||
value: function startSession(options) { | ||
key: "startCall", | ||
value: function startCall(options) { | ||
if (this.userAgent.status !== exports.ClientStatus.Connected) { | ||
@@ -1542,3 +1501,3 @@ throw new Error('No active connection. Call `client.setup()` to initialize the device first.'); | ||
this.userAgent.register(); | ||
return new OutgoingSession(this.userAgent, { | ||
return new OutgoingCall(this.userAgent, { | ||
params: options | ||
@@ -1562,2 +1521,110 @@ }); | ||
var MediaSources = /*#__PURE__*/function () { | ||
function MediaSources() { | ||
var _this = this; | ||
_classCallCheck(this, MediaSources); | ||
_defineProperty(this, "eventEmitter", new events.EventEmitter()); | ||
_defineProperty(this, "_devices", { | ||
inputs: { | ||
audio: [], | ||
video: [] | ||
}, | ||
outputs: { | ||
audio: [] | ||
} | ||
}); | ||
_defineProperty(this, "setDevices", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return _this.get(); | ||
case 2: | ||
_this._devices = _context.sent; | ||
_this.eventEmitter.emit('devicechange', _this._devices); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))); | ||
_defineProperty(this, "get", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
var data, devices; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
data = { | ||
inputs: { | ||
audio: [], | ||
video: [] | ||
}, | ||
outputs: { | ||
audio: [] | ||
} | ||
}; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return navigator.mediaDevices.enumerateDevices(); | ||
case 4: | ||
devices = _context2.sent; | ||
devices.forEach(function (device) { | ||
var _device$kind$split = device.kind.split(/(input|output)/gi), | ||
_device$kind$split2 = _slicedToArray(_device$kind$split, 2), | ||
kind = _device$kind$split2[0], | ||
type = _device$kind$split2[1]; | ||
type === 'input' ? data.inputs[kind].push(device) : data.outputs[kind].push(device); | ||
}); | ||
_context2.next = 10; | ||
break; | ||
case 8: | ||
_context2.prev = 8; | ||
_context2.t0 = _context2["catch"](1); | ||
case 10: | ||
return _context2.abrupt("return", data); | ||
case 11: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[1, 8]]); | ||
}))); | ||
_defineProperty(this, "on", function (eventName, cb) { | ||
_this.eventEmitter.on(eventName, cb); | ||
}); | ||
_defineProperty(this, "off", function (eventName, cb) { | ||
_this.eventEmitter.off(eventName, cb); | ||
}); | ||
navigator.mediaDevices.ondevicechange = this.setDevices; | ||
this.setDevices(); | ||
} | ||
_createClass(MediaSources, [{ | ||
key: "devices", | ||
get: function get() { | ||
return this._devices; | ||
} | ||
}]); | ||
return MediaSources; | ||
}(); | ||
var __internalToggleDebugMode = function __internalToggleDebugMode(opts) { | ||
@@ -1572,11 +1639,11 @@ if (opts.enable) { | ||
exports.BadRequestError = BadRequestError; | ||
exports.Call = Call; | ||
exports.ForbiddenError = ForbiddenError; | ||
exports.IncomingSession = IncomingSession; | ||
exports.IncomingCall = IncomingCall; | ||
exports.InternalError = InternalError; | ||
exports.MediaManager = MediaManager; | ||
exports.MediaSources = MediaSources; | ||
exports.MessageBirdClient = MessageBirdClient; | ||
exports.NotAcceptableError = NotAcceptableError; | ||
exports.OutgoingSession = OutgoingSession; | ||
exports.RTCSession = RTCSession; | ||
exports.OutgoingCall = OutgoingCall; | ||
exports.__internalToggleDebugMode = __internalToggleDebugMode; | ||
//# sourceMappingURL=index.js.map |
@@ -16,13 +16,13 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
export var SessionStatus; | ||
export var CallStatus; | ||
(function (SessionStatus) { | ||
SessionStatus["Initial"] = "initial"; | ||
SessionStatus["Ringing"] = "ringing"; | ||
SessionStatus["Connecting"] = "connecting"; | ||
SessionStatus["Failed"] = "failed"; | ||
SessionStatus["Accepted"] = "accepted"; | ||
SessionStatus["Confirmed"] = "confirmed"; | ||
SessionStatus["Disconnected"] = "disconnected"; | ||
})(SessionStatus || (SessionStatus = {})); | ||
(function (CallStatus) { | ||
CallStatus["Initial"] = "initial"; | ||
CallStatus["Ringing"] = "ringing"; | ||
CallStatus["Connecting"] = "connecting"; | ||
CallStatus["Failed"] = "failed"; | ||
CallStatus["Accepted"] = "accepted"; | ||
CallStatus["Confirmed"] = "confirmed"; | ||
CallStatus["Disconnected"] = "disconnected"; | ||
})(CallStatus || (CallStatus = {})); | ||
@@ -29,0 +29,0 @@ export var ClientStatus; |
@@ -19,3 +19,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
export function getSDKVersionHeader() { | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "c71020ed" || 'HEAD'; | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "01296074" || 'HEAD'; | ||
return "SDK-Version: ".concat(version); | ||
@@ -22,0 +22,0 @@ } |
import { debug } from 'jssip'; | ||
export { MessageBirdClient } from "./MessageBirdClient.js"; | ||
export * from "./MediaManager.js"; | ||
export { RTCSession } from "./RTCSession.js"; | ||
export { IncomingSession } from "./IncomingSession.js"; | ||
export * from "./MediaSources.js"; | ||
export * from "./Call.js"; | ||
export * from "./IncomingCall.js"; | ||
export * from "./MediaSources.js"; | ||
export * from "./domain.js"; | ||
export * from "./OutgoingSession.js"; | ||
export * from "./OutgoingCall.js"; | ||
export var __internalToggleDebugMode = function __internalToggleDebugMode(opts) { | ||
@@ -9,0 +10,0 @@ if (opts.enable) { |
@@ -6,4 +6,4 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import UserAgent from "./UserAgent.js"; | ||
import { OutgoingSession } from "./OutgoingSession.js"; | ||
import { IncomingSession } from "./IncomingSession.js"; | ||
import { OutgoingCall } from "./OutgoingCall.js"; | ||
import { IncomingCall } from "./IncomingCall.js"; | ||
import { ClientStatus } from "./domain.js"; | ||
@@ -31,3 +31,3 @@ /** | ||
_defineProperty(this, "handleNewSession", function (sessionEvent) { | ||
var incomingSession = new IncomingSession(_this.userAgent, sessionEvent); | ||
var incomingSession = new IncomingCall(_this.userAgent, sessionEvent); | ||
incomingSession.on('failed', function () { | ||
@@ -82,4 +82,4 @@ _this.eventEmitter.emit('canceled', incomingSession); | ||
}, { | ||
key: "startSession", | ||
value: function startSession(options) { | ||
key: "startCall", | ||
value: function startCall(options) { | ||
if (this.userAgent.status !== ClientStatus.Connected) { | ||
@@ -90,3 +90,3 @@ throw new Error('No active connection. Call `client.setup()` to initialize the device first.'); | ||
this.userAgent.register(); | ||
return new OutgoingSession(this.userAgent, { | ||
return new OutgoingCall(this.userAgent, { | ||
params: options | ||
@@ -93,0 +93,0 @@ }); |
@@ -65,2 +65,8 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
_defineProperty(this, "handleNewSession", function (session) { | ||
if (session.originator === 'remote') { | ||
_this.eventEmitter.emit('session', session); | ||
} | ||
}); | ||
_defineProperty(this, "call", function (options) { | ||
@@ -132,9 +138,2 @@ return _this.sipUA.call(_this.sipAddress, options); | ||
}, { | ||
key: "handleNewSession", | ||
value: function handleNewSession(session) { | ||
if (session.originator === 'remote') { | ||
this.eventEmitter.emit('session', session); | ||
} | ||
} | ||
}, { | ||
key: "sendMessage", | ||
@@ -141,0 +140,0 @@ value: function sendMessage(message, options) { |
@@ -18,3 +18,3 @@ export interface TurnConfig { | ||
} | ||
export declare enum SessionStatus { | ||
export declare enum CallStatus { | ||
Initial = "initial", | ||
@@ -21,0 +21,0 @@ Ringing = "ringing", |
export { MessageBirdClient } from './MessageBirdClient'; | ||
export * from './MediaManager'; | ||
export { RTCSession } from './RTCSession'; | ||
export { IncomingSession } from './IncomingSession'; | ||
export * from './MediaSources'; | ||
export * from './Call'; | ||
export * from './IncomingCall'; | ||
export * from './MediaSources'; | ||
export * from './domain'; | ||
export * from './OutgoingSession'; | ||
export * from './OutgoingCall'; | ||
export declare const __internalToggleDebugMode: (opts: { | ||
enable: boolean; | ||
}) => void; |
@@ -1,4 +0,4 @@ | ||
import { SipUaOptions, UserAgentError } from './UserAgent'; | ||
import { OutgoingSession, StartConnectionOptions } from './OutgoingSession'; | ||
import { IncomingSession } from './IncomingSession'; | ||
import { UserAgentOptions, UserAgentError } from './UserAgent'; | ||
import { OutgoingCall, StartCallParams } from './OutgoingCall'; | ||
import { IncomingCall } from './IncomingCall'; | ||
import { ClientStatus } from './domain'; | ||
@@ -14,6 +14,6 @@ /** | ||
private retryTimeout; | ||
constructor(options?: SipUaOptions); | ||
on(name: 'incoming', callback: (session: IncomingSession) => void): void; | ||
constructor(options?: UserAgentOptions); | ||
on(name: 'incoming', callback: (incomingCall: IncomingCall) => void): void; | ||
on(name: 'error', callback: (error: UserAgentError) => void): void; | ||
on(name: 'canceled', callback: (data: IncomingSession) => void): void; | ||
on(name: 'canceled', callback: (data: IncomingCall) => void): void; | ||
on(name: 'status', callback: (status: ClientStatus) => void): void; | ||
@@ -25,3 +25,3 @@ removeEventListener(name: string, callback: any): void; | ||
destroy(): void; | ||
startSession(options?: StartConnectionOptions): OutgoingSession; | ||
startCall(options?: StartCallParams): OutgoingCall; | ||
private handleNewSession; | ||
@@ -28,0 +28,0 @@ get status(): ClientStatus; |
@@ -1,2 +0,1 @@ | ||
/// <reference path="../../jssip.d.ts" /> | ||
/// <reference types="node" /> | ||
@@ -6,3 +5,3 @@ import { EventEmitter } from 'events'; | ||
import { ForbiddenError, NotAcceptableError, InternalError, ClientStatus } from './domain'; | ||
export interface SipUaOptions { | ||
export interface UserAgentOptions { | ||
host?: string; | ||
@@ -20,3 +19,3 @@ turnHost?: string; | ||
private sipAddress; | ||
constructor({ host }: SipUaOptions); | ||
constructor({ host }: UserAgentOptions); | ||
on(name: 'status', calback: (status: ClientStatus) => void): void; | ||
@@ -23,0 +22,0 @@ on(name: 'error', callback: (error: UserAgentError) => void): void; |
@@ -14,4 +14,2 @@ import { UA, WebSocketInterface, debug } from 'jssip'; | ||
import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; | ||
import { IncomingMessageHeaders } from 'incomingMessageHeaders'; | ||
import { FailureCauses } from 'failureCauses'; | ||
import _regeneratorRuntime from '@babel/runtime/regenerator'; | ||
@@ -48,3 +46,3 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator'; | ||
function getSDKVersionHeader() { | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "c71020ed" ; | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "01296074" ; | ||
return "SDK-Version: ".concat(version); | ||
@@ -88,13 +86,13 @@ } | ||
var SessionStatus; | ||
var CallStatus; | ||
(function (SessionStatus) { | ||
SessionStatus["Initial"] = "initial"; | ||
SessionStatus["Ringing"] = "ringing"; | ||
SessionStatus["Connecting"] = "connecting"; | ||
SessionStatus["Failed"] = "failed"; | ||
SessionStatus["Accepted"] = "accepted"; | ||
SessionStatus["Confirmed"] = "confirmed"; | ||
SessionStatus["Disconnected"] = "disconnected"; | ||
})(SessionStatus || (SessionStatus = {})); | ||
(function (CallStatus) { | ||
CallStatus["Initial"] = "initial"; | ||
CallStatus["Ringing"] = "ringing"; | ||
CallStatus["Connecting"] = "connecting"; | ||
CallStatus["Failed"] = "failed"; | ||
CallStatus["Accepted"] = "accepted"; | ||
CallStatus["Confirmed"] = "confirmed"; | ||
CallStatus["Disconnected"] = "disconnected"; | ||
})(CallStatus || (CallStatus = {})); | ||
@@ -235,2 +233,8 @@ var ClientStatus; | ||
_defineProperty(this, "handleNewSession", function (session) { | ||
if (session.originator === 'remote') { | ||
_this.eventEmitter.emit('session', session); | ||
} | ||
}); | ||
_defineProperty(this, "call", function (options) { | ||
@@ -302,9 +306,2 @@ return _this.sipUA.call(_this.sipAddress, options); | ||
}, { | ||
key: "handleNewSession", | ||
value: function handleNewSession(session) { | ||
if (session.originator === 'remote') { | ||
this.eventEmitter.emit('session', session); | ||
} | ||
} | ||
}, { | ||
key: "sendMessage", | ||
@@ -354,246 +351,44 @@ value: function sendMessage(message, options) { | ||
var MediaManager = function MediaManager(streamTargets, rtcPeerConnection) { | ||
var _this = this; | ||
var IncomingMessageHeaders; | ||
_classCallCheck(this, MediaManager); | ||
(function (IncomingMessageHeaders) { | ||
IncomingMessageHeaders["Via"] = "Via"; | ||
IncomingMessageHeaders["RecordRoute"] = "Record-Route"; | ||
IncomingMessageHeaders["CallID"] = "Call-ID"; | ||
IncomingMessageHeaders["From"] = "From"; | ||
IncomingMessageHeaders["To"] = "To"; | ||
IncomingMessageHeaders["CSeq"] = "CSeq"; | ||
IncomingMessageHeaders["Warning"] = "Warning"; | ||
IncomingMessageHeaders["Server"] = "Server"; | ||
IncomingMessageHeaders["ContentLength"] = "Content-Length"; | ||
})(IncomingMessageHeaders || (IncomingMessageHeaders = {})); | ||
this.streamTargets = streamTargets; | ||
this.rtcPeerConnection = rtcPeerConnection; | ||
var FailureCauses; | ||
_defineProperty(this, "eventEmitter", new EventEmitter()); | ||
(function (FailureCauses) { | ||
FailureCauses["ConnectionError"] = "Connection Error"; | ||
FailureCauses["RequestTimeout"] = "Request Timeout"; | ||
FailureCauses["SIPFailureCode"] = "SIP Failure Code"; | ||
FailureCauses["InternalError"] = "Internal Error"; | ||
FailureCauses["Busy"] = "Busy"; | ||
FailureCauses["Rejected"] = "Rejected"; | ||
FailureCauses["Redirected"] = "Redirected"; | ||
FailureCauses["Unavailable"] = "Unavailable"; | ||
FailureCauses["NotFound"] = "Not Found"; | ||
FailureCauses["AddressIncomplete"] = "Address Incomplete"; | ||
FailureCauses["IncompatibleSDP"] = "Incompatible SDP"; | ||
FailureCauses["MissingSDP"] = "Received a request/response that should have SDP body but did not."; | ||
FailureCauses["AuthenticationError"] = "Authentication Error"; | ||
FailureCauses["InvalidSDPDescriptor"] = "399 SIP \"Invalid SDP descriptor (PJMEDIA_SDP_EINSDP)\""; | ||
FailureCauses["Bye"] = "Terminated"; | ||
FailureCauses["Canceled"] = "Canceled"; | ||
FailureCauses["NoAnswer"] = "No Answer"; | ||
FailureCauses["Expires"] = "Expires"; | ||
FailureCauses["NoACK"] = "No ACK"; | ||
FailureCauses["DialogError"] = "Dialog Error"; | ||
FailureCauses["UserDeniedMediaAccess"] = "User Denied Media Access"; | ||
FailureCauses["BadMediaDescription"] = "Bad Media Description"; | ||
FailureCauses["RTPTimeout"] = "RTP Timeout"; | ||
})(FailureCauses || (FailureCauses = {})); | ||
_defineProperty(this, "_handleDeviceChange", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var devices; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return _this.get(); | ||
case 2: | ||
devices = _context.sent; | ||
_this.eventEmitter.emit('devicechange', devices); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))); | ||
_defineProperty(this, "get", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
var data, devices; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
data = { | ||
inputs: { | ||
audio: [], | ||
video: [] | ||
}, | ||
outputs: { | ||
audio: [] | ||
} | ||
}; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return navigator.mediaDevices.enumerateDevices(); | ||
case 4: | ||
devices = _context2.sent; | ||
devices.forEach(function (device) { | ||
var _device$kind$split = device.kind.split(/(input|output)/gi), | ||
_device$kind$split2 = _slicedToArray(_device$kind$split, 2), | ||
kind = _device$kind$split2[0], | ||
type = _device$kind$split2[1]; | ||
type === 'input' ? data.inputs[kind].push(device) : data.outputs[kind].push(device); | ||
}); | ||
_context2.next = 10; | ||
break; | ||
case 8: | ||
_context2.prev = 8; | ||
_context2.t0 = _context2["catch"](1); | ||
case 10: | ||
return _context2.abrupt("return", data); | ||
case 11: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[1, 8]]); | ||
}))); | ||
_defineProperty(this, "on", function (eventName, cb) { | ||
_this.eventEmitter.on(eventName, cb); | ||
}); | ||
_defineProperty(this, "off", function (eventName, cb) { | ||
_this.eventEmitter.off(eventName, cb); | ||
}); | ||
_defineProperty(this, "set", /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(constraints) { | ||
var senders, nextStream, nextTracks, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _sender$track, sender, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, track; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
if (!(!_this.streamTargets || !_this.rtcPeerConnection)) { | ||
_context3.next = 2; | ||
break; | ||
} | ||
throw new Error('Unable to set user media source. An active RTC connection is required.'); | ||
case 2: | ||
// Get the A/V track senders | ||
senders = _this.rtcPeerConnection.getSenders(); // Apply the desired media constraints | ||
_context3.next = 5; | ||
return navigator.mediaDevices.getUserMedia(constraints); | ||
case 5: | ||
nextStream = _context3.sent; | ||
_context3.next = 8; | ||
return nextStream.getTracks(); | ||
case 8: | ||
nextTracks = _context3.sent; | ||
// Iterate through the list of track senders | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_context3.prev = 12; | ||
_iterator = senders[Symbol.iterator](); | ||
case 14: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context3.next = 46; | ||
break; | ||
} | ||
sender = _step.value; | ||
// Stop each existing track | ||
(_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.stop(); // Replace the tracks that this sender is | ||
// using with the newly specified ones. | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context3.prev = 20; | ||
_iterator2 = nextTracks[Symbol.iterator](); | ||
case 22: | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
_context3.next = 29; | ||
break; | ||
} | ||
track = _step2.value; | ||
_context3.next = 26; | ||
return sender.replaceTrack(track); | ||
case 26: | ||
_iteratorNormalCompletion2 = true; | ||
_context3.next = 22; | ||
break; | ||
case 29: | ||
_context3.next = 35; | ||
break; | ||
case 31: | ||
_context3.prev = 31; | ||
_context3.t0 = _context3["catch"](20); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context3.t0; | ||
case 35: | ||
_context3.prev = 35; | ||
_context3.prev = 36; | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
} | ||
case 38: | ||
_context3.prev = 38; | ||
if (!_didIteratorError2) { | ||
_context3.next = 41; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 41: | ||
return _context3.finish(38); | ||
case 42: | ||
return _context3.finish(35); | ||
case 43: | ||
_iteratorNormalCompletion = true; | ||
_context3.next = 14; | ||
break; | ||
case 46: | ||
_context3.next = 52; | ||
break; | ||
case 48: | ||
_context3.prev = 48; | ||
_context3.t1 = _context3["catch"](12); | ||
_didIteratorError = true; | ||
_iteratorError = _context3.t1; | ||
case 52: | ||
_context3.prev = 52; | ||
_context3.prev = 53; | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
} | ||
case 55: | ||
_context3.prev = 55; | ||
if (!_didIteratorError) { | ||
_context3.next = 58; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 58: | ||
return _context3.finish(55); | ||
case 59: | ||
return _context3.finish(52); | ||
case 60: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, null, [[12, 48, 52, 60], [20, 31, 35, 43], [36,, 38, 42], [53,, 55, 59]]); | ||
})); | ||
return function (_x) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}()); | ||
navigator.mediaDevices.ondevicechange = this._handleDeviceChange; | ||
}; | ||
function createStreamTarget(stream) { | ||
@@ -986,10 +781,12 @@ var video = document.createElement('video'); | ||
var COLLECTION_INTERVAL = 5000; | ||
var RTCSession = /*#__PURE__*/function () { | ||
function RTCSession(sipRtcSession) { | ||
var Call = /*#__PURE__*/function () { | ||
function Call(rtcSession) { | ||
var _this = this; | ||
_classCallCheck(this, RTCSession); | ||
_classCallCheck(this, Call); | ||
_defineProperty(this, "_status", SessionStatus.Connecting); | ||
this.rtcSession = rtcSession; | ||
_defineProperty(this, "_status", CallStatus.Connecting); | ||
_defineProperty(this, "_lastError", null); | ||
@@ -999,14 +796,14 @@ | ||
_defineProperty(this, "sipRTCSession", void 0); | ||
_defineProperty(this, "_callId", null); | ||
_defineProperty(this, "_callId", void 0); | ||
_defineProperty(this, "statsTimeout", 0); | ||
_defineProperty(this, "statsTimeout", void 0); | ||
_defineProperty(this, "streamTargets", []); | ||
_defineProperty(this, "mediaSources", void 0); | ||
_defineProperty(this, "addTrackListener", function () { | ||
if (!_this.rtcSession.connection) { | ||
throw new Error('Connection is not ready to add track listener'); | ||
} | ||
_defineProperty(this, "addTrackListener", function () { | ||
_this.sipRTCSession.connection.addEventListener('track', _this.handleAddTrack); | ||
_this.rtcSession.connection.addEventListener('track', _this.handleAddTrack); | ||
}); | ||
@@ -1027,3 +824,3 @@ | ||
_this.sipRTCSession.sendDTMF(keys); | ||
_this.rtcSession.sendDTMF(keys); | ||
}); | ||
@@ -1034,5 +831,8 @@ | ||
return removeStreamTarget(target); | ||
}); | ||
}); // FIXME: which statuses to allow this? Prevent jssip error | ||
_this.sipRTCSession.terminate(); | ||
if (_this.status !== CallStatus.Failed) { | ||
_this.rtcSession.terminate(); | ||
} | ||
}); | ||
@@ -1053,3 +853,3 @@ | ||
_this.setStatus(SessionStatus.Accepted); | ||
_this.setStatus(CallStatus.Accepted); | ||
}); | ||
@@ -1062,3 +862,3 @@ | ||
_this.setStatus(SessionStatus.Confirmed); | ||
_this.setStatus(CallStatus.Confirmed); | ||
}); | ||
@@ -1069,14 +869,6 @@ | ||
_this.setStatus(SessionStatus.Disconnected); | ||
_this.setStatus(CallStatus.Disconnected); | ||
}); | ||
_defineProperty(this, "handleFailed", function (data) { | ||
if (_this.sipRTCSession) { | ||
try { | ||
_this.getAndSendStats(); | ||
} finally { | ||
clearTimeout(_this.statsTimeout); | ||
} | ||
} | ||
var error; // TODO: Handle specific errors. | ||
@@ -1089,3 +881,3 @@ | ||
_this.setStatus(SessionStatus.Failed); | ||
_this.setStatus(CallStatus.Failed); | ||
@@ -1097,3 +889,3 @@ _this.setError(error); | ||
if (data.originator === 'remote' && data.response.status_code === SipStatusCodes.Ringing) { | ||
_this.setStatus(SessionStatus.Ringing); | ||
_this.setStatus(CallStatus.Ringing); | ||
@@ -1110,7 +902,7 @@ _this._callId = data.response.call_id; | ||
if (muted) { | ||
_this.sipRTCSession.mute({ | ||
_this.rtcSession.mute({ | ||
audio: true | ||
}); | ||
} else { | ||
_this.sipRTCSession.unmute({ | ||
_this.rtcSession.unmute({ | ||
audio: true | ||
@@ -1121,14 +913,14 @@ }); | ||
this.sipRTCSession = sipRtcSession; | ||
this.sipRTCSession.on('accepted', this.handleAccepted); | ||
this.sipRTCSession.on('confirmed', this.handleConfirmed); | ||
this.sipRTCSession.on('ended', this.handleEnded); | ||
this.sipRTCSession.on('failed', this.handleFailed); | ||
this.sipRTCSession.on('progress', this.handleProgress); | ||
this.sipRTCSession.on('muted', this.handleMuteUnmute); | ||
this.sipRTCSession.on('unmuted', this.handleMuteUnmute); | ||
this.mediaSources = new MediaManager(this.streamTargets, sipRtcSession.connection); | ||
rtcSession.on('accepted', this.handleAccepted); | ||
rtcSession.on('confirmed', this.handleConfirmed); | ||
rtcSession.on('ended', this.handleEnded); | ||
rtcSession.on('failed', this.handleFailed); | ||
rtcSession.on('progress', this.handleProgress); | ||
rtcSession.on('muted', this.handleMuteUnmute); | ||
rtcSession.on('unmuted', this.handleMuteUnmute); // Default eventEmitter behavior is to throw when there's no listeners | ||
this.eventEmitter.on('error', function () {}); | ||
} | ||
_createClass(RTCSession, [{ | ||
_createClass(Call, [{ | ||
key: "on", | ||
@@ -1146,8 +938,8 @@ value: function on(name, cb) { | ||
value: function answer(options) { | ||
return this.sipRTCSession.answer(options); | ||
return this.rtcSession.answer(options); | ||
} | ||
}, { | ||
key: "terminate", | ||
value: function terminate() { | ||
return this.sipRTCSession.terminate(); | ||
key: "endCall", | ||
value: function endCall() { | ||
return this.rtcSession.terminate(); | ||
} | ||
@@ -1157,3 +949,3 @@ }, { | ||
value: function setError(error) { | ||
this._lastError = SessionStatus.Failed; | ||
this._lastError = error; | ||
this.eventEmitter.emit('error', error); | ||
@@ -1164,12 +956,6 @@ } | ||
value: function sendInfoMessage(message) { | ||
this.sipRTCSession.sendInfo('application/json', JSON.stringify(message)); | ||
if (this.status === CallStatus.Failed) return; | ||
this.rtcSession.sendInfo('application/json', JSON.stringify(message)); | ||
} | ||
}, { | ||
key: "getStatsReport", | ||
value: function getStatsReport() { | ||
return this.sipRTCSession.connection.getStats().then(function (report) { | ||
return new StatsReport(report); | ||
}); | ||
} | ||
}, { | ||
key: "getAndSendStats", | ||
@@ -1179,4 +965,10 @@ value: function getAndSendStats() { | ||
return this.getStatsReport().then(function (stats) { | ||
return _this2.sendInfoMessage(stats.data); | ||
if (!this.rtcSession.isEstablished()) { | ||
return Promise.reject(new Error('RTC Session was not established')); | ||
} | ||
return this.rtcSession.connection.getStats().then(function (report) { | ||
var statsReport = new StatsReport(report); | ||
_this2.sendInfoMessage(statsReport); | ||
}); | ||
@@ -1194,8 +986,10 @@ } | ||
case 0: | ||
this.statsTimeout = setTimeout(function () { | ||
var isEstablished = _this3.sipRTCSession.isEstablished(); | ||
this.statsTimeout = window.setTimeout(function () { | ||
var isEstablished = _this3.rtcSession.isEstablished(); | ||
if (!isEstablished) return; | ||
_this3.getAndSendStats()["finally"](function () { | ||
_this3.getAndSendStats()["catch"](function () { | ||
window.clearTimeout(_this3.statsTimeout); | ||
})["finally"](function () { | ||
return _this3.getConnectionStats(); | ||
@@ -1220,2 +1014,159 @@ }); | ||
}, { | ||
key: "setInputSource", | ||
value: function () { | ||
var _setInputSource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(constraints) { | ||
var senders, nextStream, nextTracks, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _sender$track, sender, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, track; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (this.rtcSession.connection) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
throw new Error('Could not set media sources. No active call ongoing.'); | ||
case 2: | ||
// Get the A/V track senders | ||
senders = this.rtcSession.connection.getSenders(); // Apply the desired media constraints | ||
_context2.next = 5; | ||
return navigator.mediaDevices.getUserMedia(constraints); | ||
case 5: | ||
nextStream = _context2.sent; | ||
_context2.next = 8; | ||
return nextStream.getTracks(); | ||
case 8: | ||
nextTracks = _context2.sent; | ||
// Iterate through the list of track senders | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_context2.prev = 12; | ||
_iterator = senders[Symbol.iterator](); | ||
case 14: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context2.next = 46; | ||
break; | ||
} | ||
sender = _step.value; | ||
// Stop each existing track | ||
(_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.stop(); // Replace the tracks that this sender is | ||
// using with the newly specified ones. | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context2.prev = 20; | ||
_iterator2 = nextTracks[Symbol.iterator](); | ||
case 22: | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
_context2.next = 29; | ||
break; | ||
} | ||
track = _step2.value; | ||
_context2.next = 26; | ||
return sender.replaceTrack(track); | ||
case 26: | ||
_iteratorNormalCompletion2 = true; | ||
_context2.next = 22; | ||
break; | ||
case 29: | ||
_context2.next = 35; | ||
break; | ||
case 31: | ||
_context2.prev = 31; | ||
_context2.t0 = _context2["catch"](20); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context2.t0; | ||
case 35: | ||
_context2.prev = 35; | ||
_context2.prev = 36; | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
} | ||
case 38: | ||
_context2.prev = 38; | ||
if (!_didIteratorError2) { | ||
_context2.next = 41; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 41: | ||
return _context2.finish(38); | ||
case 42: | ||
return _context2.finish(35); | ||
case 43: | ||
_iteratorNormalCompletion = true; | ||
_context2.next = 14; | ||
break; | ||
case 46: | ||
_context2.next = 52; | ||
break; | ||
case 48: | ||
_context2.prev = 48; | ||
_context2.t1 = _context2["catch"](12); | ||
_didIteratorError = true; | ||
_iteratorError = _context2.t1; | ||
case 52: | ||
_context2.prev = 52; | ||
_context2.prev = 53; | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
} | ||
case 55: | ||
_context2.prev = 55; | ||
if (!_didIteratorError) { | ||
_context2.next = 58; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 58: | ||
return _context2.finish(55); | ||
case 59: | ||
return _context2.finish(52); | ||
case 60: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this, [[12, 48, 52, 60], [20, 31, 35, 43], [36,, 38, 42], [53,, 55, 59]]); | ||
})); | ||
function setInputSource(_x) { | ||
return _setInputSource.apply(this, arguments); | ||
} | ||
return setInputSource; | ||
}() | ||
}, { | ||
key: "status", | ||
@@ -1238,14 +1189,16 @@ get: function get() { | ||
get: function get() { | ||
return this.sipRTCSession.isMuted().audio; | ||
var _ref, _this$rtcSession$isMu; | ||
return (_ref = (_this$rtcSession$isMu = this.rtcSession.isMuted()) === null || _this$rtcSession$isMu === void 0 ? void 0 : _this$rtcSession$isMu.audio) !== null && _ref !== void 0 ? _ref : false; | ||
} | ||
}]); | ||
return RTCSession; | ||
return Call; | ||
}(); | ||
var OutgoingSession = /*#__PURE__*/function () { | ||
function OutgoingSession(ua, options) { | ||
var OutgoingCall = /*#__PURE__*/function () { | ||
function OutgoingCall(ua, options) { | ||
var _this = this; | ||
_classCallCheck(this, OutgoingSession); | ||
_classCallCheck(this, OutgoingCall); | ||
@@ -1259,3 +1212,3 @@ this.ua = ua; | ||
_defineProperty(this, "rtcSession", void 0); | ||
_defineProperty(this, "_call", void 0); | ||
@@ -1280,3 +1233,3 @@ _defineProperty(this, "eventEmitter", new EventEmitter()); | ||
_this.rtcSession = nextSession; | ||
_this._call = nextSession; | ||
@@ -1329,10 +1282,10 @@ _this.eventEmitter.emit('session', nextSession); | ||
this.rtcSession = this.startOutgoingSession(); | ||
this._call = this.startOutgoingSession(); | ||
} | ||
_createClass(OutgoingSession, [{ | ||
_createClass(OutgoingCall, [{ | ||
key: "startOutgoingSession", | ||
value: function startOutgoingSession() { | ||
var params = this.options.params; | ||
var sipSession = this.ua.call({ | ||
var rtcSession = this.ua.call({ | ||
mediaConstraints: { | ||
@@ -1348,6 +1301,6 @@ audio: true, | ||
}); | ||
sipSession.on('sending', this.handleSending); | ||
sipSession.on('progress', this.handleProgress); | ||
sipSession.on('failed', this.handleFailed); | ||
var session = new RTCSession(sipSession); | ||
rtcSession.on('sending', this.handleSending); | ||
rtcSession.on('progress', this.handleProgress); | ||
rtcSession.on('failed', this.handleFailed); | ||
var session = new Call(rtcSession); | ||
session.addTrackListener(); | ||
@@ -1362,15 +1315,22 @@ return session; | ||
}, { | ||
key: "session", | ||
key: "removeEventListener", | ||
value: function removeEventListener(name, cb) { | ||
this.eventEmitter.removeListener(name, cb); | ||
} | ||
}, { | ||
key: "call", | ||
get: function get() { | ||
return this.rtcSession; | ||
return this._call; | ||
} | ||
}]); | ||
return OutgoingSession; | ||
return OutgoingCall; | ||
}(); | ||
var IncomingSession = /*#__PURE__*/function () { | ||
function IncomingSession(ua, sipSession) { | ||
_classCallCheck(this, IncomingSession); | ||
var IncomingCall = /*#__PURE__*/function () { | ||
function IncomingCall(ua, rtcSession) { | ||
var _this = this; | ||
_classCallCheck(this, IncomingCall); | ||
this.ua = ua; | ||
@@ -1382,10 +1342,16 @@ | ||
_defineProperty(this, "session", void 0); | ||
_defineProperty(this, "call", void 0); | ||
this.session = new RTCSession(sipSession.session); | ||
this._displayName = sipSession.request.from.display_name; | ||
sipSession.session.on('failed', this.handleFailed); | ||
_defineProperty(this, "handleFailed", function () { | ||
// Historically, we would always emit canceled when a session failed. Maybe we need better error handling | ||
// In the future, because "failed" may be sent at more points in time | ||
_this.eventEmitter.emit('failed', _this); | ||
}); | ||
this.call = new Call(rtcSession.session); | ||
this._displayName = rtcSession.request.from.display_name; | ||
rtcSession.session.on('failed', this.handleFailed); | ||
} | ||
_createClass(IncomingSession, [{ | ||
_createClass(IncomingCall, [{ | ||
key: "on", | ||
@@ -1396,12 +1362,5 @@ value: function on(name, cb) { | ||
}, { | ||
key: "handleFailed", | ||
value: function handleFailed() { | ||
// Historically, we would always emit canceled when a session failed. Maybe we need better error handling | ||
// In the future, because "failed" may be sent at more points in time | ||
this.eventEmitter.emit('failed', this); | ||
} | ||
}, { | ||
key: "accept", | ||
value: function accept() { | ||
this.session.answer({ | ||
this.call.answer({ | ||
extraHeaders: [], | ||
@@ -1412,4 +1371,4 @@ pcConfig: { | ||
}); | ||
this.session.addTrackListener(); | ||
return this.session; | ||
this.call.addTrackListener(); | ||
return this.call; | ||
} | ||
@@ -1419,3 +1378,3 @@ }, { | ||
value: function reject() { | ||
this.session.terminate(); | ||
this.call.endCall(); | ||
} | ||
@@ -1429,3 +1388,3 @@ }, { | ||
return IncomingSession; | ||
return IncomingCall; | ||
}(); | ||
@@ -1454,3 +1413,3 @@ | ||
_defineProperty(this, "handleNewSession", function (sessionEvent) { | ||
var incomingSession = new IncomingSession(_this.userAgent, sessionEvent); | ||
var incomingSession = new IncomingCall(_this.userAgent, sessionEvent); | ||
incomingSession.on('failed', function () { | ||
@@ -1505,4 +1464,4 @@ _this.eventEmitter.emit('canceled', incomingSession); | ||
}, { | ||
key: "startSession", | ||
value: function startSession(options) { | ||
key: "startCall", | ||
value: function startCall(options) { | ||
if (this.userAgent.status !== ClientStatus.Connected) { | ||
@@ -1513,3 +1472,3 @@ throw new Error('No active connection. Call `client.setup()` to initialize the device first.'); | ||
this.userAgent.register(); | ||
return new OutgoingSession(this.userAgent, { | ||
return new OutgoingCall(this.userAgent, { | ||
params: options | ||
@@ -1533,2 +1492,110 @@ }); | ||
var MediaSources = /*#__PURE__*/function () { | ||
function MediaSources() { | ||
var _this = this; | ||
_classCallCheck(this, MediaSources); | ||
_defineProperty(this, "eventEmitter", new EventEmitter()); | ||
_defineProperty(this, "_devices", { | ||
inputs: { | ||
audio: [], | ||
video: [] | ||
}, | ||
outputs: { | ||
audio: [] | ||
} | ||
}); | ||
_defineProperty(this, "setDevices", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return _this.get(); | ||
case 2: | ||
_this._devices = _context.sent; | ||
_this.eventEmitter.emit('devicechange', _this._devices); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))); | ||
_defineProperty(this, "get", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
var data, devices; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
data = { | ||
inputs: { | ||
audio: [], | ||
video: [] | ||
}, | ||
outputs: { | ||
audio: [] | ||
} | ||
}; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return navigator.mediaDevices.enumerateDevices(); | ||
case 4: | ||
devices = _context2.sent; | ||
devices.forEach(function (device) { | ||
var _device$kind$split = device.kind.split(/(input|output)/gi), | ||
_device$kind$split2 = _slicedToArray(_device$kind$split, 2), | ||
kind = _device$kind$split2[0], | ||
type = _device$kind$split2[1]; | ||
type === 'input' ? data.inputs[kind].push(device) : data.outputs[kind].push(device); | ||
}); | ||
_context2.next = 10; | ||
break; | ||
case 8: | ||
_context2.prev = 8; | ||
_context2.t0 = _context2["catch"](1); | ||
case 10: | ||
return _context2.abrupt("return", data); | ||
case 11: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[1, 8]]); | ||
}))); | ||
_defineProperty(this, "on", function (eventName, cb) { | ||
_this.eventEmitter.on(eventName, cb); | ||
}); | ||
_defineProperty(this, "off", function (eventName, cb) { | ||
_this.eventEmitter.off(eventName, cb); | ||
}); | ||
navigator.mediaDevices.ondevicechange = this.setDevices; | ||
this.setDevices(); | ||
} | ||
_createClass(MediaSources, [{ | ||
key: "devices", | ||
get: function get() { | ||
return this._devices; | ||
} | ||
}]); | ||
return MediaSources; | ||
}(); | ||
var __internalToggleDebugMode = function __internalToggleDebugMode(opts) { | ||
@@ -1542,3 +1609,3 @@ if (opts.enable) { | ||
export { BadRequestError, ClientStatus, ErrorCodes, ForbiddenError, IncomingSession, InternalError, MediaManager, MessageBirdClient, NotAcceptableError, OutgoingSession, RTCSession, SessionStatus, SipStatusCodes, __internalToggleDebugMode }; | ||
export { BadRequestError, Call, CallStatus, ClientStatus, ErrorCodes, ForbiddenError, IncomingCall, InternalError, MediaSources, MessageBirdClient, NotAcceptableError, OutgoingCall, SipStatusCodes, __internalToggleDebugMode }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@messagebird/client", | ||
"version": "1.0.0-next.2", | ||
"version": "1.0.0-next.3", | ||
"license": "UNLICENSED", | ||
@@ -61,6 +61,6 @@ "files": [ | ||
}, | ||
"types": "dist-types/index.d.ts", | ||
"esnext": "dist-src/index.js", | ||
"main": "dist-node/index.js", | ||
"module": "dist-web/index.js", | ||
"types": "dist-types/index.d.ts" | ||
"module": "dist-web/index.js" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
418480
4530