adapter.js 135 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.adapter = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. /*
  3. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by a BSD-style license
  6. * that can be found in the LICENSE file in the root of the source
  7. * tree.
  8. */
  9. /* eslint-env node */
  10. 'use strict';
  11. var _adapter_factory = require("./adapter_factory.js");
  12. var adapter = (0, _adapter_factory.adapterFactory)({
  13. window: typeof window === 'undefined' ? undefined : window
  14. });
  15. module.exports = adapter; // this is the difference from adapter_core.
  16. },{"./adapter_factory.js":2}],2:[function(require,module,exports){
  17. "use strict";
  18. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  19. Object.defineProperty(exports, "__esModule", {
  20. value: true
  21. });
  22. exports.adapterFactory = adapterFactory;
  23. var utils = _interopRequireWildcard(require("./utils"));
  24. var chromeShim = _interopRequireWildcard(require("./chrome/chrome_shim"));
  25. var firefoxShim = _interopRequireWildcard(require("./firefox/firefox_shim"));
  26. var safariShim = _interopRequireWildcard(require("./safari/safari_shim"));
  27. var commonShim = _interopRequireWildcard(require("./common_shim"));
  28. var sdp = _interopRequireWildcard(require("sdp"));
  29. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  30. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  31. /*
  32. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  33. *
  34. * Use of this source code is governed by a BSD-style license
  35. * that can be found in the LICENSE file in the root of the source
  36. * tree.
  37. */
  38. // Browser shims.
  39. // Shimming starts here.
  40. function adapterFactory() {
  41. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  42. window = _ref.window;
  43. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  44. shimChrome: true,
  45. shimFirefox: true,
  46. shimSafari: true
  47. };
  48. // Utils.
  49. var logging = utils.log;
  50. var browserDetails = utils.detectBrowser(window);
  51. var adapter = {
  52. browserDetails: browserDetails,
  53. commonShim: commonShim,
  54. extractVersion: utils.extractVersion,
  55. disableLog: utils.disableLog,
  56. disableWarnings: utils.disableWarnings,
  57. // Expose sdp as a convenience. For production apps include directly.
  58. sdp: sdp
  59. };
  60. // Shim browser if found.
  61. switch (browserDetails.browser) {
  62. case 'chrome':
  63. if (!chromeShim || !chromeShim.shimPeerConnection || !options.shimChrome) {
  64. logging('Chrome shim is not included in this adapter release.');
  65. return adapter;
  66. }
  67. if (browserDetails.version === null) {
  68. logging('Chrome shim can not determine version, not shimming.');
  69. return adapter;
  70. }
  71. logging('adapter.js shimming chrome.');
  72. // Export to the adapter global object visible in the browser.
  73. adapter.browserShim = chromeShim;
  74. // Must be called before shimPeerConnection.
  75. commonShim.shimAddIceCandidateNullOrEmpty(window, browserDetails);
  76. commonShim.shimParameterlessSetLocalDescription(window, browserDetails);
  77. chromeShim.shimGetUserMedia(window, browserDetails);
  78. chromeShim.shimMediaStream(window, browserDetails);
  79. chromeShim.shimPeerConnection(window, browserDetails);
  80. chromeShim.shimOnTrack(window, browserDetails);
  81. chromeShim.shimAddTrackRemoveTrack(window, browserDetails);
  82. chromeShim.shimGetSendersWithDtmf(window, browserDetails);
  83. chromeShim.shimGetStats(window, browserDetails);
  84. chromeShim.shimSenderReceiverGetStats(window, browserDetails);
  85. chromeShim.fixNegotiationNeeded(window, browserDetails);
  86. commonShim.shimRTCIceCandidate(window, browserDetails);
  87. commonShim.shimRTCIceCandidateRelayProtocol(window, browserDetails);
  88. commonShim.shimConnectionState(window, browserDetails);
  89. commonShim.shimMaxMessageSize(window, browserDetails);
  90. commonShim.shimSendThrowTypeError(window, browserDetails);
  91. commonShim.removeExtmapAllowMixed(window, browserDetails);
  92. break;
  93. case 'firefox':
  94. if (!firefoxShim || !firefoxShim.shimPeerConnection || !options.shimFirefox) {
  95. logging('Firefox shim is not included in this adapter release.');
  96. return adapter;
  97. }
  98. logging('adapter.js shimming firefox.');
  99. // Export to the adapter global object visible in the browser.
  100. adapter.browserShim = firefoxShim;
  101. // Must be called before shimPeerConnection.
  102. commonShim.shimAddIceCandidateNullOrEmpty(window, browserDetails);
  103. commonShim.shimParameterlessSetLocalDescription(window, browserDetails);
  104. firefoxShim.shimGetUserMedia(window, browserDetails);
  105. firefoxShim.shimPeerConnection(window, browserDetails);
  106. firefoxShim.shimOnTrack(window, browserDetails);
  107. firefoxShim.shimRemoveStream(window, browserDetails);
  108. firefoxShim.shimSenderGetStats(window, browserDetails);
  109. firefoxShim.shimReceiverGetStats(window, browserDetails);
  110. firefoxShim.shimRTCDataChannel(window, browserDetails);
  111. firefoxShim.shimAddTransceiver(window, browserDetails);
  112. firefoxShim.shimGetParameters(window, browserDetails);
  113. firefoxShim.shimCreateOffer(window, browserDetails);
  114. firefoxShim.shimCreateAnswer(window, browserDetails);
  115. commonShim.shimRTCIceCandidate(window, browserDetails);
  116. commonShim.shimConnectionState(window, browserDetails);
  117. commonShim.shimMaxMessageSize(window, browserDetails);
  118. commonShim.shimSendThrowTypeError(window, browserDetails);
  119. break;
  120. case 'safari':
  121. if (!safariShim || !options.shimSafari) {
  122. logging('Safari shim is not included in this adapter release.');
  123. return adapter;
  124. }
  125. logging('adapter.js shimming safari.');
  126. // Export to the adapter global object visible in the browser.
  127. adapter.browserShim = safariShim;
  128. // Must be called before shimCallbackAPI.
  129. commonShim.shimAddIceCandidateNullOrEmpty(window, browserDetails);
  130. commonShim.shimParameterlessSetLocalDescription(window, browserDetails);
  131. safariShim.shimRTCIceServerUrls(window, browserDetails);
  132. safariShim.shimCreateOfferLegacy(window, browserDetails);
  133. safariShim.shimCallbacksAPI(window, browserDetails);
  134. safariShim.shimLocalStreamsAPI(window, browserDetails);
  135. safariShim.shimRemoteStreamsAPI(window, browserDetails);
  136. safariShim.shimTrackEventTransceiver(window, browserDetails);
  137. safariShim.shimGetUserMedia(window, browserDetails);
  138. safariShim.shimAudioContext(window, browserDetails);
  139. commonShim.shimRTCIceCandidate(window, browserDetails);
  140. commonShim.shimRTCIceCandidateRelayProtocol(window, browserDetails);
  141. commonShim.shimMaxMessageSize(window, browserDetails);
  142. commonShim.shimSendThrowTypeError(window, browserDetails);
  143. commonShim.removeExtmapAllowMixed(window, browserDetails);
  144. break;
  145. default:
  146. logging('Unsupported browser!');
  147. break;
  148. }
  149. return adapter;
  150. }
  151. },{"./chrome/chrome_shim":3,"./common_shim":6,"./firefox/firefox_shim":7,"./safari/safari_shim":10,"./utils":11,"sdp":12}],3:[function(require,module,exports){
  152. /*
  153. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  154. *
  155. * Use of this source code is governed by a BSD-style license
  156. * that can be found in the LICENSE file in the root of the source
  157. * tree.
  158. */
  159. /* eslint-env node */
  160. 'use strict';
  161. Object.defineProperty(exports, "__esModule", {
  162. value: true
  163. });
  164. exports.fixNegotiationNeeded = fixNegotiationNeeded;
  165. exports.shimAddTrackRemoveTrack = shimAddTrackRemoveTrack;
  166. exports.shimAddTrackRemoveTrackWithNative = shimAddTrackRemoveTrackWithNative;
  167. Object.defineProperty(exports, "shimGetDisplayMedia", {
  168. enumerable: true,
  169. get: function get() {
  170. return _getdisplaymedia.shimGetDisplayMedia;
  171. }
  172. });
  173. exports.shimGetSendersWithDtmf = shimGetSendersWithDtmf;
  174. exports.shimGetStats = shimGetStats;
  175. Object.defineProperty(exports, "shimGetUserMedia", {
  176. enumerable: true,
  177. get: function get() {
  178. return _getusermedia.shimGetUserMedia;
  179. }
  180. });
  181. exports.shimMediaStream = shimMediaStream;
  182. exports.shimOnTrack = shimOnTrack;
  183. exports.shimPeerConnection = shimPeerConnection;
  184. exports.shimSenderReceiverGetStats = shimSenderReceiverGetStats;
  185. var utils = _interopRequireWildcard(require("../utils.js"));
  186. var _getusermedia = require("./getusermedia");
  187. var _getdisplaymedia = require("./getdisplaymedia");
  188. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  189. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  190. function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  191. function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
  192. function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
  193. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  194. function shimMediaStream(window) {
  195. window.MediaStream = window.MediaStream || window.webkitMediaStream;
  196. }
  197. function shimOnTrack(window) {
  198. if (_typeof(window) === 'object' && window.RTCPeerConnection && !('ontrack' in window.RTCPeerConnection.prototype)) {
  199. Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', {
  200. get: function get() {
  201. return this._ontrack;
  202. },
  203. set: function set(f) {
  204. if (this._ontrack) {
  205. this.removeEventListener('track', this._ontrack);
  206. }
  207. this.addEventListener('track', this._ontrack = f);
  208. },
  209. enumerable: true,
  210. configurable: true
  211. });
  212. var origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
  213. window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription() {
  214. var _this = this;
  215. if (!this._ontrackpoly) {
  216. this._ontrackpoly = function (e) {
  217. // onaddstream does not fire when a track is added to an existing
  218. // stream. But stream.onaddtrack is implemented so we use that.
  219. e.stream.addEventListener('addtrack', function (te) {
  220. var receiver;
  221. if (window.RTCPeerConnection.prototype.getReceivers) {
  222. receiver = _this.getReceivers().find(function (r) {
  223. return r.track && r.track.id === te.track.id;
  224. });
  225. } else {
  226. receiver = {
  227. track: te.track
  228. };
  229. }
  230. var event = new Event('track');
  231. event.track = te.track;
  232. event.receiver = receiver;
  233. event.transceiver = {
  234. receiver: receiver
  235. };
  236. event.streams = [e.stream];
  237. _this.dispatchEvent(event);
  238. });
  239. e.stream.getTracks().forEach(function (track) {
  240. var receiver;
  241. if (window.RTCPeerConnection.prototype.getReceivers) {
  242. receiver = _this.getReceivers().find(function (r) {
  243. return r.track && r.track.id === track.id;
  244. });
  245. } else {
  246. receiver = {
  247. track: track
  248. };
  249. }
  250. var event = new Event('track');
  251. event.track = track;
  252. event.receiver = receiver;
  253. event.transceiver = {
  254. receiver: receiver
  255. };
  256. event.streams = [e.stream];
  257. _this.dispatchEvent(event);
  258. });
  259. };
  260. this.addEventListener('addstream', this._ontrackpoly);
  261. }
  262. return origSetRemoteDescription.apply(this, arguments);
  263. };
  264. } else {
  265. // even if RTCRtpTransceiver is in window, it is only used and
  266. // emitted in unified-plan. Unfortunately this means we need
  267. // to unconditionally wrap the event.
  268. utils.wrapPeerConnectionEvent(window, 'track', function (e) {
  269. if (!e.transceiver) {
  270. Object.defineProperty(e, 'transceiver', {
  271. value: {
  272. receiver: e.receiver
  273. }
  274. });
  275. }
  276. return e;
  277. });
  278. }
  279. }
  280. function shimGetSendersWithDtmf(window) {
  281. // Overrides addTrack/removeTrack, depends on shimAddTrackRemoveTrack.
  282. if (_typeof(window) === 'object' && window.RTCPeerConnection && !('getSenders' in window.RTCPeerConnection.prototype) && 'createDTMFSender' in window.RTCPeerConnection.prototype) {
  283. var shimSenderWithDtmf = function shimSenderWithDtmf(pc, track) {
  284. return {
  285. track: track,
  286. get dtmf() {
  287. if (this._dtmf === undefined) {
  288. if (track.kind === 'audio') {
  289. this._dtmf = pc.createDTMFSender(track);
  290. } else {
  291. this._dtmf = null;
  292. }
  293. }
  294. return this._dtmf;
  295. },
  296. _pc: pc
  297. };
  298. };
  299. // augment addTrack when getSenders is not available.
  300. if (!window.RTCPeerConnection.prototype.getSenders) {
  301. window.RTCPeerConnection.prototype.getSenders = function getSenders() {
  302. this._senders = this._senders || [];
  303. return this._senders.slice(); // return a copy of the internal state.
  304. };
  305. var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
  306. window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
  307. var sender = origAddTrack.apply(this, arguments);
  308. if (!sender) {
  309. sender = shimSenderWithDtmf(this, track);
  310. this._senders.push(sender);
  311. }
  312. return sender;
  313. };
  314. var origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
  315. window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
  316. origRemoveTrack.apply(this, arguments);
  317. var idx = this._senders.indexOf(sender);
  318. if (idx !== -1) {
  319. this._senders.splice(idx, 1);
  320. }
  321. };
  322. }
  323. var origAddStream = window.RTCPeerConnection.prototype.addStream;
  324. window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
  325. var _this2 = this;
  326. this._senders = this._senders || [];
  327. origAddStream.apply(this, [stream]);
  328. stream.getTracks().forEach(function (track) {
  329. _this2._senders.push(shimSenderWithDtmf(_this2, track));
  330. });
  331. };
  332. var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
  333. window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
  334. var _this3 = this;
  335. this._senders = this._senders || [];
  336. origRemoveStream.apply(this, [stream]);
  337. stream.getTracks().forEach(function (track) {
  338. var sender = _this3._senders.find(function (s) {
  339. return s.track === track;
  340. });
  341. if (sender) {
  342. // remove sender
  343. _this3._senders.splice(_this3._senders.indexOf(sender), 1);
  344. }
  345. });
  346. };
  347. } else if (_typeof(window) === 'object' && window.RTCPeerConnection && 'getSenders' in window.RTCPeerConnection.prototype && 'createDTMFSender' in window.RTCPeerConnection.prototype && window.RTCRtpSender && !('dtmf' in window.RTCRtpSender.prototype)) {
  348. var origGetSenders = window.RTCPeerConnection.prototype.getSenders;
  349. window.RTCPeerConnection.prototype.getSenders = function getSenders() {
  350. var _this4 = this;
  351. var senders = origGetSenders.apply(this, []);
  352. senders.forEach(function (sender) {
  353. return sender._pc = _this4;
  354. });
  355. return senders;
  356. };
  357. Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', {
  358. get: function get() {
  359. if (this._dtmf === undefined) {
  360. if (this.track.kind === 'audio') {
  361. this._dtmf = this._pc.createDTMFSender(this.track);
  362. } else {
  363. this._dtmf = null;
  364. }
  365. }
  366. return this._dtmf;
  367. }
  368. });
  369. }
  370. }
  371. function shimGetStats(window) {
  372. if (!window.RTCPeerConnection) {
  373. return;
  374. }
  375. var origGetStats = window.RTCPeerConnection.prototype.getStats;
  376. window.RTCPeerConnection.prototype.getStats = function getStats() {
  377. var _this5 = this;
  378. var _arguments = Array.prototype.slice.call(arguments),
  379. selector = _arguments[0],
  380. onSucc = _arguments[1],
  381. onErr = _arguments[2];
  382. // If selector is a function then we are in the old style stats so just
  383. // pass back the original getStats format to avoid breaking old users.
  384. if (arguments.length > 0 && typeof selector === 'function') {
  385. return origGetStats.apply(this, arguments);
  386. }
  387. // When spec-style getStats is supported, return those when called with
  388. // either no arguments or the selector argument is null.
  389. if (origGetStats.length === 0 && (arguments.length === 0 || typeof selector !== 'function')) {
  390. return origGetStats.apply(this, []);
  391. }
  392. var fixChromeStats_ = function fixChromeStats_(response) {
  393. var standardReport = {};
  394. var reports = response.result();
  395. reports.forEach(function (report) {
  396. var standardStats = {
  397. id: report.id,
  398. timestamp: report.timestamp,
  399. type: {
  400. localcandidate: 'local-candidate',
  401. remotecandidate: 'remote-candidate'
  402. }[report.type] || report.type
  403. };
  404. report.names().forEach(function (name) {
  405. standardStats[name] = report.stat(name);
  406. });
  407. standardReport[standardStats.id] = standardStats;
  408. });
  409. return standardReport;
  410. };
  411. // shim getStats with maplike support
  412. var makeMapStats = function makeMapStats(stats) {
  413. return new Map(Object.keys(stats).map(function (key) {
  414. return [key, stats[key]];
  415. }));
  416. };
  417. if (arguments.length >= 2) {
  418. var successCallbackWrapper_ = function successCallbackWrapper_(response) {
  419. onSucc(makeMapStats(fixChromeStats_(response)));
  420. };
  421. return origGetStats.apply(this, [successCallbackWrapper_, selector]);
  422. }
  423. // promise-support
  424. return new Promise(function (resolve, reject) {
  425. origGetStats.apply(_this5, [function (response) {
  426. resolve(makeMapStats(fixChromeStats_(response)));
  427. }, reject]);
  428. }).then(onSucc, onErr);
  429. };
  430. }
  431. function shimSenderReceiverGetStats(window) {
  432. if (!(_typeof(window) === 'object' && window.RTCPeerConnection && window.RTCRtpSender && window.RTCRtpReceiver)) {
  433. return;
  434. }
  435. // shim sender stats.
  436. if (!('getStats' in window.RTCRtpSender.prototype)) {
  437. var origGetSenders = window.RTCPeerConnection.prototype.getSenders;
  438. if (origGetSenders) {
  439. window.RTCPeerConnection.prototype.getSenders = function getSenders() {
  440. var _this6 = this;
  441. var senders = origGetSenders.apply(this, []);
  442. senders.forEach(function (sender) {
  443. return sender._pc = _this6;
  444. });
  445. return senders;
  446. };
  447. }
  448. var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
  449. if (origAddTrack) {
  450. window.RTCPeerConnection.prototype.addTrack = function addTrack() {
  451. var sender = origAddTrack.apply(this, arguments);
  452. sender._pc = this;
  453. return sender;
  454. };
  455. }
  456. window.RTCRtpSender.prototype.getStats = function getStats() {
  457. var sender = this;
  458. return this._pc.getStats().then(function (result) {
  459. return (
  460. /* Note: this will include stats of all senders that
  461. * send a track with the same id as sender.track as
  462. * it is not possible to identify the RTCRtpSender.
  463. */
  464. utils.filterStats(result, sender.track, true)
  465. );
  466. });
  467. };
  468. }
  469. // shim receiver stats.
  470. if (!('getStats' in window.RTCRtpReceiver.prototype)) {
  471. var origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;
  472. if (origGetReceivers) {
  473. window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {
  474. var _this7 = this;
  475. var receivers = origGetReceivers.apply(this, []);
  476. receivers.forEach(function (receiver) {
  477. return receiver._pc = _this7;
  478. });
  479. return receivers;
  480. };
  481. }
  482. utils.wrapPeerConnectionEvent(window, 'track', function (e) {
  483. e.receiver._pc = e.srcElement;
  484. return e;
  485. });
  486. window.RTCRtpReceiver.prototype.getStats = function getStats() {
  487. var receiver = this;
  488. return this._pc.getStats().then(function (result) {
  489. return utils.filterStats(result, receiver.track, false);
  490. });
  491. };
  492. }
  493. if (!('getStats' in window.RTCRtpSender.prototype && 'getStats' in window.RTCRtpReceiver.prototype)) {
  494. return;
  495. }
  496. // shim RTCPeerConnection.getStats(track).
  497. var origGetStats = window.RTCPeerConnection.prototype.getStats;
  498. window.RTCPeerConnection.prototype.getStats = function getStats() {
  499. if (arguments.length > 0 && arguments[0] instanceof window.MediaStreamTrack) {
  500. var track = arguments[0];
  501. var sender;
  502. var receiver;
  503. var err;
  504. this.getSenders().forEach(function (s) {
  505. if (s.track === track) {
  506. if (sender) {
  507. err = true;
  508. } else {
  509. sender = s;
  510. }
  511. }
  512. });
  513. this.getReceivers().forEach(function (r) {
  514. if (r.track === track) {
  515. if (receiver) {
  516. err = true;
  517. } else {
  518. receiver = r;
  519. }
  520. }
  521. return r.track === track;
  522. });
  523. if (err || sender && receiver) {
  524. return Promise.reject(new DOMException('There are more than one sender or receiver for the track.', 'InvalidAccessError'));
  525. } else if (sender) {
  526. return sender.getStats();
  527. } else if (receiver) {
  528. return receiver.getStats();
  529. }
  530. return Promise.reject(new DOMException('There is no sender or receiver for the track.', 'InvalidAccessError'));
  531. }
  532. return origGetStats.apply(this, arguments);
  533. };
  534. }
  535. function shimAddTrackRemoveTrackWithNative(window) {
  536. // shim addTrack/removeTrack with native variants in order to make
  537. // the interactions with legacy getLocalStreams behave as in other browsers.
  538. // Keeps a mapping stream.id => [stream, rtpsenders...]
  539. window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
  540. var _this8 = this;
  541. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  542. return Object.keys(this._shimmedLocalStreams).map(function (streamId) {
  543. return _this8._shimmedLocalStreams[streamId][0];
  544. });
  545. };
  546. var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
  547. window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
  548. if (!stream) {
  549. return origAddTrack.apply(this, arguments);
  550. }
  551. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  552. var sender = origAddTrack.apply(this, arguments);
  553. if (!this._shimmedLocalStreams[stream.id]) {
  554. this._shimmedLocalStreams[stream.id] = [stream, sender];
  555. } else if (this._shimmedLocalStreams[stream.id].indexOf(sender) === -1) {
  556. this._shimmedLocalStreams[stream.id].push(sender);
  557. }
  558. return sender;
  559. };
  560. var origAddStream = window.RTCPeerConnection.prototype.addStream;
  561. window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
  562. var _this9 = this;
  563. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  564. stream.getTracks().forEach(function (track) {
  565. var alreadyExists = _this9.getSenders().find(function (s) {
  566. return s.track === track;
  567. });
  568. if (alreadyExists) {
  569. throw new DOMException('Track already exists.', 'InvalidAccessError');
  570. }
  571. });
  572. var existingSenders = this.getSenders();
  573. origAddStream.apply(this, arguments);
  574. var newSenders = this.getSenders().filter(function (newSender) {
  575. return existingSenders.indexOf(newSender) === -1;
  576. });
  577. this._shimmedLocalStreams[stream.id] = [stream].concat(newSenders);
  578. };
  579. var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
  580. window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
  581. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  582. delete this._shimmedLocalStreams[stream.id];
  583. return origRemoveStream.apply(this, arguments);
  584. };
  585. var origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
  586. window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
  587. var _this10 = this;
  588. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  589. if (sender) {
  590. Object.keys(this._shimmedLocalStreams).forEach(function (streamId) {
  591. var idx = _this10._shimmedLocalStreams[streamId].indexOf(sender);
  592. if (idx !== -1) {
  593. _this10._shimmedLocalStreams[streamId].splice(idx, 1);
  594. }
  595. if (_this10._shimmedLocalStreams[streamId].length === 1) {
  596. delete _this10._shimmedLocalStreams[streamId];
  597. }
  598. });
  599. }
  600. return origRemoveTrack.apply(this, arguments);
  601. };
  602. }
  603. function shimAddTrackRemoveTrack(window, browserDetails) {
  604. if (!window.RTCPeerConnection) {
  605. return;
  606. }
  607. // shim addTrack and removeTrack.
  608. if (window.RTCPeerConnection.prototype.addTrack && browserDetails.version >= 65) {
  609. return shimAddTrackRemoveTrackWithNative(window);
  610. }
  611. // also shim pc.getLocalStreams when addTrack is shimmed
  612. // to return the original streams.
  613. var origGetLocalStreams = window.RTCPeerConnection.prototype.getLocalStreams;
  614. window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
  615. var _this11 = this;
  616. var nativeStreams = origGetLocalStreams.apply(this);
  617. this._reverseStreams = this._reverseStreams || {};
  618. return nativeStreams.map(function (stream) {
  619. return _this11._reverseStreams[stream.id];
  620. });
  621. };
  622. var origAddStream = window.RTCPeerConnection.prototype.addStream;
  623. window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
  624. var _this12 = this;
  625. this._streams = this._streams || {};
  626. this._reverseStreams = this._reverseStreams || {};
  627. stream.getTracks().forEach(function (track) {
  628. var alreadyExists = _this12.getSenders().find(function (s) {
  629. return s.track === track;
  630. });
  631. if (alreadyExists) {
  632. throw new DOMException('Track already exists.', 'InvalidAccessError');
  633. }
  634. });
  635. // Add identity mapping for consistency with addTrack.
  636. // Unless this is being used with a stream from addTrack.
  637. if (!this._reverseStreams[stream.id]) {
  638. var newStream = new window.MediaStream(stream.getTracks());
  639. this._streams[stream.id] = newStream;
  640. this._reverseStreams[newStream.id] = stream;
  641. stream = newStream;
  642. }
  643. origAddStream.apply(this, [stream]);
  644. };
  645. var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
  646. window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
  647. this._streams = this._streams || {};
  648. this._reverseStreams = this._reverseStreams || {};
  649. origRemoveStream.apply(this, [this._streams[stream.id] || stream]);
  650. delete this._reverseStreams[this._streams[stream.id] ? this._streams[stream.id].id : stream.id];
  651. delete this._streams[stream.id];
  652. };
  653. window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
  654. var _this13 = this;
  655. if (this.signalingState === 'closed') {
  656. throw new DOMException('The RTCPeerConnection\'s signalingState is \'closed\'.', 'InvalidStateError');
  657. }
  658. var streams = [].slice.call(arguments, 1);
  659. if (streams.length !== 1 || !streams[0].getTracks().find(function (t) {
  660. return t === track;
  661. })) {
  662. // this is not fully correct but all we can manage without
  663. // [[associated MediaStreams]] internal slot.
  664. throw new DOMException('The adapter.js addTrack polyfill only supports a single ' + ' stream which is associated with the specified track.', 'NotSupportedError');
  665. }
  666. var alreadyExists = this.getSenders().find(function (s) {
  667. return s.track === track;
  668. });
  669. if (alreadyExists) {
  670. throw new DOMException('Track already exists.', 'InvalidAccessError');
  671. }
  672. this._streams = this._streams || {};
  673. this._reverseStreams = this._reverseStreams || {};
  674. var oldStream = this._streams[stream.id];
  675. if (oldStream) {
  676. // this is using odd Chrome behaviour, use with caution:
  677. // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
  678. // Note: we rely on the high-level addTrack/dtmf shim to
  679. // create the sender with a dtmf sender.
  680. oldStream.addTrack(track);
  681. // Trigger ONN async.
  682. Promise.resolve().then(function () {
  683. _this13.dispatchEvent(new Event('negotiationneeded'));
  684. });
  685. } else {
  686. var newStream = new window.MediaStream([track]);
  687. this._streams[stream.id] = newStream;
  688. this._reverseStreams[newStream.id] = stream;
  689. this.addStream(newStream);
  690. }
  691. return this.getSenders().find(function (s) {
  692. return s.track === track;
  693. });
  694. };
  695. // replace the internal stream id with the external one and
  696. // vice versa.
  697. function replaceInternalStreamId(pc, description) {
  698. var sdp = description.sdp;
  699. Object.keys(pc._reverseStreams || []).forEach(function (internalId) {
  700. var externalStream = pc._reverseStreams[internalId];
  701. var internalStream = pc._streams[externalStream.id];
  702. sdp = sdp.replace(new RegExp(internalStream.id, 'g'), externalStream.id);
  703. });
  704. return new RTCSessionDescription({
  705. type: description.type,
  706. sdp: sdp
  707. });
  708. }
  709. function replaceExternalStreamId(pc, description) {
  710. var sdp = description.sdp;
  711. Object.keys(pc._reverseStreams || []).forEach(function (internalId) {
  712. var externalStream = pc._reverseStreams[internalId];
  713. var internalStream = pc._streams[externalStream.id];
  714. sdp = sdp.replace(new RegExp(externalStream.id, 'g'), internalStream.id);
  715. });
  716. return new RTCSessionDescription({
  717. type: description.type,
  718. sdp: sdp
  719. });
  720. }
  721. ['createOffer', 'createAnswer'].forEach(function (method) {
  722. var nativeMethod = window.RTCPeerConnection.prototype[method];
  723. var methodObj = _defineProperty({}, method, function () {
  724. var _this14 = this;
  725. var args = arguments;
  726. var isLegacyCall = arguments.length && typeof arguments[0] === 'function';
  727. if (isLegacyCall) {
  728. return nativeMethod.apply(this, [function (description) {
  729. var desc = replaceInternalStreamId(_this14, description);
  730. args[0].apply(null, [desc]);
  731. }, function (err) {
  732. if (args[1]) {
  733. args[1].apply(null, err);
  734. }
  735. }, arguments[2]]);
  736. }
  737. return nativeMethod.apply(this, arguments).then(function (description) {
  738. return replaceInternalStreamId(_this14, description);
  739. });
  740. });
  741. window.RTCPeerConnection.prototype[method] = methodObj[method];
  742. });
  743. var origSetLocalDescription = window.RTCPeerConnection.prototype.setLocalDescription;
  744. window.RTCPeerConnection.prototype.setLocalDescription = function setLocalDescription() {
  745. if (!arguments.length || !arguments[0].type) {
  746. return origSetLocalDescription.apply(this, arguments);
  747. }
  748. arguments[0] = replaceExternalStreamId(this, arguments[0]);
  749. return origSetLocalDescription.apply(this, arguments);
  750. };
  751. // TODO: mangle getStats: https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamstats-streamidentifier
  752. var origLocalDescription = Object.getOwnPropertyDescriptor(window.RTCPeerConnection.prototype, 'localDescription');
  753. Object.defineProperty(window.RTCPeerConnection.prototype, 'localDescription', {
  754. get: function get() {
  755. var description = origLocalDescription.get.apply(this);
  756. if (description.type === '') {
  757. return description;
  758. }
  759. return replaceInternalStreamId(this, description);
  760. }
  761. });
  762. window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
  763. var _this15 = this;
  764. if (this.signalingState === 'closed') {
  765. throw new DOMException('The RTCPeerConnection\'s signalingState is \'closed\'.', 'InvalidStateError');
  766. }
  767. // We can not yet check for sender instanceof RTCRtpSender
  768. // since we shim RTPSender. So we check if sender._pc is set.
  769. if (!sender._pc) {
  770. throw new DOMException('Argument 1 of RTCPeerConnection.removeTrack ' + 'does not implement interface RTCRtpSender.', 'TypeError');
  771. }
  772. var isLocal = sender._pc === this;
  773. if (!isLocal) {
  774. throw new DOMException('Sender was not created by this connection.', 'InvalidAccessError');
  775. }
  776. // Search for the native stream the senders track belongs to.
  777. this._streams = this._streams || {};
  778. var stream;
  779. Object.keys(this._streams).forEach(function (streamid) {
  780. var hasTrack = _this15._streams[streamid].getTracks().find(function (track) {
  781. return sender.track === track;
  782. });
  783. if (hasTrack) {
  784. stream = _this15._streams[streamid];
  785. }
  786. });
  787. if (stream) {
  788. if (stream.getTracks().length === 1) {
  789. // if this is the last track of the stream, remove the stream. This
  790. // takes care of any shimmed _senders.
  791. this.removeStream(this._reverseStreams[stream.id]);
  792. } else {
  793. // relying on the same odd chrome behaviour as above.
  794. stream.removeTrack(sender.track);
  795. }
  796. this.dispatchEvent(new Event('negotiationneeded'));
  797. }
  798. };
  799. }
  800. function shimPeerConnection(window, browserDetails) {
  801. if (!window.RTCPeerConnection && window.webkitRTCPeerConnection) {
  802. // very basic support for old versions.
  803. window.RTCPeerConnection = window.webkitRTCPeerConnection;
  804. }
  805. if (!window.RTCPeerConnection) {
  806. return;
  807. }
  808. // shim implicit creation of RTCSessionDescription/RTCIceCandidate
  809. if (browserDetails.version < 53) {
  810. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'].forEach(function (method) {
  811. var nativeMethod = window.RTCPeerConnection.prototype[method];
  812. var methodObj = _defineProperty({}, method, function () {
  813. arguments[0] = new (method === 'addIceCandidate' ? window.RTCIceCandidate : window.RTCSessionDescription)(arguments[0]);
  814. return nativeMethod.apply(this, arguments);
  815. });
  816. window.RTCPeerConnection.prototype[method] = methodObj[method];
  817. });
  818. }
  819. }
  820. // Attempt to fix ONN in plan-b mode.
  821. function fixNegotiationNeeded(window, browserDetails) {
  822. utils.wrapPeerConnectionEvent(window, 'negotiationneeded', function (e) {
  823. var pc = e.target;
  824. if (browserDetails.version < 72 || pc.getConfiguration && pc.getConfiguration().sdpSemantics === 'plan-b') {
  825. if (pc.signalingState !== 'stable') {
  826. return;
  827. }
  828. }
  829. return e;
  830. });
  831. }
  832. },{"../utils.js":11,"./getdisplaymedia":4,"./getusermedia":5}],4:[function(require,module,exports){
  833. /*
  834. * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.
  835. *
  836. * Use of this source code is governed by a BSD-style license
  837. * that can be found in the LICENSE file in the root of the source
  838. * tree.
  839. */
  840. /* eslint-env node */
  841. 'use strict';
  842. Object.defineProperty(exports, "__esModule", {
  843. value: true
  844. });
  845. exports.shimGetDisplayMedia = shimGetDisplayMedia;
  846. function shimGetDisplayMedia(window, getSourceId) {
  847. if (window.navigator.mediaDevices && 'getDisplayMedia' in window.navigator.mediaDevices) {
  848. return;
  849. }
  850. if (!window.navigator.mediaDevices) {
  851. return;
  852. }
  853. // getSourceId is a function that returns a promise resolving with
  854. // the sourceId of the screen/window/tab to be shared.
  855. if (typeof getSourceId !== 'function') {
  856. console.error('shimGetDisplayMedia: getSourceId argument is not ' + 'a function');
  857. return;
  858. }
  859. window.navigator.mediaDevices.getDisplayMedia = function getDisplayMedia(constraints) {
  860. return getSourceId(constraints).then(function (sourceId) {
  861. var widthSpecified = constraints.video && constraints.video.width;
  862. var heightSpecified = constraints.video && constraints.video.height;
  863. var frameRateSpecified = constraints.video && constraints.video.frameRate;
  864. constraints.video = {
  865. mandatory: {
  866. chromeMediaSource: 'desktop',
  867. chromeMediaSourceId: sourceId,
  868. maxFrameRate: frameRateSpecified || 3
  869. }
  870. };
  871. if (widthSpecified) {
  872. constraints.video.mandatory.maxWidth = widthSpecified;
  873. }
  874. if (heightSpecified) {
  875. constraints.video.mandatory.maxHeight = heightSpecified;
  876. }
  877. return window.navigator.mediaDevices.getUserMedia(constraints);
  878. });
  879. };
  880. }
  881. },{}],5:[function(require,module,exports){
  882. /*
  883. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  884. *
  885. * Use of this source code is governed by a BSD-style license
  886. * that can be found in the LICENSE file in the root of the source
  887. * tree.
  888. */
  889. /* eslint-env node */
  890. 'use strict';
  891. Object.defineProperty(exports, "__esModule", {
  892. value: true
  893. });
  894. exports.shimGetUserMedia = shimGetUserMedia;
  895. var utils = _interopRequireWildcard(require("../utils.js"));
  896. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  897. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  898. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  899. var logging = utils.log;
  900. function shimGetUserMedia(window, browserDetails) {
  901. var navigator = window && window.navigator;
  902. if (!navigator.mediaDevices) {
  903. return;
  904. }
  905. var constraintsToChrome_ = function constraintsToChrome_(c) {
  906. if (_typeof(c) !== 'object' || c.mandatory || c.optional) {
  907. return c;
  908. }
  909. var cc = {};
  910. Object.keys(c).forEach(function (key) {
  911. if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
  912. return;
  913. }
  914. var r = _typeof(c[key]) === 'object' ? c[key] : {
  915. ideal: c[key]
  916. };
  917. if (r.exact !== undefined && typeof r.exact === 'number') {
  918. r.min = r.max = r.exact;
  919. }
  920. var oldname_ = function oldname_(prefix, name) {
  921. if (prefix) {
  922. return prefix + name.charAt(0).toUpperCase() + name.slice(1);
  923. }
  924. return name === 'deviceId' ? 'sourceId' : name;
  925. };
  926. if (r.ideal !== undefined) {
  927. cc.optional = cc.optional || [];
  928. var oc = {};
  929. if (typeof r.ideal === 'number') {
  930. oc[oldname_('min', key)] = r.ideal;
  931. cc.optional.push(oc);
  932. oc = {};
  933. oc[oldname_('max', key)] = r.ideal;
  934. cc.optional.push(oc);
  935. } else {
  936. oc[oldname_('', key)] = r.ideal;
  937. cc.optional.push(oc);
  938. }
  939. }
  940. if (r.exact !== undefined && typeof r.exact !== 'number') {
  941. cc.mandatory = cc.mandatory || {};
  942. cc.mandatory[oldname_('', key)] = r.exact;
  943. } else {
  944. ['min', 'max'].forEach(function (mix) {
  945. if (r[mix] !== undefined) {
  946. cc.mandatory = cc.mandatory || {};
  947. cc.mandatory[oldname_(mix, key)] = r[mix];
  948. }
  949. });
  950. }
  951. });
  952. if (c.advanced) {
  953. cc.optional = (cc.optional || []).concat(c.advanced);
  954. }
  955. return cc;
  956. };
  957. var shimConstraints_ = function shimConstraints_(constraints, func) {
  958. if (browserDetails.version >= 61) {
  959. return func(constraints);
  960. }
  961. constraints = JSON.parse(JSON.stringify(constraints));
  962. if (constraints && _typeof(constraints.audio) === 'object') {
  963. var remap = function remap(obj, a, b) {
  964. if (a in obj && !(b in obj)) {
  965. obj[b] = obj[a];
  966. delete obj[a];
  967. }
  968. };
  969. constraints = JSON.parse(JSON.stringify(constraints));
  970. remap(constraints.audio, 'autoGainControl', 'googAutoGainControl');
  971. remap(constraints.audio, 'noiseSuppression', 'googNoiseSuppression');
  972. constraints.audio = constraintsToChrome_(constraints.audio);
  973. }
  974. if (constraints && _typeof(constraints.video) === 'object') {
  975. // Shim facingMode for mobile & surface pro.
  976. var face = constraints.video.facingMode;
  977. face = face && (_typeof(face) === 'object' ? face : {
  978. ideal: face
  979. });
  980. var getSupportedFacingModeLies = browserDetails.version < 66;
  981. if (face && (face.exact === 'user' || face.exact === 'environment' || face.ideal === 'user' || face.ideal === 'environment') && !(navigator.mediaDevices.getSupportedConstraints && navigator.mediaDevices.getSupportedConstraints().facingMode && !getSupportedFacingModeLies)) {
  982. delete constraints.video.facingMode;
  983. var matches;
  984. if (face.exact === 'environment' || face.ideal === 'environment') {
  985. matches = ['back', 'rear'];
  986. } else if (face.exact === 'user' || face.ideal === 'user') {
  987. matches = ['front'];
  988. }
  989. if (matches) {
  990. // Look for matches in label, or use last cam for back (typical).
  991. return navigator.mediaDevices.enumerateDevices().then(function (devices) {
  992. devices = devices.filter(function (d) {
  993. return d.kind === 'videoinput';
  994. });
  995. var dev = devices.find(function (d) {
  996. return matches.some(function (match) {
  997. return d.label.toLowerCase().includes(match);
  998. });
  999. });
  1000. if (!dev && devices.length && matches.includes('back')) {
  1001. dev = devices[devices.length - 1]; // more likely the back cam
  1002. }
  1003. if (dev) {
  1004. constraints.video.deviceId = face.exact ? {
  1005. exact: dev.deviceId
  1006. } : {
  1007. ideal: dev.deviceId
  1008. };
  1009. }
  1010. constraints.video = constraintsToChrome_(constraints.video);
  1011. logging('chrome: ' + JSON.stringify(constraints));
  1012. return func(constraints);
  1013. });
  1014. }
  1015. }
  1016. constraints.video = constraintsToChrome_(constraints.video);
  1017. }
  1018. logging('chrome: ' + JSON.stringify(constraints));
  1019. return func(constraints);
  1020. };
  1021. var shimError_ = function shimError_(e) {
  1022. if (browserDetails.version >= 64) {
  1023. return e;
  1024. }
  1025. return {
  1026. name: {
  1027. PermissionDeniedError: 'NotAllowedError',
  1028. PermissionDismissedError: 'NotAllowedError',
  1029. InvalidStateError: 'NotAllowedError',
  1030. DevicesNotFoundError: 'NotFoundError',
  1031. ConstraintNotSatisfiedError: 'OverconstrainedError',
  1032. TrackStartError: 'NotReadableError',
  1033. MediaDeviceFailedDueToShutdown: 'NotAllowedError',
  1034. MediaDeviceKillSwitchOn: 'NotAllowedError',
  1035. TabCaptureError: 'AbortError',
  1036. ScreenCaptureError: 'AbortError',
  1037. DeviceCaptureError: 'AbortError'
  1038. }[e.name] || e.name,
  1039. message: e.message,
  1040. constraint: e.constraint || e.constraintName,
  1041. toString: function toString() {
  1042. return this.name + (this.message && ': ') + this.message;
  1043. }
  1044. };
  1045. };
  1046. var getUserMedia_ = function getUserMedia_(constraints, onSuccess, onError) {
  1047. shimConstraints_(constraints, function (c) {
  1048. navigator.webkitGetUserMedia(c, onSuccess, function (e) {
  1049. if (onError) {
  1050. onError(shimError_(e));
  1051. }
  1052. });
  1053. });
  1054. };
  1055. navigator.getUserMedia = getUserMedia_.bind(navigator);
  1056. // Even though Chrome 45 has navigator.mediaDevices and a getUserMedia
  1057. // function which returns a Promise, it does not accept spec-style
  1058. // constraints.
  1059. if (navigator.mediaDevices.getUserMedia) {
  1060. var origGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
  1061. navigator.mediaDevices.getUserMedia = function (cs) {
  1062. return shimConstraints_(cs, function (c) {
  1063. return origGetUserMedia(c).then(function (stream) {
  1064. if (c.audio && !stream.getAudioTracks().length || c.video && !stream.getVideoTracks().length) {
  1065. stream.getTracks().forEach(function (track) {
  1066. track.stop();
  1067. });
  1068. throw new DOMException('', 'NotFoundError');
  1069. }
  1070. return stream;
  1071. }, function (e) {
  1072. return Promise.reject(shimError_(e));
  1073. });
  1074. });
  1075. };
  1076. }
  1077. }
  1078. },{"../utils.js":11}],6:[function(require,module,exports){
  1079. /*
  1080. * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
  1081. *
  1082. * Use of this source code is governed by a BSD-style license
  1083. * that can be found in the LICENSE file in the root of the source
  1084. * tree.
  1085. */
  1086. /* eslint-env node */
  1087. 'use strict';
  1088. Object.defineProperty(exports, "__esModule", {
  1089. value: true
  1090. });
  1091. exports.removeExtmapAllowMixed = removeExtmapAllowMixed;
  1092. exports.shimAddIceCandidateNullOrEmpty = shimAddIceCandidateNullOrEmpty;
  1093. exports.shimConnectionState = shimConnectionState;
  1094. exports.shimMaxMessageSize = shimMaxMessageSize;
  1095. exports.shimParameterlessSetLocalDescription = shimParameterlessSetLocalDescription;
  1096. exports.shimRTCIceCandidate = shimRTCIceCandidate;
  1097. exports.shimRTCIceCandidateRelayProtocol = shimRTCIceCandidateRelayProtocol;
  1098. exports.shimSendThrowTypeError = shimSendThrowTypeError;
  1099. var _sdp = _interopRequireDefault(require("sdp"));
  1100. var utils = _interopRequireWildcard(require("./utils"));
  1101. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  1102. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1103. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  1104. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  1105. function shimRTCIceCandidate(window) {
  1106. // foundation is arbitrarily chosen as an indicator for full support for
  1107. // https://w3c.github.io/webrtc-pc/#rtcicecandidate-interface
  1108. if (!window.RTCIceCandidate || window.RTCIceCandidate && 'foundation' in window.RTCIceCandidate.prototype) {
  1109. return;
  1110. }
  1111. var NativeRTCIceCandidate = window.RTCIceCandidate;
  1112. window.RTCIceCandidate = function RTCIceCandidate(args) {
  1113. // Remove the a= which shouldn't be part of the candidate string.
  1114. if (_typeof(args) === 'object' && args.candidate && args.candidate.indexOf('a=') === 0) {
  1115. args = JSON.parse(JSON.stringify(args));
  1116. args.candidate = args.candidate.substring(2);
  1117. }
  1118. if (args.candidate && args.candidate.length) {
  1119. // Augment the native candidate with the parsed fields.
  1120. var nativeCandidate = new NativeRTCIceCandidate(args);
  1121. var parsedCandidate = _sdp["default"].parseCandidate(args.candidate);
  1122. for (var key in parsedCandidate) {
  1123. if (!(key in nativeCandidate)) {
  1124. Object.defineProperty(nativeCandidate, key, {
  1125. value: parsedCandidate[key]
  1126. });
  1127. }
  1128. }
  1129. // Override serializer to not serialize the extra attributes.
  1130. nativeCandidate.toJSON = function toJSON() {
  1131. return {
  1132. candidate: nativeCandidate.candidate,
  1133. sdpMid: nativeCandidate.sdpMid,
  1134. sdpMLineIndex: nativeCandidate.sdpMLineIndex,
  1135. usernameFragment: nativeCandidate.usernameFragment
  1136. };
  1137. };
  1138. return nativeCandidate;
  1139. }
  1140. return new NativeRTCIceCandidate(args);
  1141. };
  1142. window.RTCIceCandidate.prototype = NativeRTCIceCandidate.prototype;
  1143. // Hook up the augmented candidate in onicecandidate and
  1144. // addEventListener('icecandidate', ...)
  1145. utils.wrapPeerConnectionEvent(window, 'icecandidate', function (e) {
  1146. if (e.candidate) {
  1147. Object.defineProperty(e, 'candidate', {
  1148. value: new window.RTCIceCandidate(e.candidate),
  1149. writable: 'false'
  1150. });
  1151. }
  1152. return e;
  1153. });
  1154. }
  1155. function shimRTCIceCandidateRelayProtocol(window) {
  1156. if (!window.RTCIceCandidate || window.RTCIceCandidate && 'relayProtocol' in window.RTCIceCandidate.prototype) {
  1157. return;
  1158. }
  1159. // Hook up the augmented candidate in onicecandidate and
  1160. // addEventListener('icecandidate', ...)
  1161. utils.wrapPeerConnectionEvent(window, 'icecandidate', function (e) {
  1162. if (e.candidate) {
  1163. var parsedCandidate = _sdp["default"].parseCandidate(e.candidate.candidate);
  1164. if (parsedCandidate.type === 'relay') {
  1165. // This is a libwebrtc-specific mapping of local type preference
  1166. // to relayProtocol.
  1167. e.candidate.relayProtocol = {
  1168. 0: 'tls',
  1169. 1: 'tcp',
  1170. 2: 'udp'
  1171. }[parsedCandidate.priority >> 24];
  1172. }
  1173. }
  1174. return e;
  1175. });
  1176. }
  1177. function shimMaxMessageSize(window, browserDetails) {
  1178. if (!window.RTCPeerConnection) {
  1179. return;
  1180. }
  1181. if (!('sctp' in window.RTCPeerConnection.prototype)) {
  1182. Object.defineProperty(window.RTCPeerConnection.prototype, 'sctp', {
  1183. get: function get() {
  1184. return typeof this._sctp === 'undefined' ? null : this._sctp;
  1185. }
  1186. });
  1187. }
  1188. var sctpInDescription = function sctpInDescription(description) {
  1189. if (!description || !description.sdp) {
  1190. return false;
  1191. }
  1192. var sections = _sdp["default"].splitSections(description.sdp);
  1193. sections.shift();
  1194. return sections.some(function (mediaSection) {
  1195. var mLine = _sdp["default"].parseMLine(mediaSection);
  1196. return mLine && mLine.kind === 'application' && mLine.protocol.indexOf('SCTP') !== -1;
  1197. });
  1198. };
  1199. var getRemoteFirefoxVersion = function getRemoteFirefoxVersion(description) {
  1200. // TODO: Is there a better solution for detecting Firefox?
  1201. var match = description.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);
  1202. if (match === null || match.length < 2) {
  1203. return -1;
  1204. }
  1205. var version = parseInt(match[1], 10);
  1206. // Test for NaN (yes, this is ugly)
  1207. return version !== version ? -1 : version;
  1208. };
  1209. var getCanSendMaxMessageSize = function getCanSendMaxMessageSize(remoteIsFirefox) {
  1210. // Every implementation we know can send at least 64 KiB.
  1211. // Note: Although Chrome is technically able to send up to 256 KiB, the
  1212. // data does not reach the other peer reliably.
  1213. // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=8419
  1214. var canSendMaxMessageSize = 65536;
  1215. if (browserDetails.browser === 'firefox') {
  1216. if (browserDetails.version < 57) {
  1217. if (remoteIsFirefox === -1) {
  1218. // FF < 57 will send in 16 KiB chunks using the deprecated PPID
  1219. // fragmentation.
  1220. canSendMaxMessageSize = 16384;
  1221. } else {
  1222. // However, other FF (and RAWRTC) can reassemble PPID-fragmented
  1223. // messages. Thus, supporting ~2 GiB when sending.
  1224. canSendMaxMessageSize = 2147483637;
  1225. }
  1226. } else if (browserDetails.version < 60) {
  1227. // Currently, all FF >= 57 will reset the remote maximum message size
  1228. // to the default value when a data channel is created at a later
  1229. // stage. :(
  1230. // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831
  1231. canSendMaxMessageSize = browserDetails.version === 57 ? 65535 : 65536;
  1232. } else {
  1233. // FF >= 60 supports sending ~2 GiB
  1234. canSendMaxMessageSize = 2147483637;
  1235. }
  1236. }
  1237. return canSendMaxMessageSize;
  1238. };
  1239. var getMaxMessageSize = function getMaxMessageSize(description, remoteIsFirefox) {
  1240. // Note: 65536 bytes is the default value from the SDP spec. Also,
  1241. // every implementation we know supports receiving 65536 bytes.
  1242. var maxMessageSize = 65536;
  1243. // FF 57 has a slightly incorrect default remote max message size, so
  1244. // we need to adjust it here to avoid a failure when sending.
  1245. // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1425697
  1246. if (browserDetails.browser === 'firefox' && browserDetails.version === 57) {
  1247. maxMessageSize = 65535;
  1248. }
  1249. var match = _sdp["default"].matchPrefix(description.sdp, 'a=max-message-size:');
  1250. if (match.length > 0) {
  1251. maxMessageSize = parseInt(match[0].substring(19), 10);
  1252. } else if (browserDetails.browser === 'firefox' && remoteIsFirefox !== -1) {
  1253. // If the maximum message size is not present in the remote SDP and
  1254. // both local and remote are Firefox, the remote peer can receive
  1255. // ~2 GiB.
  1256. maxMessageSize = 2147483637;
  1257. }
  1258. return maxMessageSize;
  1259. };
  1260. var origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
  1261. window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription() {
  1262. this._sctp = null;
  1263. // Chrome decided to not expose .sctp in plan-b mode.
  1264. // As usual, adapter.js has to do an 'ugly worakaround'
  1265. // to cover up the mess.
  1266. if (browserDetails.browser === 'chrome' && browserDetails.version >= 76) {
  1267. var _this$getConfiguratio = this.getConfiguration(),
  1268. sdpSemantics = _this$getConfiguratio.sdpSemantics;
  1269. if (sdpSemantics === 'plan-b') {
  1270. Object.defineProperty(this, 'sctp', {
  1271. get: function get() {
  1272. return typeof this._sctp === 'undefined' ? null : this._sctp;
  1273. },
  1274. enumerable: true,
  1275. configurable: true
  1276. });
  1277. }
  1278. }
  1279. if (sctpInDescription(arguments[0])) {
  1280. // Check if the remote is FF.
  1281. var isFirefox = getRemoteFirefoxVersion(arguments[0]);
  1282. // Get the maximum message size the local peer is capable of sending
  1283. var canSendMMS = getCanSendMaxMessageSize(isFirefox);
  1284. // Get the maximum message size of the remote peer.
  1285. var remoteMMS = getMaxMessageSize(arguments[0], isFirefox);
  1286. // Determine final maximum message size
  1287. var maxMessageSize;
  1288. if (canSendMMS === 0 && remoteMMS === 0) {
  1289. maxMessageSize = Number.POSITIVE_INFINITY;
  1290. } else if (canSendMMS === 0 || remoteMMS === 0) {
  1291. maxMessageSize = Math.max(canSendMMS, remoteMMS);
  1292. } else {
  1293. maxMessageSize = Math.min(canSendMMS, remoteMMS);
  1294. }
  1295. // Create a dummy RTCSctpTransport object and the 'maxMessageSize'
  1296. // attribute.
  1297. var sctp = {};
  1298. Object.defineProperty(sctp, 'maxMessageSize', {
  1299. get: function get() {
  1300. return maxMessageSize;
  1301. }
  1302. });
  1303. this._sctp = sctp;
  1304. }
  1305. return origSetRemoteDescription.apply(this, arguments);
  1306. };
  1307. }
  1308. function shimSendThrowTypeError(window) {
  1309. if (!(window.RTCPeerConnection && 'createDataChannel' in window.RTCPeerConnection.prototype)) {
  1310. return;
  1311. }
  1312. // Note: Although Firefox >= 57 has a native implementation, the maximum
  1313. // message size can be reset for all data channels at a later stage.
  1314. // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831
  1315. function wrapDcSend(dc, pc) {
  1316. var origDataChannelSend = dc.send;
  1317. dc.send = function send() {
  1318. var data = arguments[0];
  1319. var length = data.length || data.size || data.byteLength;
  1320. if (dc.readyState === 'open' && pc.sctp && length > pc.sctp.maxMessageSize) {
  1321. throw new TypeError('Message too large (can send a maximum of ' + pc.sctp.maxMessageSize + ' bytes)');
  1322. }
  1323. return origDataChannelSend.apply(dc, arguments);
  1324. };
  1325. }
  1326. var origCreateDataChannel = window.RTCPeerConnection.prototype.createDataChannel;
  1327. window.RTCPeerConnection.prototype.createDataChannel = function createDataChannel() {
  1328. var dataChannel = origCreateDataChannel.apply(this, arguments);
  1329. wrapDcSend(dataChannel, this);
  1330. return dataChannel;
  1331. };
  1332. utils.wrapPeerConnectionEvent(window, 'datachannel', function (e) {
  1333. wrapDcSend(e.channel, e.target);
  1334. return e;
  1335. });
  1336. }
  1337. /* shims RTCConnectionState by pretending it is the same as iceConnectionState.
  1338. * See https://bugs.chromium.org/p/webrtc/issues/detail?id=6145#c12
  1339. * for why this is a valid hack in Chrome. In Firefox it is slightly incorrect
  1340. * since DTLS failures would be hidden. See
  1341. * https://bugzilla.mozilla.org/show_bug.cgi?id=1265827
  1342. * for the Firefox tracking bug.
  1343. */
  1344. function shimConnectionState(window) {
  1345. if (!window.RTCPeerConnection || 'connectionState' in window.RTCPeerConnection.prototype) {
  1346. return;
  1347. }
  1348. var proto = window.RTCPeerConnection.prototype;
  1349. Object.defineProperty(proto, 'connectionState', {
  1350. get: function get() {
  1351. return {
  1352. completed: 'connected',
  1353. checking: 'connecting'
  1354. }[this.iceConnectionState] || this.iceConnectionState;
  1355. },
  1356. enumerable: true,
  1357. configurable: true
  1358. });
  1359. Object.defineProperty(proto, 'onconnectionstatechange', {
  1360. get: function get() {
  1361. return this._onconnectionstatechange || null;
  1362. },
  1363. set: function set(cb) {
  1364. if (this._onconnectionstatechange) {
  1365. this.removeEventListener('connectionstatechange', this._onconnectionstatechange);
  1366. delete this._onconnectionstatechange;
  1367. }
  1368. if (cb) {
  1369. this.addEventListener('connectionstatechange', this._onconnectionstatechange = cb);
  1370. }
  1371. },
  1372. enumerable: true,
  1373. configurable: true
  1374. });
  1375. ['setLocalDescription', 'setRemoteDescription'].forEach(function (method) {
  1376. var origMethod = proto[method];
  1377. proto[method] = function () {
  1378. if (!this._connectionstatechangepoly) {
  1379. this._connectionstatechangepoly = function (e) {
  1380. var pc = e.target;
  1381. if (pc._lastConnectionState !== pc.connectionState) {
  1382. pc._lastConnectionState = pc.connectionState;
  1383. var newEvent = new Event('connectionstatechange', e);
  1384. pc.dispatchEvent(newEvent);
  1385. }
  1386. return e;
  1387. };
  1388. this.addEventListener('iceconnectionstatechange', this._connectionstatechangepoly);
  1389. }
  1390. return origMethod.apply(this, arguments);
  1391. };
  1392. });
  1393. }
  1394. function removeExtmapAllowMixed(window, browserDetails) {
  1395. /* remove a=extmap-allow-mixed for webrtc.org < M71 */
  1396. if (!window.RTCPeerConnection) {
  1397. return;
  1398. }
  1399. if (browserDetails.browser === 'chrome' && browserDetails.version >= 71) {
  1400. return;
  1401. }
  1402. if (browserDetails.browser === 'safari' && browserDetails.version >= 605) {
  1403. return;
  1404. }
  1405. var nativeSRD = window.RTCPeerConnection.prototype.setRemoteDescription;
  1406. window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription(desc) {
  1407. if (desc && desc.sdp && desc.sdp.indexOf('\na=extmap-allow-mixed') !== -1) {
  1408. var sdp = desc.sdp.split('\n').filter(function (line) {
  1409. return line.trim() !== 'a=extmap-allow-mixed';
  1410. }).join('\n');
  1411. // Safari enforces read-only-ness of RTCSessionDescription fields.
  1412. if (window.RTCSessionDescription && desc instanceof window.RTCSessionDescription) {
  1413. arguments[0] = new window.RTCSessionDescription({
  1414. type: desc.type,
  1415. sdp: sdp
  1416. });
  1417. } else {
  1418. desc.sdp = sdp;
  1419. }
  1420. }
  1421. return nativeSRD.apply(this, arguments);
  1422. };
  1423. }
  1424. function shimAddIceCandidateNullOrEmpty(window, browserDetails) {
  1425. // Support for addIceCandidate(null or undefined)
  1426. // as well as addIceCandidate({candidate: "", ...})
  1427. // https://bugs.chromium.org/p/chromium/issues/detail?id=978582
  1428. // Note: must be called before other polyfills which change the signature.
  1429. if (!(window.RTCPeerConnection && window.RTCPeerConnection.prototype)) {
  1430. return;
  1431. }
  1432. var nativeAddIceCandidate = window.RTCPeerConnection.prototype.addIceCandidate;
  1433. if (!nativeAddIceCandidate || nativeAddIceCandidate.length === 0) {
  1434. return;
  1435. }
  1436. window.RTCPeerConnection.prototype.addIceCandidate = function addIceCandidate() {
  1437. if (!arguments[0]) {
  1438. if (arguments[1]) {
  1439. arguments[1].apply(null);
  1440. }
  1441. return Promise.resolve();
  1442. }
  1443. // Firefox 68+ emits and processes {candidate: "", ...}, ignore
  1444. // in older versions.
  1445. // Native support for ignoring exists for Chrome M77+.
  1446. // Safari ignores as well, exact version unknown but works in the same
  1447. // version that also ignores addIceCandidate(null).
  1448. if ((browserDetails.browser === 'chrome' && browserDetails.version < 78 || browserDetails.browser === 'firefox' && browserDetails.version < 68 || browserDetails.browser === 'safari') && arguments[0] && arguments[0].candidate === '') {
  1449. return Promise.resolve();
  1450. }
  1451. return nativeAddIceCandidate.apply(this, arguments);
  1452. };
  1453. }
  1454. // Note: Make sure to call this ahead of APIs that modify
  1455. // setLocalDescription.length
  1456. function shimParameterlessSetLocalDescription(window, browserDetails) {
  1457. if (!(window.RTCPeerConnection && window.RTCPeerConnection.prototype)) {
  1458. return;
  1459. }
  1460. var nativeSetLocalDescription = window.RTCPeerConnection.prototype.setLocalDescription;
  1461. if (!nativeSetLocalDescription || nativeSetLocalDescription.length === 0) {
  1462. return;
  1463. }
  1464. window.RTCPeerConnection.prototype.setLocalDescription = function setLocalDescription() {
  1465. var _this = this;
  1466. var desc = arguments[0] || {};
  1467. if (_typeof(desc) !== 'object' || desc.type && desc.sdp) {
  1468. return nativeSetLocalDescription.apply(this, arguments);
  1469. }
  1470. // The remaining steps should technically happen when SLD comes off the
  1471. // RTCPeerConnection's operations chain (not ahead of going on it), but
  1472. // this is too difficult to shim. Instead, this shim only covers the
  1473. // common case where the operations chain is empty. This is imperfect, but
  1474. // should cover many cases. Rationale: Even if we can't reduce the glare
  1475. // window to zero on imperfect implementations, there's value in tapping
  1476. // into the perfect negotiation pattern that several browsers support.
  1477. desc = {
  1478. type: desc.type,
  1479. sdp: desc.sdp
  1480. };
  1481. if (!desc.type) {
  1482. switch (this.signalingState) {
  1483. case 'stable':
  1484. case 'have-local-offer':
  1485. case 'have-remote-pranswer':
  1486. desc.type = 'offer';
  1487. break;
  1488. default:
  1489. desc.type = 'answer';
  1490. break;
  1491. }
  1492. }
  1493. if (desc.sdp || desc.type !== 'offer' && desc.type !== 'answer') {
  1494. return nativeSetLocalDescription.apply(this, [desc]);
  1495. }
  1496. var func = desc.type === 'offer' ? this.createOffer : this.createAnswer;
  1497. return func.apply(this).then(function (d) {
  1498. return nativeSetLocalDescription.apply(_this, [d]);
  1499. });
  1500. };
  1501. }
  1502. },{"./utils":11,"sdp":12}],7:[function(require,module,exports){
  1503. /*
  1504. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  1505. *
  1506. * Use of this source code is governed by a BSD-style license
  1507. * that can be found in the LICENSE file in the root of the source
  1508. * tree.
  1509. */
  1510. /* eslint-env node */
  1511. 'use strict';
  1512. Object.defineProperty(exports, "__esModule", {
  1513. value: true
  1514. });
  1515. exports.shimAddTransceiver = shimAddTransceiver;
  1516. exports.shimCreateAnswer = shimCreateAnswer;
  1517. exports.shimCreateOffer = shimCreateOffer;
  1518. Object.defineProperty(exports, "shimGetDisplayMedia", {
  1519. enumerable: true,
  1520. get: function get() {
  1521. return _getdisplaymedia.shimGetDisplayMedia;
  1522. }
  1523. });
  1524. exports.shimGetParameters = shimGetParameters;
  1525. Object.defineProperty(exports, "shimGetUserMedia", {
  1526. enumerable: true,
  1527. get: function get() {
  1528. return _getusermedia.shimGetUserMedia;
  1529. }
  1530. });
  1531. exports.shimOnTrack = shimOnTrack;
  1532. exports.shimPeerConnection = shimPeerConnection;
  1533. exports.shimRTCDataChannel = shimRTCDataChannel;
  1534. exports.shimReceiverGetStats = shimReceiverGetStats;
  1535. exports.shimRemoveStream = shimRemoveStream;
  1536. exports.shimSenderGetStats = shimSenderGetStats;
  1537. var utils = _interopRequireWildcard(require("../utils"));
  1538. var _getusermedia = require("./getusermedia");
  1539. var _getdisplaymedia = require("./getdisplaymedia");
  1540. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  1541. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1542. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  1543. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  1544. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  1545. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
  1546. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  1547. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
  1548. function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  1549. function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
  1550. function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
  1551. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  1552. function shimOnTrack(window) {
  1553. if (_typeof(window) === 'object' && window.RTCTrackEvent && 'receiver' in window.RTCTrackEvent.prototype && !('transceiver' in window.RTCTrackEvent.prototype)) {
  1554. Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {
  1555. get: function get() {
  1556. return {
  1557. receiver: this.receiver
  1558. };
  1559. }
  1560. });
  1561. }
  1562. }
  1563. function shimPeerConnection(window, browserDetails) {
  1564. if (_typeof(window) !== 'object' || !(window.RTCPeerConnection || window.mozRTCPeerConnection)) {
  1565. return; // probably media.peerconnection.enabled=false in about:config
  1566. }
  1567. if (!window.RTCPeerConnection && window.mozRTCPeerConnection) {
  1568. // very basic support for old versions.
  1569. window.RTCPeerConnection = window.mozRTCPeerConnection;
  1570. }
  1571. if (browserDetails.version < 53) {
  1572. // shim away need for obsolete RTCIceCandidate/RTCSessionDescription.
  1573. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'].forEach(function (method) {
  1574. var nativeMethod = window.RTCPeerConnection.prototype[method];
  1575. var methodObj = _defineProperty({}, method, function () {
  1576. arguments[0] = new (method === 'addIceCandidate' ? window.RTCIceCandidate : window.RTCSessionDescription)(arguments[0]);
  1577. return nativeMethod.apply(this, arguments);
  1578. });
  1579. window.RTCPeerConnection.prototype[method] = methodObj[method];
  1580. });
  1581. }
  1582. var modernStatsTypes = {
  1583. inboundrtp: 'inbound-rtp',
  1584. outboundrtp: 'outbound-rtp',
  1585. candidatepair: 'candidate-pair',
  1586. localcandidate: 'local-candidate',
  1587. remotecandidate: 'remote-candidate'
  1588. };
  1589. var nativeGetStats = window.RTCPeerConnection.prototype.getStats;
  1590. window.RTCPeerConnection.prototype.getStats = function getStats() {
  1591. var _arguments = Array.prototype.slice.call(arguments),
  1592. selector = _arguments[0],
  1593. onSucc = _arguments[1],
  1594. onErr = _arguments[2];
  1595. return nativeGetStats.apply(this, [selector || null]).then(function (stats) {
  1596. if (browserDetails.version < 53 && !onSucc) {
  1597. // Shim only promise getStats with spec-hyphens in type names
  1598. // Leave callback version alone; misc old uses of forEach before Map
  1599. try {
  1600. stats.forEach(function (stat) {
  1601. stat.type = modernStatsTypes[stat.type] || stat.type;
  1602. });
  1603. } catch (e) {
  1604. if (e.name !== 'TypeError') {
  1605. throw e;
  1606. }
  1607. // Avoid TypeError: "type" is read-only, in old versions. 34-43ish
  1608. stats.forEach(function (stat, i) {
  1609. stats.set(i, Object.assign({}, stat, {
  1610. type: modernStatsTypes[stat.type] || stat.type
  1611. }));
  1612. });
  1613. }
  1614. }
  1615. return stats;
  1616. }).then(onSucc, onErr);
  1617. };
  1618. }
  1619. function shimSenderGetStats(window) {
  1620. if (!(_typeof(window) === 'object' && window.RTCPeerConnection && window.RTCRtpSender)) {
  1621. return;
  1622. }
  1623. if (window.RTCRtpSender && 'getStats' in window.RTCRtpSender.prototype) {
  1624. return;
  1625. }
  1626. var origGetSenders = window.RTCPeerConnection.prototype.getSenders;
  1627. if (origGetSenders) {
  1628. window.RTCPeerConnection.prototype.getSenders = function getSenders() {
  1629. var _this = this;
  1630. var senders = origGetSenders.apply(this, []);
  1631. senders.forEach(function (sender) {
  1632. return sender._pc = _this;
  1633. });
  1634. return senders;
  1635. };
  1636. }
  1637. var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
  1638. if (origAddTrack) {
  1639. window.RTCPeerConnection.prototype.addTrack = function addTrack() {
  1640. var sender = origAddTrack.apply(this, arguments);
  1641. sender._pc = this;
  1642. return sender;
  1643. };
  1644. }
  1645. window.RTCRtpSender.prototype.getStats = function getStats() {
  1646. return this.track ? this._pc.getStats(this.track) : Promise.resolve(new Map());
  1647. };
  1648. }
  1649. function shimReceiverGetStats(window) {
  1650. if (!(_typeof(window) === 'object' && window.RTCPeerConnection && window.RTCRtpSender)) {
  1651. return;
  1652. }
  1653. if (window.RTCRtpSender && 'getStats' in window.RTCRtpReceiver.prototype) {
  1654. return;
  1655. }
  1656. var origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;
  1657. if (origGetReceivers) {
  1658. window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {
  1659. var _this2 = this;
  1660. var receivers = origGetReceivers.apply(this, []);
  1661. receivers.forEach(function (receiver) {
  1662. return receiver._pc = _this2;
  1663. });
  1664. return receivers;
  1665. };
  1666. }
  1667. utils.wrapPeerConnectionEvent(window, 'track', function (e) {
  1668. e.receiver._pc = e.srcElement;
  1669. return e;
  1670. });
  1671. window.RTCRtpReceiver.prototype.getStats = function getStats() {
  1672. return this._pc.getStats(this.track);
  1673. };
  1674. }
  1675. function shimRemoveStream(window) {
  1676. if (!window.RTCPeerConnection || 'removeStream' in window.RTCPeerConnection.prototype) {
  1677. return;
  1678. }
  1679. window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
  1680. var _this3 = this;
  1681. utils.deprecated('removeStream', 'removeTrack');
  1682. this.getSenders().forEach(function (sender) {
  1683. if (sender.track && stream.getTracks().includes(sender.track)) {
  1684. _this3.removeTrack(sender);
  1685. }
  1686. });
  1687. };
  1688. }
  1689. function shimRTCDataChannel(window) {
  1690. // rename DataChannel to RTCDataChannel (native fix in FF60):
  1691. // https://bugzilla.mozilla.org/show_bug.cgi?id=1173851
  1692. if (window.DataChannel && !window.RTCDataChannel) {
  1693. window.RTCDataChannel = window.DataChannel;
  1694. }
  1695. }
  1696. function shimAddTransceiver(window) {
  1697. // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647
  1698. // Firefox ignores the init sendEncodings options passed to addTransceiver
  1699. // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918
  1700. if (!(_typeof(window) === 'object' && window.RTCPeerConnection)) {
  1701. return;
  1702. }
  1703. var origAddTransceiver = window.RTCPeerConnection.prototype.addTransceiver;
  1704. if (origAddTransceiver) {
  1705. window.RTCPeerConnection.prototype.addTransceiver = function addTransceiver() {
  1706. this.setParametersPromises = [];
  1707. // WebIDL input coercion and validation
  1708. var sendEncodings = arguments[1] && arguments[1].sendEncodings;
  1709. if (sendEncodings === undefined) {
  1710. sendEncodings = [];
  1711. }
  1712. sendEncodings = _toConsumableArray(sendEncodings);
  1713. var shouldPerformCheck = sendEncodings.length > 0;
  1714. if (shouldPerformCheck) {
  1715. // If sendEncodings params are provided, validate grammar
  1716. sendEncodings.forEach(function (encodingParam) {
  1717. if ('rid' in encodingParam) {
  1718. var ridRegex = /^[a-z0-9]{0,16}$/i;
  1719. if (!ridRegex.test(encodingParam.rid)) {
  1720. throw new TypeError('Invalid RID value provided.');
  1721. }
  1722. }
  1723. if ('scaleResolutionDownBy' in encodingParam) {
  1724. if (!(parseFloat(encodingParam.scaleResolutionDownBy) >= 1.0)) {
  1725. throw new RangeError('scale_resolution_down_by must be >= 1.0');
  1726. }
  1727. }
  1728. if ('maxFramerate' in encodingParam) {
  1729. if (!(parseFloat(encodingParam.maxFramerate) >= 0)) {
  1730. throw new RangeError('max_framerate must be >= 0.0');
  1731. }
  1732. }
  1733. });
  1734. }
  1735. var transceiver = origAddTransceiver.apply(this, arguments);
  1736. if (shouldPerformCheck) {
  1737. // Check if the init options were applied. If not we do this in an
  1738. // asynchronous way and save the promise reference in a global object.
  1739. // This is an ugly hack, but at the same time is way more robust than
  1740. // checking the sender parameters before and after the createOffer
  1741. // Also note that after the createoffer we are not 100% sure that
  1742. // the params were asynchronously applied so we might miss the
  1743. // opportunity to recreate offer.
  1744. var sender = transceiver.sender;
  1745. var params = sender.getParameters();
  1746. if (!('encodings' in params) ||
  1747. // Avoid being fooled by patched getParameters() below.
  1748. params.encodings.length === 1 && Object.keys(params.encodings[0]).length === 0) {
  1749. params.encodings = sendEncodings;
  1750. sender.sendEncodings = sendEncodings;
  1751. this.setParametersPromises.push(sender.setParameters(params).then(function () {
  1752. delete sender.sendEncodings;
  1753. })["catch"](function () {
  1754. delete sender.sendEncodings;
  1755. }));
  1756. }
  1757. }
  1758. return transceiver;
  1759. };
  1760. }
  1761. }
  1762. function shimGetParameters(window) {
  1763. if (!(_typeof(window) === 'object' && window.RTCRtpSender)) {
  1764. return;
  1765. }
  1766. var origGetParameters = window.RTCRtpSender.prototype.getParameters;
  1767. if (origGetParameters) {
  1768. window.RTCRtpSender.prototype.getParameters = function getParameters() {
  1769. var params = origGetParameters.apply(this, arguments);
  1770. if (!('encodings' in params)) {
  1771. params.encodings = [].concat(this.sendEncodings || [{}]);
  1772. }
  1773. return params;
  1774. };
  1775. }
  1776. }
  1777. function shimCreateOffer(window) {
  1778. // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647
  1779. // Firefox ignores the init sendEncodings options passed to addTransceiver
  1780. // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918
  1781. if (!(_typeof(window) === 'object' && window.RTCPeerConnection)) {
  1782. return;
  1783. }
  1784. var origCreateOffer = window.RTCPeerConnection.prototype.createOffer;
  1785. window.RTCPeerConnection.prototype.createOffer = function createOffer() {
  1786. var _arguments2 = arguments,
  1787. _this4 = this;
  1788. if (this.setParametersPromises && this.setParametersPromises.length) {
  1789. return Promise.all(this.setParametersPromises).then(function () {
  1790. return origCreateOffer.apply(_this4, _arguments2);
  1791. })["finally"](function () {
  1792. _this4.setParametersPromises = [];
  1793. });
  1794. }
  1795. return origCreateOffer.apply(this, arguments);
  1796. };
  1797. }
  1798. function shimCreateAnswer(window) {
  1799. // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647
  1800. // Firefox ignores the init sendEncodings options passed to addTransceiver
  1801. // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918
  1802. if (!(_typeof(window) === 'object' && window.RTCPeerConnection)) {
  1803. return;
  1804. }
  1805. var origCreateAnswer = window.RTCPeerConnection.prototype.createAnswer;
  1806. window.RTCPeerConnection.prototype.createAnswer = function createAnswer() {
  1807. var _arguments3 = arguments,
  1808. _this5 = this;
  1809. if (this.setParametersPromises && this.setParametersPromises.length) {
  1810. return Promise.all(this.setParametersPromises).then(function () {
  1811. return origCreateAnswer.apply(_this5, _arguments3);
  1812. })["finally"](function () {
  1813. _this5.setParametersPromises = [];
  1814. });
  1815. }
  1816. return origCreateAnswer.apply(this, arguments);
  1817. };
  1818. }
  1819. },{"../utils":11,"./getdisplaymedia":8,"./getusermedia":9}],8:[function(require,module,exports){
  1820. /*
  1821. * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.
  1822. *
  1823. * Use of this source code is governed by a BSD-style license
  1824. * that can be found in the LICENSE file in the root of the source
  1825. * tree.
  1826. */
  1827. /* eslint-env node */
  1828. 'use strict';
  1829. Object.defineProperty(exports, "__esModule", {
  1830. value: true
  1831. });
  1832. exports.shimGetDisplayMedia = shimGetDisplayMedia;
  1833. function shimGetDisplayMedia(window, preferredMediaSource) {
  1834. if (window.navigator.mediaDevices && 'getDisplayMedia' in window.navigator.mediaDevices) {
  1835. return;
  1836. }
  1837. if (!window.navigator.mediaDevices) {
  1838. return;
  1839. }
  1840. window.navigator.mediaDevices.getDisplayMedia = function getDisplayMedia(constraints) {
  1841. if (!(constraints && constraints.video)) {
  1842. var err = new DOMException('getDisplayMedia without video ' + 'constraints is undefined');
  1843. err.name = 'NotFoundError';
  1844. // from https://heycam.github.io/webidl/#idl-DOMException-error-names
  1845. err.code = 8;
  1846. return Promise.reject(err);
  1847. }
  1848. if (constraints.video === true) {
  1849. constraints.video = {
  1850. mediaSource: preferredMediaSource
  1851. };
  1852. } else {
  1853. constraints.video.mediaSource = preferredMediaSource;
  1854. }
  1855. return window.navigator.mediaDevices.getUserMedia(constraints);
  1856. };
  1857. }
  1858. },{}],9:[function(require,module,exports){
  1859. /*
  1860. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  1861. *
  1862. * Use of this source code is governed by a BSD-style license
  1863. * that can be found in the LICENSE file in the root of the source
  1864. * tree.
  1865. */
  1866. /* eslint-env node */
  1867. 'use strict';
  1868. Object.defineProperty(exports, "__esModule", {
  1869. value: true
  1870. });
  1871. exports.shimGetUserMedia = shimGetUserMedia;
  1872. var utils = _interopRequireWildcard(require("../utils"));
  1873. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  1874. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1875. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  1876. function shimGetUserMedia(window, browserDetails) {
  1877. var navigator = window && window.navigator;
  1878. var MediaStreamTrack = window && window.MediaStreamTrack;
  1879. navigator.getUserMedia = function (constraints, onSuccess, onError) {
  1880. // Replace Firefox 44+'s deprecation warning with unprefixed version.
  1881. utils.deprecated('navigator.getUserMedia', 'navigator.mediaDevices.getUserMedia');
  1882. navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);
  1883. };
  1884. if (!(browserDetails.version > 55 && 'autoGainControl' in navigator.mediaDevices.getSupportedConstraints())) {
  1885. var remap = function remap(obj, a, b) {
  1886. if (a in obj && !(b in obj)) {
  1887. obj[b] = obj[a];
  1888. delete obj[a];
  1889. }
  1890. };
  1891. var nativeGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
  1892. navigator.mediaDevices.getUserMedia = function (c) {
  1893. if (_typeof(c) === 'object' && _typeof(c.audio) === 'object') {
  1894. c = JSON.parse(JSON.stringify(c));
  1895. remap(c.audio, 'autoGainControl', 'mozAutoGainControl');
  1896. remap(c.audio, 'noiseSuppression', 'mozNoiseSuppression');
  1897. }
  1898. return nativeGetUserMedia(c);
  1899. };
  1900. if (MediaStreamTrack && MediaStreamTrack.prototype.getSettings) {
  1901. var nativeGetSettings = MediaStreamTrack.prototype.getSettings;
  1902. MediaStreamTrack.prototype.getSettings = function () {
  1903. var obj = nativeGetSettings.apply(this, arguments);
  1904. remap(obj, 'mozAutoGainControl', 'autoGainControl');
  1905. remap(obj, 'mozNoiseSuppression', 'noiseSuppression');
  1906. return obj;
  1907. };
  1908. }
  1909. if (MediaStreamTrack && MediaStreamTrack.prototype.applyConstraints) {
  1910. var nativeApplyConstraints = MediaStreamTrack.prototype.applyConstraints;
  1911. MediaStreamTrack.prototype.applyConstraints = function (c) {
  1912. if (this.kind === 'audio' && _typeof(c) === 'object') {
  1913. c = JSON.parse(JSON.stringify(c));
  1914. remap(c, 'autoGainControl', 'mozAutoGainControl');
  1915. remap(c, 'noiseSuppression', 'mozNoiseSuppression');
  1916. }
  1917. return nativeApplyConstraints.apply(this, [c]);
  1918. };
  1919. }
  1920. }
  1921. }
  1922. },{"../utils":11}],10:[function(require,module,exports){
  1923. /*
  1924. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  1925. *
  1926. * Use of this source code is governed by a BSD-style license
  1927. * that can be found in the LICENSE file in the root of the source
  1928. * tree.
  1929. */
  1930. 'use strict';
  1931. Object.defineProperty(exports, "__esModule", {
  1932. value: true
  1933. });
  1934. exports.shimAudioContext = shimAudioContext;
  1935. exports.shimCallbacksAPI = shimCallbacksAPI;
  1936. exports.shimConstraints = shimConstraints;
  1937. exports.shimCreateOfferLegacy = shimCreateOfferLegacy;
  1938. exports.shimGetUserMedia = shimGetUserMedia;
  1939. exports.shimLocalStreamsAPI = shimLocalStreamsAPI;
  1940. exports.shimRTCIceServerUrls = shimRTCIceServerUrls;
  1941. exports.shimRemoteStreamsAPI = shimRemoteStreamsAPI;
  1942. exports.shimTrackEventTransceiver = shimTrackEventTransceiver;
  1943. var utils = _interopRequireWildcard(require("../utils"));
  1944. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  1945. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  1946. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  1947. function shimLocalStreamsAPI(window) {
  1948. if (_typeof(window) !== 'object' || !window.RTCPeerConnection) {
  1949. return;
  1950. }
  1951. if (!('getLocalStreams' in window.RTCPeerConnection.prototype)) {
  1952. window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
  1953. if (!this._localStreams) {
  1954. this._localStreams = [];
  1955. }
  1956. return this._localStreams;
  1957. };
  1958. }
  1959. if (!('addStream' in window.RTCPeerConnection.prototype)) {
  1960. var _addTrack = window.RTCPeerConnection.prototype.addTrack;
  1961. window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
  1962. var _this = this;
  1963. if (!this._localStreams) {
  1964. this._localStreams = [];
  1965. }
  1966. if (!this._localStreams.includes(stream)) {
  1967. this._localStreams.push(stream);
  1968. }
  1969. // Try to emulate Chrome's behaviour of adding in audio-video order.
  1970. // Safari orders by track id.
  1971. stream.getAudioTracks().forEach(function (track) {
  1972. return _addTrack.call(_this, track, stream);
  1973. });
  1974. stream.getVideoTracks().forEach(function (track) {
  1975. return _addTrack.call(_this, track, stream);
  1976. });
  1977. };
  1978. window.RTCPeerConnection.prototype.addTrack = function addTrack(track) {
  1979. var _this2 = this;
  1980. for (var _len = arguments.length, streams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1981. streams[_key - 1] = arguments[_key];
  1982. }
  1983. if (streams) {
  1984. streams.forEach(function (stream) {
  1985. if (!_this2._localStreams) {
  1986. _this2._localStreams = [stream];
  1987. } else if (!_this2._localStreams.includes(stream)) {
  1988. _this2._localStreams.push(stream);
  1989. }
  1990. });
  1991. }
  1992. return _addTrack.apply(this, arguments);
  1993. };
  1994. }
  1995. if (!('removeStream' in window.RTCPeerConnection.prototype)) {
  1996. window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
  1997. var _this3 = this;
  1998. if (!this._localStreams) {
  1999. this._localStreams = [];
  2000. }
  2001. var index = this._localStreams.indexOf(stream);
  2002. if (index === -1) {
  2003. return;
  2004. }
  2005. this._localStreams.splice(index, 1);
  2006. var tracks = stream.getTracks();
  2007. this.getSenders().forEach(function (sender) {
  2008. if (tracks.includes(sender.track)) {
  2009. _this3.removeTrack(sender);
  2010. }
  2011. });
  2012. };
  2013. }
  2014. }
  2015. function shimRemoteStreamsAPI(window) {
  2016. if (_typeof(window) !== 'object' || !window.RTCPeerConnection) {
  2017. return;
  2018. }
  2019. if (!('getRemoteStreams' in window.RTCPeerConnection.prototype)) {
  2020. window.RTCPeerConnection.prototype.getRemoteStreams = function getRemoteStreams() {
  2021. return this._remoteStreams ? this._remoteStreams : [];
  2022. };
  2023. }
  2024. if (!('onaddstream' in window.RTCPeerConnection.prototype)) {
  2025. Object.defineProperty(window.RTCPeerConnection.prototype, 'onaddstream', {
  2026. get: function get() {
  2027. return this._onaddstream;
  2028. },
  2029. set: function set(f) {
  2030. var _this4 = this;
  2031. if (this._onaddstream) {
  2032. this.removeEventListener('addstream', this._onaddstream);
  2033. this.removeEventListener('track', this._onaddstreampoly);
  2034. }
  2035. this.addEventListener('addstream', this._onaddstream = f);
  2036. this.addEventListener('track', this._onaddstreampoly = function (e) {
  2037. e.streams.forEach(function (stream) {
  2038. if (!_this4._remoteStreams) {
  2039. _this4._remoteStreams = [];
  2040. }
  2041. if (_this4._remoteStreams.includes(stream)) {
  2042. return;
  2043. }
  2044. _this4._remoteStreams.push(stream);
  2045. var event = new Event('addstream');
  2046. event.stream = stream;
  2047. _this4.dispatchEvent(event);
  2048. });
  2049. });
  2050. }
  2051. });
  2052. var origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
  2053. window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription() {
  2054. var pc = this;
  2055. if (!this._onaddstreampoly) {
  2056. this.addEventListener('track', this._onaddstreampoly = function (e) {
  2057. e.streams.forEach(function (stream) {
  2058. if (!pc._remoteStreams) {
  2059. pc._remoteStreams = [];
  2060. }
  2061. if (pc._remoteStreams.indexOf(stream) >= 0) {
  2062. return;
  2063. }
  2064. pc._remoteStreams.push(stream);
  2065. var event = new Event('addstream');
  2066. event.stream = stream;
  2067. pc.dispatchEvent(event);
  2068. });
  2069. });
  2070. }
  2071. return origSetRemoteDescription.apply(pc, arguments);
  2072. };
  2073. }
  2074. }
  2075. function shimCallbacksAPI(window) {
  2076. if (_typeof(window) !== 'object' || !window.RTCPeerConnection) {
  2077. return;
  2078. }
  2079. var prototype = window.RTCPeerConnection.prototype;
  2080. var origCreateOffer = prototype.createOffer;
  2081. var origCreateAnswer = prototype.createAnswer;
  2082. var setLocalDescription = prototype.setLocalDescription;
  2083. var setRemoteDescription = prototype.setRemoteDescription;
  2084. var addIceCandidate = prototype.addIceCandidate;
  2085. prototype.createOffer = function createOffer(successCallback, failureCallback) {
  2086. var options = arguments.length >= 2 ? arguments[2] : arguments[0];
  2087. var promise = origCreateOffer.apply(this, [options]);
  2088. if (!failureCallback) {
  2089. return promise;
  2090. }
  2091. promise.then(successCallback, failureCallback);
  2092. return Promise.resolve();
  2093. };
  2094. prototype.createAnswer = function createAnswer(successCallback, failureCallback) {
  2095. var options = arguments.length >= 2 ? arguments[2] : arguments[0];
  2096. var promise = origCreateAnswer.apply(this, [options]);
  2097. if (!failureCallback) {
  2098. return promise;
  2099. }
  2100. promise.then(successCallback, failureCallback);
  2101. return Promise.resolve();
  2102. };
  2103. var withCallback = function withCallback(description, successCallback, failureCallback) {
  2104. var promise = setLocalDescription.apply(this, [description]);
  2105. if (!failureCallback) {
  2106. return promise;
  2107. }
  2108. promise.then(successCallback, failureCallback);
  2109. return Promise.resolve();
  2110. };
  2111. prototype.setLocalDescription = withCallback;
  2112. withCallback = function withCallback(description, successCallback, failureCallback) {
  2113. var promise = setRemoteDescription.apply(this, [description]);
  2114. if (!failureCallback) {
  2115. return promise;
  2116. }
  2117. promise.then(successCallback, failureCallback);
  2118. return Promise.resolve();
  2119. };
  2120. prototype.setRemoteDescription = withCallback;
  2121. withCallback = function withCallback(candidate, successCallback, failureCallback) {
  2122. var promise = addIceCandidate.apply(this, [candidate]);
  2123. if (!failureCallback) {
  2124. return promise;
  2125. }
  2126. promise.then(successCallback, failureCallback);
  2127. return Promise.resolve();
  2128. };
  2129. prototype.addIceCandidate = withCallback;
  2130. }
  2131. function shimGetUserMedia(window) {
  2132. var navigator = window && window.navigator;
  2133. if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  2134. // shim not needed in Safari 12.1
  2135. var mediaDevices = navigator.mediaDevices;
  2136. var _getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices);
  2137. navigator.mediaDevices.getUserMedia = function (constraints) {
  2138. return _getUserMedia(shimConstraints(constraints));
  2139. };
  2140. }
  2141. if (!navigator.getUserMedia && navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  2142. navigator.getUserMedia = function getUserMedia(constraints, cb, errcb) {
  2143. navigator.mediaDevices.getUserMedia(constraints).then(cb, errcb);
  2144. }.bind(navigator);
  2145. }
  2146. }
  2147. function shimConstraints(constraints) {
  2148. if (constraints && constraints.video !== undefined) {
  2149. return Object.assign({}, constraints, {
  2150. video: utils.compactObject(constraints.video)
  2151. });
  2152. }
  2153. return constraints;
  2154. }
  2155. function shimRTCIceServerUrls(window) {
  2156. if (!window.RTCPeerConnection) {
  2157. return;
  2158. }
  2159. // migrate from non-spec RTCIceServer.url to RTCIceServer.urls
  2160. var OrigPeerConnection = window.RTCPeerConnection;
  2161. window.RTCPeerConnection = function RTCPeerConnection(pcConfig, pcConstraints) {
  2162. if (pcConfig && pcConfig.iceServers) {
  2163. var newIceServers = [];
  2164. for (var i = 0; i < pcConfig.iceServers.length; i++) {
  2165. var server = pcConfig.iceServers[i];
  2166. if (server.urls === undefined && server.url) {
  2167. utils.deprecated('RTCIceServer.url', 'RTCIceServer.urls');
  2168. server = JSON.parse(JSON.stringify(server));
  2169. server.urls = server.url;
  2170. delete server.url;
  2171. newIceServers.push(server);
  2172. } else {
  2173. newIceServers.push(pcConfig.iceServers[i]);
  2174. }
  2175. }
  2176. pcConfig.iceServers = newIceServers;
  2177. }
  2178. return new OrigPeerConnection(pcConfig, pcConstraints);
  2179. };
  2180. window.RTCPeerConnection.prototype = OrigPeerConnection.prototype;
  2181. // wrap static methods. Currently just generateCertificate.
  2182. if ('generateCertificate' in OrigPeerConnection) {
  2183. Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
  2184. get: function get() {
  2185. return OrigPeerConnection.generateCertificate;
  2186. }
  2187. });
  2188. }
  2189. }
  2190. function shimTrackEventTransceiver(window) {
  2191. // Add event.transceiver member over deprecated event.receiver
  2192. if (_typeof(window) === 'object' && window.RTCTrackEvent && 'receiver' in window.RTCTrackEvent.prototype && !('transceiver' in window.RTCTrackEvent.prototype)) {
  2193. Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {
  2194. get: function get() {
  2195. return {
  2196. receiver: this.receiver
  2197. };
  2198. }
  2199. });
  2200. }
  2201. }
  2202. function shimCreateOfferLegacy(window) {
  2203. var origCreateOffer = window.RTCPeerConnection.prototype.createOffer;
  2204. window.RTCPeerConnection.prototype.createOffer = function createOffer(offerOptions) {
  2205. if (offerOptions) {
  2206. if (typeof offerOptions.offerToReceiveAudio !== 'undefined') {
  2207. // support bit values
  2208. offerOptions.offerToReceiveAudio = !!offerOptions.offerToReceiveAudio;
  2209. }
  2210. var audioTransceiver = this.getTransceivers().find(function (transceiver) {
  2211. return transceiver.receiver.track.kind === 'audio';
  2212. });
  2213. if (offerOptions.offerToReceiveAudio === false && audioTransceiver) {
  2214. if (audioTransceiver.direction === 'sendrecv') {
  2215. if (audioTransceiver.setDirection) {
  2216. audioTransceiver.setDirection('sendonly');
  2217. } else {
  2218. audioTransceiver.direction = 'sendonly';
  2219. }
  2220. } else if (audioTransceiver.direction === 'recvonly') {
  2221. if (audioTransceiver.setDirection) {
  2222. audioTransceiver.setDirection('inactive');
  2223. } else {
  2224. audioTransceiver.direction = 'inactive';
  2225. }
  2226. }
  2227. } else if (offerOptions.offerToReceiveAudio === true && !audioTransceiver) {
  2228. this.addTransceiver('audio', {
  2229. direction: 'recvonly'
  2230. });
  2231. }
  2232. if (typeof offerOptions.offerToReceiveVideo !== 'undefined') {
  2233. // support bit values
  2234. offerOptions.offerToReceiveVideo = !!offerOptions.offerToReceiveVideo;
  2235. }
  2236. var videoTransceiver = this.getTransceivers().find(function (transceiver) {
  2237. return transceiver.receiver.track.kind === 'video';
  2238. });
  2239. if (offerOptions.offerToReceiveVideo === false && videoTransceiver) {
  2240. if (videoTransceiver.direction === 'sendrecv') {
  2241. if (videoTransceiver.setDirection) {
  2242. videoTransceiver.setDirection('sendonly');
  2243. } else {
  2244. videoTransceiver.direction = 'sendonly';
  2245. }
  2246. } else if (videoTransceiver.direction === 'recvonly') {
  2247. if (videoTransceiver.setDirection) {
  2248. videoTransceiver.setDirection('inactive');
  2249. } else {
  2250. videoTransceiver.direction = 'inactive';
  2251. }
  2252. }
  2253. } else if (offerOptions.offerToReceiveVideo === true && !videoTransceiver) {
  2254. this.addTransceiver('video', {
  2255. direction: 'recvonly'
  2256. });
  2257. }
  2258. }
  2259. return origCreateOffer.apply(this, arguments);
  2260. };
  2261. }
  2262. function shimAudioContext(window) {
  2263. if (_typeof(window) !== 'object' || window.AudioContext) {
  2264. return;
  2265. }
  2266. window.AudioContext = window.webkitAudioContext;
  2267. }
  2268. },{"../utils":11}],11:[function(require,module,exports){
  2269. /*
  2270. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  2271. *
  2272. * Use of this source code is governed by a BSD-style license
  2273. * that can be found in the LICENSE file in the root of the source
  2274. * tree.
  2275. */
  2276. /* eslint-env node */
  2277. 'use strict';
  2278. Object.defineProperty(exports, "__esModule", {
  2279. value: true
  2280. });
  2281. exports.compactObject = compactObject;
  2282. exports.deprecated = deprecated;
  2283. exports.detectBrowser = detectBrowser;
  2284. exports.disableLog = disableLog;
  2285. exports.disableWarnings = disableWarnings;
  2286. exports.extractVersion = extractVersion;
  2287. exports.filterStats = filterStats;
  2288. exports.log = log;
  2289. exports.walkStats = walkStats;
  2290. exports.wrapPeerConnectionEvent = wrapPeerConnectionEvent;
  2291. function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  2292. function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
  2293. function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
  2294. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  2295. var logDisabled_ = true;
  2296. var deprecationWarnings_ = true;
  2297. /**
  2298. * Extract browser version out of the provided user agent string.
  2299. *
  2300. * @param {!string} uastring userAgent string.
  2301. * @param {!string} expr Regular expression used as match criteria.
  2302. * @param {!number} pos position in the version string to be returned.
  2303. * @return {!number} browser version.
  2304. */
  2305. function extractVersion(uastring, expr, pos) {
  2306. var match = uastring.match(expr);
  2307. return match && match.length >= pos && parseInt(match[pos], 10);
  2308. }
  2309. // Wraps the peerconnection event eventNameToWrap in a function
  2310. // which returns the modified event object (or false to prevent
  2311. // the event).
  2312. function wrapPeerConnectionEvent(window, eventNameToWrap, wrapper) {
  2313. if (!window.RTCPeerConnection) {
  2314. return;
  2315. }
  2316. var proto = window.RTCPeerConnection.prototype;
  2317. var nativeAddEventListener = proto.addEventListener;
  2318. proto.addEventListener = function (nativeEventName, cb) {
  2319. if (nativeEventName !== eventNameToWrap) {
  2320. return nativeAddEventListener.apply(this, arguments);
  2321. }
  2322. var wrappedCallback = function wrappedCallback(e) {
  2323. var modifiedEvent = wrapper(e);
  2324. if (modifiedEvent) {
  2325. if (cb.handleEvent) {
  2326. cb.handleEvent(modifiedEvent);
  2327. } else {
  2328. cb(modifiedEvent);
  2329. }
  2330. }
  2331. };
  2332. this._eventMap = this._eventMap || {};
  2333. if (!this._eventMap[eventNameToWrap]) {
  2334. this._eventMap[eventNameToWrap] = new Map();
  2335. }
  2336. this._eventMap[eventNameToWrap].set(cb, wrappedCallback);
  2337. return nativeAddEventListener.apply(this, [nativeEventName, wrappedCallback]);
  2338. };
  2339. var nativeRemoveEventListener = proto.removeEventListener;
  2340. proto.removeEventListener = function (nativeEventName, cb) {
  2341. if (nativeEventName !== eventNameToWrap || !this._eventMap || !this._eventMap[eventNameToWrap]) {
  2342. return nativeRemoveEventListener.apply(this, arguments);
  2343. }
  2344. if (!this._eventMap[eventNameToWrap].has(cb)) {
  2345. return nativeRemoveEventListener.apply(this, arguments);
  2346. }
  2347. var unwrappedCb = this._eventMap[eventNameToWrap].get(cb);
  2348. this._eventMap[eventNameToWrap]["delete"](cb);
  2349. if (this._eventMap[eventNameToWrap].size === 0) {
  2350. delete this._eventMap[eventNameToWrap];
  2351. }
  2352. if (Object.keys(this._eventMap).length === 0) {
  2353. delete this._eventMap;
  2354. }
  2355. return nativeRemoveEventListener.apply(this, [nativeEventName, unwrappedCb]);
  2356. };
  2357. Object.defineProperty(proto, 'on' + eventNameToWrap, {
  2358. get: function get() {
  2359. return this['_on' + eventNameToWrap];
  2360. },
  2361. set: function set(cb) {
  2362. if (this['_on' + eventNameToWrap]) {
  2363. this.removeEventListener(eventNameToWrap, this['_on' + eventNameToWrap]);
  2364. delete this['_on' + eventNameToWrap];
  2365. }
  2366. if (cb) {
  2367. this.addEventListener(eventNameToWrap, this['_on' + eventNameToWrap] = cb);
  2368. }
  2369. },
  2370. enumerable: true,
  2371. configurable: true
  2372. });
  2373. }
  2374. function disableLog(bool) {
  2375. if (typeof bool !== 'boolean') {
  2376. return new Error('Argument type: ' + _typeof(bool) + '. Please use a boolean.');
  2377. }
  2378. logDisabled_ = bool;
  2379. return bool ? 'adapter.js logging disabled' : 'adapter.js logging enabled';
  2380. }
  2381. /**
  2382. * Disable or enable deprecation warnings
  2383. * @param {!boolean} bool set to true to disable warnings.
  2384. */
  2385. function disableWarnings(bool) {
  2386. if (typeof bool !== 'boolean') {
  2387. return new Error('Argument type: ' + _typeof(bool) + '. Please use a boolean.');
  2388. }
  2389. deprecationWarnings_ = !bool;
  2390. return 'adapter.js deprecation warnings ' + (bool ? 'disabled' : 'enabled');
  2391. }
  2392. function log() {
  2393. if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object') {
  2394. if (logDisabled_) {
  2395. return;
  2396. }
  2397. if (typeof console !== 'undefined' && typeof console.log === 'function') {
  2398. console.log.apply(console, arguments);
  2399. }
  2400. }
  2401. }
  2402. /**
  2403. * Shows a deprecation warning suggesting the modern and spec-compatible API.
  2404. */
  2405. function deprecated(oldMethod, newMethod) {
  2406. if (!deprecationWarnings_) {
  2407. return;
  2408. }
  2409. console.warn(oldMethod + ' is deprecated, please use ' + newMethod + ' instead.');
  2410. }
  2411. /**
  2412. * Browser detector.
  2413. *
  2414. * @return {object} result containing browser and version
  2415. * properties.
  2416. */
  2417. function detectBrowser(window) {
  2418. // Returned result object.
  2419. var result = {
  2420. browser: null,
  2421. version: null
  2422. };
  2423. // Fail early if it's not a browser
  2424. if (typeof window === 'undefined' || !window.navigator || !window.navigator.userAgent) {
  2425. result.browser = 'Not a browser.';
  2426. return result;
  2427. }
  2428. var navigator = window.navigator;
  2429. if (navigator.mozGetUserMedia) {
  2430. // Firefox.
  2431. result.browser = 'firefox';
  2432. result.version = extractVersion(navigator.userAgent, /Firefox\/(\d+)\./, 1);
  2433. } else if (navigator.webkitGetUserMedia || window.isSecureContext === false && window.webkitRTCPeerConnection) {
  2434. // Chrome, Chromium, Webview, Opera.
  2435. // Version matches Chrome/WebRTC version.
  2436. // Chrome 74 removed webkitGetUserMedia on http as well so we need the
  2437. // more complicated fallback to webkitRTCPeerConnection.
  2438. result.browser = 'chrome';
  2439. result.version = extractVersion(navigator.userAgent, /Chrom(e|ium)\/(\d+)\./, 2);
  2440. } else if (window.RTCPeerConnection && navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) {
  2441. // Safari.
  2442. result.browser = 'safari';
  2443. result.version = extractVersion(navigator.userAgent, /AppleWebKit\/(\d+)\./, 1);
  2444. result.supportsUnifiedPlan = window.RTCRtpTransceiver && 'currentDirection' in window.RTCRtpTransceiver.prototype;
  2445. } else {
  2446. // Default fallthrough: not supported.
  2447. result.browser = 'Not a supported browser.';
  2448. return result;
  2449. }
  2450. return result;
  2451. }
  2452. /**
  2453. * Checks if something is an object.
  2454. *
  2455. * @param {*} val The something you want to check.
  2456. * @return true if val is an object, false otherwise.
  2457. */
  2458. function isObject(val) {
  2459. return Object.prototype.toString.call(val) === '[object Object]';
  2460. }
  2461. /**
  2462. * Remove all empty objects and undefined values
  2463. * from a nested object -- an enhanced and vanilla version
  2464. * of Lodash's `compact`.
  2465. */
  2466. function compactObject(data) {
  2467. if (!isObject(data)) {
  2468. return data;
  2469. }
  2470. return Object.keys(data).reduce(function (accumulator, key) {
  2471. var isObj = isObject(data[key]);
  2472. var value = isObj ? compactObject(data[key]) : data[key];
  2473. var isEmptyObject = isObj && !Object.keys(value).length;
  2474. if (value === undefined || isEmptyObject) {
  2475. return accumulator;
  2476. }
  2477. return Object.assign(accumulator, _defineProperty({}, key, value));
  2478. }, {});
  2479. }
  2480. /* iterates the stats graph recursively. */
  2481. function walkStats(stats, base, resultSet) {
  2482. if (!base || resultSet.has(base.id)) {
  2483. return;
  2484. }
  2485. resultSet.set(base.id, base);
  2486. Object.keys(base).forEach(function (name) {
  2487. if (name.endsWith('Id')) {
  2488. walkStats(stats, stats.get(base[name]), resultSet);
  2489. } else if (name.endsWith('Ids')) {
  2490. base[name].forEach(function (id) {
  2491. walkStats(stats, stats.get(id), resultSet);
  2492. });
  2493. }
  2494. });
  2495. }
  2496. /* filter getStats for a sender/receiver track. */
  2497. function filterStats(result, track, outbound) {
  2498. var streamStatsType = outbound ? 'outbound-rtp' : 'inbound-rtp';
  2499. var filteredResult = new Map();
  2500. if (track === null) {
  2501. return filteredResult;
  2502. }
  2503. var trackStats = [];
  2504. result.forEach(function (value) {
  2505. if (value.type === 'track' && value.trackIdentifier === track.id) {
  2506. trackStats.push(value);
  2507. }
  2508. });
  2509. trackStats.forEach(function (trackStat) {
  2510. result.forEach(function (stats) {
  2511. if (stats.type === streamStatsType && stats.trackId === trackStat.id) {
  2512. walkStats(result, stats, filteredResult);
  2513. }
  2514. });
  2515. });
  2516. return filteredResult;
  2517. }
  2518. },{}],12:[function(require,module,exports){
  2519. /* eslint-env node */
  2520. 'use strict';
  2521. // SDP helpers.
  2522. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2523. var SDPUtils = {};
  2524. // Generate an alphanumeric identifier for cname or mids.
  2525. // TODO: use UUIDs instead? https://gist.github.com/jed/982883
  2526. SDPUtils.generateIdentifier = function () {
  2527. return Math.random().toString(36).substring(2, 12);
  2528. };
  2529. // The RTCP CNAME used by all peerconnections from the same JS.
  2530. SDPUtils.localCName = SDPUtils.generateIdentifier();
  2531. // Splits SDP into lines, dealing with both CRLF and LF.
  2532. SDPUtils.splitLines = function (blob) {
  2533. return blob.trim().split('\n').map(function (line) {
  2534. return line.trim();
  2535. });
  2536. };
  2537. // Splits SDP into sessionpart and mediasections. Ensures CRLF.
  2538. SDPUtils.splitSections = function (blob) {
  2539. var parts = blob.split('\nm=');
  2540. return parts.map(function (part, index) {
  2541. return (index > 0 ? 'm=' + part : part).trim() + '\r\n';
  2542. });
  2543. };
  2544. // Returns the session description.
  2545. SDPUtils.getDescription = function (blob) {
  2546. var sections = SDPUtils.splitSections(blob);
  2547. return sections && sections[0];
  2548. };
  2549. // Returns the individual media sections.
  2550. SDPUtils.getMediaSections = function (blob) {
  2551. var sections = SDPUtils.splitSections(blob);
  2552. sections.shift();
  2553. return sections;
  2554. };
  2555. // Returns lines that start with a certain prefix.
  2556. SDPUtils.matchPrefix = function (blob, prefix) {
  2557. return SDPUtils.splitLines(blob).filter(function (line) {
  2558. return line.indexOf(prefix) === 0;
  2559. });
  2560. };
  2561. // Parses an ICE candidate line. Sample input:
  2562. // candidate:702786350 2 udp 41819902 8.8.8.8 60769 typ relay raddr 8.8.8.8
  2563. // rport 55996"
  2564. // Input can be prefixed with a=.
  2565. SDPUtils.parseCandidate = function (line) {
  2566. var parts = void 0;
  2567. // Parse both variants.
  2568. if (line.indexOf('a=candidate:') === 0) {
  2569. parts = line.substring(12).split(' ');
  2570. } else {
  2571. parts = line.substring(10).split(' ');
  2572. }
  2573. var candidate = {
  2574. foundation: parts[0],
  2575. component: { 1: 'rtp', 2: 'rtcp' }[parts[1]] || parts[1],
  2576. protocol: parts[2].toLowerCase(),
  2577. priority: parseInt(parts[3], 10),
  2578. ip: parts[4],
  2579. address: parts[4], // address is an alias for ip.
  2580. port: parseInt(parts[5], 10),
  2581. // skip parts[6] == 'typ'
  2582. type: parts[7]
  2583. };
  2584. for (var i = 8; i < parts.length; i += 2) {
  2585. switch (parts[i]) {
  2586. case 'raddr':
  2587. candidate.relatedAddress = parts[i + 1];
  2588. break;
  2589. case 'rport':
  2590. candidate.relatedPort = parseInt(parts[i + 1], 10);
  2591. break;
  2592. case 'tcptype':
  2593. candidate.tcpType = parts[i + 1];
  2594. break;
  2595. case 'ufrag':
  2596. candidate.ufrag = parts[i + 1]; // for backward compatibility.
  2597. candidate.usernameFragment = parts[i + 1];
  2598. break;
  2599. default:
  2600. // extension handling, in particular ufrag. Don't overwrite.
  2601. if (candidate[parts[i]] === undefined) {
  2602. candidate[parts[i]] = parts[i + 1];
  2603. }
  2604. break;
  2605. }
  2606. }
  2607. return candidate;
  2608. };
  2609. // Translates a candidate object into SDP candidate attribute.
  2610. // This does not include the a= prefix!
  2611. SDPUtils.writeCandidate = function (candidate) {
  2612. var sdp = [];
  2613. sdp.push(candidate.foundation);
  2614. var component = candidate.component;
  2615. if (component === 'rtp') {
  2616. sdp.push(1);
  2617. } else if (component === 'rtcp') {
  2618. sdp.push(2);
  2619. } else {
  2620. sdp.push(component);
  2621. }
  2622. sdp.push(candidate.protocol.toUpperCase());
  2623. sdp.push(candidate.priority);
  2624. sdp.push(candidate.address || candidate.ip);
  2625. sdp.push(candidate.port);
  2626. var type = candidate.type;
  2627. sdp.push('typ');
  2628. sdp.push(type);
  2629. if (type !== 'host' && candidate.relatedAddress && candidate.relatedPort) {
  2630. sdp.push('raddr');
  2631. sdp.push(candidate.relatedAddress);
  2632. sdp.push('rport');
  2633. sdp.push(candidate.relatedPort);
  2634. }
  2635. if (candidate.tcpType && candidate.protocol.toLowerCase() === 'tcp') {
  2636. sdp.push('tcptype');
  2637. sdp.push(candidate.tcpType);
  2638. }
  2639. if (candidate.usernameFragment || candidate.ufrag) {
  2640. sdp.push('ufrag');
  2641. sdp.push(candidate.usernameFragment || candidate.ufrag);
  2642. }
  2643. return 'candidate:' + sdp.join(' ');
  2644. };
  2645. // Parses an ice-options line, returns an array of option tags.
  2646. // Sample input:
  2647. // a=ice-options:foo bar
  2648. SDPUtils.parseIceOptions = function (line) {
  2649. return line.substring(14).split(' ');
  2650. };
  2651. // Parses a rtpmap line, returns RTCRtpCoddecParameters. Sample input:
  2652. // a=rtpmap:111 opus/48000/2
  2653. SDPUtils.parseRtpMap = function (line) {
  2654. var parts = line.substring(9).split(' ');
  2655. var parsed = {
  2656. payloadType: parseInt(parts.shift(), 10) // was: id
  2657. };
  2658. parts = parts[0].split('/');
  2659. parsed.name = parts[0];
  2660. parsed.clockRate = parseInt(parts[1], 10); // was: clockrate
  2661. parsed.channels = parts.length === 3 ? parseInt(parts[2], 10) : 1;
  2662. // legacy alias, got renamed back to channels in ORTC.
  2663. parsed.numChannels = parsed.channels;
  2664. return parsed;
  2665. };
  2666. // Generates a rtpmap line from RTCRtpCodecCapability or
  2667. // RTCRtpCodecParameters.
  2668. SDPUtils.writeRtpMap = function (codec) {
  2669. var pt = codec.payloadType;
  2670. if (codec.preferredPayloadType !== undefined) {
  2671. pt = codec.preferredPayloadType;
  2672. }
  2673. var channels = codec.channels || codec.numChannels || 1;
  2674. return 'a=rtpmap:' + pt + ' ' + codec.name + '/' + codec.clockRate + (channels !== 1 ? '/' + channels : '') + '\r\n';
  2675. };
  2676. // Parses a extmap line (headerextension from RFC 5285). Sample input:
  2677. // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  2678. // a=extmap:2/sendonly urn:ietf:params:rtp-hdrext:toffset
  2679. SDPUtils.parseExtmap = function (line) {
  2680. var parts = line.substring(9).split(' ');
  2681. return {
  2682. id: parseInt(parts[0], 10),
  2683. direction: parts[0].indexOf('/') > 0 ? parts[0].split('/')[1] : 'sendrecv',
  2684. uri: parts[1],
  2685. attributes: parts.slice(2).join(' ')
  2686. };
  2687. };
  2688. // Generates an extmap line from RTCRtpHeaderExtensionParameters or
  2689. // RTCRtpHeaderExtension.
  2690. SDPUtils.writeExtmap = function (headerExtension) {
  2691. return 'a=extmap:' + (headerExtension.id || headerExtension.preferredId) + (headerExtension.direction && headerExtension.direction !== 'sendrecv' ? '/' + headerExtension.direction : '') + ' ' + headerExtension.uri + (headerExtension.attributes ? ' ' + headerExtension.attributes : '') + '\r\n';
  2692. };
  2693. // Parses a fmtp line, returns dictionary. Sample input:
  2694. // a=fmtp:96 vbr=on;cng=on
  2695. // Also deals with vbr=on; cng=on
  2696. SDPUtils.parseFmtp = function (line) {
  2697. var parsed = {};
  2698. var kv = void 0;
  2699. var parts = line.substring(line.indexOf(' ') + 1).split(';');
  2700. for (var j = 0; j < parts.length; j++) {
  2701. kv = parts[j].trim().split('=');
  2702. parsed[kv[0].trim()] = kv[1];
  2703. }
  2704. return parsed;
  2705. };
  2706. // Generates a fmtp line from RTCRtpCodecCapability or RTCRtpCodecParameters.
  2707. SDPUtils.writeFmtp = function (codec) {
  2708. var line = '';
  2709. var pt = codec.payloadType;
  2710. if (codec.preferredPayloadType !== undefined) {
  2711. pt = codec.preferredPayloadType;
  2712. }
  2713. if (codec.parameters && Object.keys(codec.parameters).length) {
  2714. var params = [];
  2715. Object.keys(codec.parameters).forEach(function (param) {
  2716. if (codec.parameters[param] !== undefined) {
  2717. params.push(param + '=' + codec.parameters[param]);
  2718. } else {
  2719. params.push(param);
  2720. }
  2721. });
  2722. line += 'a=fmtp:' + pt + ' ' + params.join(';') + '\r\n';
  2723. }
  2724. return line;
  2725. };
  2726. // Parses a rtcp-fb line, returns RTCPRtcpFeedback object. Sample input:
  2727. // a=rtcp-fb:98 nack rpsi
  2728. SDPUtils.parseRtcpFb = function (line) {
  2729. var parts = line.substring(line.indexOf(' ') + 1).split(' ');
  2730. return {
  2731. type: parts.shift(),
  2732. parameter: parts.join(' ')
  2733. };
  2734. };
  2735. // Generate a=rtcp-fb lines from RTCRtpCodecCapability or RTCRtpCodecParameters.
  2736. SDPUtils.writeRtcpFb = function (codec) {
  2737. var lines = '';
  2738. var pt = codec.payloadType;
  2739. if (codec.preferredPayloadType !== undefined) {
  2740. pt = codec.preferredPayloadType;
  2741. }
  2742. if (codec.rtcpFeedback && codec.rtcpFeedback.length) {
  2743. // FIXME: special handling for trr-int?
  2744. codec.rtcpFeedback.forEach(function (fb) {
  2745. lines += 'a=rtcp-fb:' + pt + ' ' + fb.type + (fb.parameter && fb.parameter.length ? ' ' + fb.parameter : '') + '\r\n';
  2746. });
  2747. }
  2748. return lines;
  2749. };
  2750. // Parses a RFC 5576 ssrc media attribute. Sample input:
  2751. // a=ssrc:3735928559 cname:something
  2752. SDPUtils.parseSsrcMedia = function (line) {
  2753. var sp = line.indexOf(' ');
  2754. var parts = {
  2755. ssrc: parseInt(line.substring(7, sp), 10)
  2756. };
  2757. var colon = line.indexOf(':', sp);
  2758. if (colon > -1) {
  2759. parts.attribute = line.substring(sp + 1, colon);
  2760. parts.value = line.substring(colon + 1);
  2761. } else {
  2762. parts.attribute = line.substring(sp + 1);
  2763. }
  2764. return parts;
  2765. };
  2766. // Parse a ssrc-group line (see RFC 5576). Sample input:
  2767. // a=ssrc-group:semantics 12 34
  2768. SDPUtils.parseSsrcGroup = function (line) {
  2769. var parts = line.substring(13).split(' ');
  2770. return {
  2771. semantics: parts.shift(),
  2772. ssrcs: parts.map(function (ssrc) {
  2773. return parseInt(ssrc, 10);
  2774. })
  2775. };
  2776. };
  2777. // Extracts the MID (RFC 5888) from a media section.
  2778. // Returns the MID or undefined if no mid line was found.
  2779. SDPUtils.getMid = function (mediaSection) {
  2780. var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:')[0];
  2781. if (mid) {
  2782. return mid.substring(6);
  2783. }
  2784. };
  2785. // Parses a fingerprint line for DTLS-SRTP.
  2786. SDPUtils.parseFingerprint = function (line) {
  2787. var parts = line.substring(14).split(' ');
  2788. return {
  2789. algorithm: parts[0].toLowerCase(), // algorithm is case-sensitive in Edge.
  2790. value: parts[1].toUpperCase() // the definition is upper-case in RFC 4572.
  2791. };
  2792. };
  2793. // Extracts DTLS parameters from SDP media section or sessionpart.
  2794. // FIXME: for consistency with other functions this should only
  2795. // get the fingerprint line as input. See also getIceParameters.
  2796. SDPUtils.getDtlsParameters = function (mediaSection, sessionpart) {
  2797. var lines = SDPUtils.matchPrefix(mediaSection + sessionpart, 'a=fingerprint:');
  2798. // Note: a=setup line is ignored since we use the 'auto' role in Edge.
  2799. return {
  2800. role: 'auto',
  2801. fingerprints: lines.map(SDPUtils.parseFingerprint)
  2802. };
  2803. };
  2804. // Serializes DTLS parameters to SDP.
  2805. SDPUtils.writeDtlsParameters = function (params, setupType) {
  2806. var sdp = 'a=setup:' + setupType + '\r\n';
  2807. params.fingerprints.forEach(function (fp) {
  2808. sdp += 'a=fingerprint:' + fp.algorithm + ' ' + fp.value + '\r\n';
  2809. });
  2810. return sdp;
  2811. };
  2812. // Parses a=crypto lines into
  2813. // https://rawgit.com/aboba/edgertc/master/msortc-rs4.html#dictionary-rtcsrtpsdesparameters-members
  2814. SDPUtils.parseCryptoLine = function (line) {
  2815. var parts = line.substring(9).split(' ');
  2816. return {
  2817. tag: parseInt(parts[0], 10),
  2818. cryptoSuite: parts[1],
  2819. keyParams: parts[2],
  2820. sessionParams: parts.slice(3)
  2821. };
  2822. };
  2823. SDPUtils.writeCryptoLine = function (parameters) {
  2824. return 'a=crypto:' + parameters.tag + ' ' + parameters.cryptoSuite + ' ' + (_typeof(parameters.keyParams) === 'object' ? SDPUtils.writeCryptoKeyParams(parameters.keyParams) : parameters.keyParams) + (parameters.sessionParams ? ' ' + parameters.sessionParams.join(' ') : '') + '\r\n';
  2825. };
  2826. // Parses the crypto key parameters into
  2827. // https://rawgit.com/aboba/edgertc/master/msortc-rs4.html#rtcsrtpkeyparam*
  2828. SDPUtils.parseCryptoKeyParams = function (keyParams) {
  2829. if (keyParams.indexOf('inline:') !== 0) {
  2830. return null;
  2831. }
  2832. var parts = keyParams.substring(7).split('|');
  2833. return {
  2834. keyMethod: 'inline',
  2835. keySalt: parts[0],
  2836. lifeTime: parts[1],
  2837. mkiValue: parts[2] ? parts[2].split(':')[0] : undefined,
  2838. mkiLength: parts[2] ? parts[2].split(':')[1] : undefined
  2839. };
  2840. };
  2841. SDPUtils.writeCryptoKeyParams = function (keyParams) {
  2842. return keyParams.keyMethod + ':' + keyParams.keySalt + (keyParams.lifeTime ? '|' + keyParams.lifeTime : '') + (keyParams.mkiValue && keyParams.mkiLength ? '|' + keyParams.mkiValue + ':' + keyParams.mkiLength : '');
  2843. };
  2844. // Extracts all SDES parameters.
  2845. SDPUtils.getCryptoParameters = function (mediaSection, sessionpart) {
  2846. var lines = SDPUtils.matchPrefix(mediaSection + sessionpart, 'a=crypto:');
  2847. return lines.map(SDPUtils.parseCryptoLine);
  2848. };
  2849. // Parses ICE information from SDP media section or sessionpart.
  2850. // FIXME: for consistency with other functions this should only
  2851. // get the ice-ufrag and ice-pwd lines as input.
  2852. SDPUtils.getIceParameters = function (mediaSection, sessionpart) {
  2853. var ufrag = SDPUtils.matchPrefix(mediaSection + sessionpart, 'a=ice-ufrag:')[0];
  2854. var pwd = SDPUtils.matchPrefix(mediaSection + sessionpart, 'a=ice-pwd:')[0];
  2855. if (!(ufrag && pwd)) {
  2856. return null;
  2857. }
  2858. return {
  2859. usernameFragment: ufrag.substring(12),
  2860. password: pwd.substring(10)
  2861. };
  2862. };
  2863. // Serializes ICE parameters to SDP.
  2864. SDPUtils.writeIceParameters = function (params) {
  2865. var sdp = 'a=ice-ufrag:' + params.usernameFragment + '\r\n' + 'a=ice-pwd:' + params.password + '\r\n';
  2866. if (params.iceLite) {
  2867. sdp += 'a=ice-lite\r\n';
  2868. }
  2869. return sdp;
  2870. };
  2871. // Parses the SDP media section and returns RTCRtpParameters.
  2872. SDPUtils.parseRtpParameters = function (mediaSection) {
  2873. var description = {
  2874. codecs: [],
  2875. headerExtensions: [],
  2876. fecMechanisms: [],
  2877. rtcp: []
  2878. };
  2879. var lines = SDPUtils.splitLines(mediaSection);
  2880. var mline = lines[0].split(' ');
  2881. description.profile = mline[2];
  2882. for (var i = 3; i < mline.length; i++) {
  2883. // find all codecs from mline[3..]
  2884. var pt = mline[i];
  2885. var rtpmapline = SDPUtils.matchPrefix(mediaSection, 'a=rtpmap:' + pt + ' ')[0];
  2886. if (rtpmapline) {
  2887. var codec = SDPUtils.parseRtpMap(rtpmapline);
  2888. var fmtps = SDPUtils.matchPrefix(mediaSection, 'a=fmtp:' + pt + ' ');
  2889. // Only the first a=fmtp:<pt> is considered.
  2890. codec.parameters = fmtps.length ? SDPUtils.parseFmtp(fmtps[0]) : {};
  2891. codec.rtcpFeedback = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-fb:' + pt + ' ').map(SDPUtils.parseRtcpFb);
  2892. description.codecs.push(codec);
  2893. // parse FEC mechanisms from rtpmap lines.
  2894. switch (codec.name.toUpperCase()) {
  2895. case 'RED':
  2896. case 'ULPFEC':
  2897. description.fecMechanisms.push(codec.name.toUpperCase());
  2898. break;
  2899. default:
  2900. // only RED and ULPFEC are recognized as FEC mechanisms.
  2901. break;
  2902. }
  2903. }
  2904. }
  2905. SDPUtils.matchPrefix(mediaSection, 'a=extmap:').forEach(function (line) {
  2906. description.headerExtensions.push(SDPUtils.parseExtmap(line));
  2907. });
  2908. var wildcardRtcpFb = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-fb:* ').map(SDPUtils.parseRtcpFb);
  2909. description.codecs.forEach(function (codec) {
  2910. wildcardRtcpFb.forEach(function (fb) {
  2911. var duplicate = codec.rtcpFeedback.find(function (existingFeedback) {
  2912. return existingFeedback.type === fb.type && existingFeedback.parameter === fb.parameter;
  2913. });
  2914. if (!duplicate) {
  2915. codec.rtcpFeedback.push(fb);
  2916. }
  2917. });
  2918. });
  2919. // FIXME: parse rtcp.
  2920. return description;
  2921. };
  2922. // Generates parts of the SDP media section describing the capabilities /
  2923. // parameters.
  2924. SDPUtils.writeRtpDescription = function (kind, caps) {
  2925. var sdp = '';
  2926. // Build the mline.
  2927. sdp += 'm=' + kind + ' ';
  2928. sdp += caps.codecs.length > 0 ? '9' : '0'; // reject if no codecs.
  2929. sdp += ' ' + (caps.profile || 'UDP/TLS/RTP/SAVPF') + ' ';
  2930. sdp += caps.codecs.map(function (codec) {
  2931. if (codec.preferredPayloadType !== undefined) {
  2932. return codec.preferredPayloadType;
  2933. }
  2934. return codec.payloadType;
  2935. }).join(' ') + '\r\n';
  2936. sdp += 'c=IN IP4 0.0.0.0\r\n';
  2937. sdp += 'a=rtcp:9 IN IP4 0.0.0.0\r\n';
  2938. // Add a=rtpmap lines for each codec. Also fmtp and rtcp-fb.
  2939. caps.codecs.forEach(function (codec) {
  2940. sdp += SDPUtils.writeRtpMap(codec);
  2941. sdp += SDPUtils.writeFmtp(codec);
  2942. sdp += SDPUtils.writeRtcpFb(codec);
  2943. });
  2944. var maxptime = 0;
  2945. caps.codecs.forEach(function (codec) {
  2946. if (codec.maxptime > maxptime) {
  2947. maxptime = codec.maxptime;
  2948. }
  2949. });
  2950. if (maxptime > 0) {
  2951. sdp += 'a=maxptime:' + maxptime + '\r\n';
  2952. }
  2953. if (caps.headerExtensions) {
  2954. caps.headerExtensions.forEach(function (extension) {
  2955. sdp += SDPUtils.writeExtmap(extension);
  2956. });
  2957. }
  2958. // FIXME: write fecMechanisms.
  2959. return sdp;
  2960. };
  2961. // Parses the SDP media section and returns an array of
  2962. // RTCRtpEncodingParameters.
  2963. SDPUtils.parseRtpEncodingParameters = function (mediaSection) {
  2964. var encodingParameters = [];
  2965. var description = SDPUtils.parseRtpParameters(mediaSection);
  2966. var hasRed = description.fecMechanisms.indexOf('RED') !== -1;
  2967. var hasUlpfec = description.fecMechanisms.indexOf('ULPFEC') !== -1;
  2968. // filter a=ssrc:... cname:, ignore PlanB-msid
  2969. var ssrcs = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:').map(function (line) {
  2970. return SDPUtils.parseSsrcMedia(line);
  2971. }).filter(function (parts) {
  2972. return parts.attribute === 'cname';
  2973. });
  2974. var primarySsrc = ssrcs.length > 0 && ssrcs[0].ssrc;
  2975. var secondarySsrc = void 0;
  2976. var flows = SDPUtils.matchPrefix(mediaSection, 'a=ssrc-group:FID').map(function (line) {
  2977. var parts = line.substring(17).split(' ');
  2978. return parts.map(function (part) {
  2979. return parseInt(part, 10);
  2980. });
  2981. });
  2982. if (flows.length > 0 && flows[0].length > 1 && flows[0][0] === primarySsrc) {
  2983. secondarySsrc = flows[0][1];
  2984. }
  2985. description.codecs.forEach(function (codec) {
  2986. if (codec.name.toUpperCase() === 'RTX' && codec.parameters.apt) {
  2987. var encParam = {
  2988. ssrc: primarySsrc,
  2989. codecPayloadType: parseInt(codec.parameters.apt, 10)
  2990. };
  2991. if (primarySsrc && secondarySsrc) {
  2992. encParam.rtx = { ssrc: secondarySsrc };
  2993. }
  2994. encodingParameters.push(encParam);
  2995. if (hasRed) {
  2996. encParam = JSON.parse(JSON.stringify(encParam));
  2997. encParam.fec = {
  2998. ssrc: primarySsrc,
  2999. mechanism: hasUlpfec ? 'red+ulpfec' : 'red'
  3000. };
  3001. encodingParameters.push(encParam);
  3002. }
  3003. }
  3004. });
  3005. if (encodingParameters.length === 0 && primarySsrc) {
  3006. encodingParameters.push({
  3007. ssrc: primarySsrc
  3008. });
  3009. }
  3010. // we support both b=AS and b=TIAS but interpret AS as TIAS.
  3011. var bandwidth = SDPUtils.matchPrefix(mediaSection, 'b=');
  3012. if (bandwidth.length) {
  3013. if (bandwidth[0].indexOf('b=TIAS:') === 0) {
  3014. bandwidth = parseInt(bandwidth[0].substring(7), 10);
  3015. } else if (bandwidth[0].indexOf('b=AS:') === 0) {
  3016. // use formula from JSEP to convert b=AS to TIAS value.
  3017. bandwidth = parseInt(bandwidth[0].substring(5), 10) * 1000 * 0.95 - 50 * 40 * 8;
  3018. } else {
  3019. bandwidth = undefined;
  3020. }
  3021. encodingParameters.forEach(function (params) {
  3022. params.maxBitrate = bandwidth;
  3023. });
  3024. }
  3025. return encodingParameters;
  3026. };
  3027. // parses http://draft.ortc.org/#rtcrtcpparameters*
  3028. SDPUtils.parseRtcpParameters = function (mediaSection) {
  3029. var rtcpParameters = {};
  3030. // Gets the first SSRC. Note that with RTX there might be multiple
  3031. // SSRCs.
  3032. var remoteSsrc = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:').map(function (line) {
  3033. return SDPUtils.parseSsrcMedia(line);
  3034. }).filter(function (obj) {
  3035. return obj.attribute === 'cname';
  3036. })[0];
  3037. if (remoteSsrc) {
  3038. rtcpParameters.cname = remoteSsrc.value;
  3039. rtcpParameters.ssrc = remoteSsrc.ssrc;
  3040. }
  3041. // Edge uses the compound attribute instead of reducedSize
  3042. // compound is !reducedSize
  3043. var rsize = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-rsize');
  3044. rtcpParameters.reducedSize = rsize.length > 0;
  3045. rtcpParameters.compound = rsize.length === 0;
  3046. // parses the rtcp-mux attrіbute.
  3047. // Note that Edge does not support unmuxed RTCP.
  3048. var mux = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-mux');
  3049. rtcpParameters.mux = mux.length > 0;
  3050. return rtcpParameters;
  3051. };
  3052. SDPUtils.writeRtcpParameters = function (rtcpParameters) {
  3053. var sdp = '';
  3054. if (rtcpParameters.reducedSize) {
  3055. sdp += 'a=rtcp-rsize\r\n';
  3056. }
  3057. if (rtcpParameters.mux) {
  3058. sdp += 'a=rtcp-mux\r\n';
  3059. }
  3060. if (rtcpParameters.ssrc !== undefined && rtcpParameters.cname) {
  3061. sdp += 'a=ssrc:' + rtcpParameters.ssrc + ' cname:' + rtcpParameters.cname + '\r\n';
  3062. }
  3063. return sdp;
  3064. };
  3065. // parses either a=msid: or a=ssrc:... msid lines and returns
  3066. // the id of the MediaStream and MediaStreamTrack.
  3067. SDPUtils.parseMsid = function (mediaSection) {
  3068. var parts = void 0;
  3069. var spec = SDPUtils.matchPrefix(mediaSection, 'a=msid:');
  3070. if (spec.length === 1) {
  3071. parts = spec[0].substring(7).split(' ');
  3072. return { stream: parts[0], track: parts[1] };
  3073. }
  3074. var planB = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:').map(function (line) {
  3075. return SDPUtils.parseSsrcMedia(line);
  3076. }).filter(function (msidParts) {
  3077. return msidParts.attribute === 'msid';
  3078. });
  3079. if (planB.length > 0) {
  3080. parts = planB[0].value.split(' ');
  3081. return { stream: parts[0], track: parts[1] };
  3082. }
  3083. };
  3084. // SCTP
  3085. // parses draft-ietf-mmusic-sctp-sdp-26 first and falls back
  3086. // to draft-ietf-mmusic-sctp-sdp-05
  3087. SDPUtils.parseSctpDescription = function (mediaSection) {
  3088. var mline = SDPUtils.parseMLine(mediaSection);
  3089. var maxSizeLine = SDPUtils.matchPrefix(mediaSection, 'a=max-message-size:');
  3090. var maxMessageSize = void 0;
  3091. if (maxSizeLine.length > 0) {
  3092. maxMessageSize = parseInt(maxSizeLine[0].substring(19), 10);
  3093. }
  3094. if (isNaN(maxMessageSize)) {
  3095. maxMessageSize = 65536;
  3096. }
  3097. var sctpPort = SDPUtils.matchPrefix(mediaSection, 'a=sctp-port:');
  3098. if (sctpPort.length > 0) {
  3099. return {
  3100. port: parseInt(sctpPort[0].substring(12), 10),
  3101. protocol: mline.fmt,
  3102. maxMessageSize: maxMessageSize
  3103. };
  3104. }
  3105. var sctpMapLines = SDPUtils.matchPrefix(mediaSection, 'a=sctpmap:');
  3106. if (sctpMapLines.length > 0) {
  3107. var parts = sctpMapLines[0].substring(10).split(' ');
  3108. return {
  3109. port: parseInt(parts[0], 10),
  3110. protocol: parts[1],
  3111. maxMessageSize: maxMessageSize
  3112. };
  3113. }
  3114. };
  3115. // SCTP
  3116. // outputs the draft-ietf-mmusic-sctp-sdp-26 version that all browsers
  3117. // support by now receiving in this format, unless we originally parsed
  3118. // as the draft-ietf-mmusic-sctp-sdp-05 format (indicated by the m-line
  3119. // protocol of DTLS/SCTP -- without UDP/ or TCP/)
  3120. SDPUtils.writeSctpDescription = function (media, sctp) {
  3121. var output = [];
  3122. if (media.protocol !== 'DTLS/SCTP') {
  3123. output = ['m=' + media.kind + ' 9 ' + media.protocol + ' ' + sctp.protocol + '\r\n', 'c=IN IP4 0.0.0.0\r\n', 'a=sctp-port:' + sctp.port + '\r\n'];
  3124. } else {
  3125. output = ['m=' + media.kind + ' 9 ' + media.protocol + ' ' + sctp.port + '\r\n', 'c=IN IP4 0.0.0.0\r\n', 'a=sctpmap:' + sctp.port + ' ' + sctp.protocol + ' 65535\r\n'];
  3126. }
  3127. if (sctp.maxMessageSize !== undefined) {
  3128. output.push('a=max-message-size:' + sctp.maxMessageSize + '\r\n');
  3129. }
  3130. return output.join('');
  3131. };
  3132. // Generate a session ID for SDP.
  3133. // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-20#section-5.2.1
  3134. // recommends using a cryptographically random +ve 64-bit value
  3135. // but right now this should be acceptable and within the right range
  3136. SDPUtils.generateSessionId = function () {
  3137. return Math.random().toString().substr(2, 22);
  3138. };
  3139. // Write boiler plate for start of SDP
  3140. // sessId argument is optional - if not supplied it will
  3141. // be generated randomly
  3142. // sessVersion is optional and defaults to 2
  3143. // sessUser is optional and defaults to 'thisisadapterortc'
  3144. SDPUtils.writeSessionBoilerplate = function (sessId, sessVer, sessUser) {
  3145. var sessionId = void 0;
  3146. var version = sessVer !== undefined ? sessVer : 2;
  3147. if (sessId) {
  3148. sessionId = sessId;
  3149. } else {
  3150. sessionId = SDPUtils.generateSessionId();
  3151. }
  3152. var user = sessUser || 'thisisadapterortc';
  3153. // FIXME: sess-id should be an NTP timestamp.
  3154. return 'v=0\r\n' + 'o=' + user + ' ' + sessionId + ' ' + version + ' IN IP4 127.0.0.1\r\n' + 's=-\r\n' + 't=0 0\r\n';
  3155. };
  3156. // Gets the direction from the mediaSection or the sessionpart.
  3157. SDPUtils.getDirection = function (mediaSection, sessionpart) {
  3158. // Look for sendrecv, sendonly, recvonly, inactive, default to sendrecv.
  3159. var lines = SDPUtils.splitLines(mediaSection);
  3160. for (var i = 0; i < lines.length; i++) {
  3161. switch (lines[i]) {
  3162. case 'a=sendrecv':
  3163. case 'a=sendonly':
  3164. case 'a=recvonly':
  3165. case 'a=inactive':
  3166. return lines[i].substring(2);
  3167. default:
  3168. // FIXME: What should happen here?
  3169. }
  3170. }
  3171. if (sessionpart) {
  3172. return SDPUtils.getDirection(sessionpart);
  3173. }
  3174. return 'sendrecv';
  3175. };
  3176. SDPUtils.getKind = function (mediaSection) {
  3177. var lines = SDPUtils.splitLines(mediaSection);
  3178. var mline = lines[0].split(' ');
  3179. return mline[0].substring(2);
  3180. };
  3181. SDPUtils.isRejected = function (mediaSection) {
  3182. return mediaSection.split(' ', 2)[1] === '0';
  3183. };
  3184. SDPUtils.parseMLine = function (mediaSection) {
  3185. var lines = SDPUtils.splitLines(mediaSection);
  3186. var parts = lines[0].substring(2).split(' ');
  3187. return {
  3188. kind: parts[0],
  3189. port: parseInt(parts[1], 10),
  3190. protocol: parts[2],
  3191. fmt: parts.slice(3).join(' ')
  3192. };
  3193. };
  3194. SDPUtils.parseOLine = function (mediaSection) {
  3195. var line = SDPUtils.matchPrefix(mediaSection, 'o=')[0];
  3196. var parts = line.substring(2).split(' ');
  3197. return {
  3198. username: parts[0],
  3199. sessionId: parts[1],
  3200. sessionVersion: parseInt(parts[2], 10),
  3201. netType: parts[3],
  3202. addressType: parts[4],
  3203. address: parts[5]
  3204. };
  3205. };
  3206. // a very naive interpretation of a valid SDP.
  3207. SDPUtils.isValidSDP = function (blob) {
  3208. if (typeof blob !== 'string' || blob.length === 0) {
  3209. return false;
  3210. }
  3211. var lines = SDPUtils.splitLines(blob);
  3212. for (var i = 0; i < lines.length; i++) {
  3213. if (lines[i].length < 2 || lines[i].charAt(1) !== '=') {
  3214. return false;
  3215. }
  3216. // TODO: check the modifier a bit more.
  3217. }
  3218. return true;
  3219. };
  3220. // Expose public methods.
  3221. if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') {
  3222. module.exports = SDPUtils;
  3223. }
  3224. },{}]},{},[1])(1)
  3225. });