├── README.md ├── app.js ├── firebase-init.js ├── github.png ├── index.html └── vendor ├── firebase.js └── simplePeer.js /README.md: -------------------------------------------------------------------------------- 1 | # Tutorials 2 | 3 | ## Tutorials used: 4 | 5 | - WebRTC without setting up server: https://www.grafikart.fr/tutoriels/javascript/webrtc-864 6 | - WebRTC without any external libraries: https://websitebeaver.com/insanely-simple-webrtc-video-chat-using-firebase-with-codepen-demo 7 | - WebRTC with Firebase https://dev.to/rynobax_7/creating-a-multiplayer-game-with-webrtc 8 | 9 | ## Other tutorials found 10 | 11 | - WebRTC with Pusher and Node: https://pusher.com/tutorials/webrtc-video-call-app-nodejs 12 | 13 | ### Definition of STUN/SERVER 14 | 15 | > A STUN/TURN server is used for NAT traversal in VoIP. Whether you're at home behind a common router, at work behind an enterprise firewall, or traveling, chances are that you will be behind a NAT which must be traversed before making calls. [source: [Viagénie](http://numb.viagenie.ca)] 16 | 17 | > If a STUN server doesn’t work, then WebRTC will try the next server, which is why you should add several. But using more than two STUN/TURN servers slows down discovery. STUN servers are cheaper than TURN servers, which is why Google and Firefox allow anyone to access their STUN servers for free. TURN servers are harder to find for free, but they do exist. [sources: [websitebeaver](https://websitebeaver.com/insanely-simple-webrtc-video-chat-using-firebase-with-codepen-demo), [Bugzilla](https://bugzilla.mozilla.org/show_bug.cgi?id=1322659)] 18 | 19 | ### Servers used in this app 20 | 21 | [simple-peer](https://github.com/feross/simple-peer) provides by default two STUN server: 22 | 23 | ```js 24 | config: { 25 | iceServers: [ 26 | { urls: 'stun:stun.l.google.com:19302' }, 27 | { urls: 'stun:global.stun.twilio.com:3478?transport=udp' }, 28 | ] 29 | } 30 | ``` 31 | 32 | Mozilla provides another free STUN server : `{urls: 'stun:stun.services.mozilla.com'}` 33 | 34 | [Viagénie](http://numb.viagenie.ca) provides a free TURN server: 35 | 36 | ```js 37 | {urls: 'turn:numb.viagenie.ca','credential': '****','username': '****'} 38 | ``` 39 | 40 | So my final config is as follows: 41 | 42 | ```js 43 | config: { 44 | iceServers: [ 45 | { urls: 'stun:stun.l.google.com:19302' }, 46 | { urls: 'stun:global.stun.twilio.com:3478?transport=udp' }, 47 | { urls: 'stun:stun.services.mozilla.com' }, 48 | { urls: 'turn:numb.viagenie.ca', credential: '****', username: '****' }, 49 | ] 50 | } 51 | ``` 52 | 53 | Paid service provided by [Twilio](https://www.twilio.com/stun-turn): 54 | 55 | - [Pricing](https://www.twilio.com/stun-turn/pricing) 56 | - [FAQ](https://www.twilio.com/docs/stun-turn/faq) 57 | 58 | ### WebRTC in real world apps: 59 | 60 | - Google Allo 61 | - Goole Duo 62 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const showMyFaceButton = document.querySelector('#start') 2 | const showFriendsFaceButton = document.querySelector('#receiver') 3 | const showMyFaceVideo = document.querySelector('#emitter-video') 4 | const showFriendsFaceVideo = document.querySelector('#receiver-video') 5 | 6 | const offerTextarea = document.querySelector('#offer') 7 | 8 | const yourId = Math.floor(Math.random() * 1000000000) 9 | 10 | let p = null 11 | 12 | import { database } from './firebase-init.js' 13 | 14 | function readMessage(data) { 15 | const msg = JSON.parse(data.val().message) 16 | const sender = data.val().sender 17 | 18 | if (sender != yourId) { 19 | console.log(msg) 20 | if (p === null) { 21 | p = new SimplePeer({ 22 | initiator: false, 23 | config: { 24 | iceServers: [ 25 | { urls: 'stun:stun.l.google.com:19302' }, 26 | { urls: 'stun:global.stun.twilio.com:3478?transport=udp' }, 27 | { urls: 'stun:stun.services.mozilla.com' }, 28 | { 29 | urls: 'turn:numb.viagenie.ca', 30 | credential: '****', 31 | username: '****', 32 | }, 33 | ], 34 | }, 35 | }) 36 | bindEvents(p) 37 | } 38 | p.signal(msg) 39 | } 40 | } 41 | 42 | function bindEvents(p) { 43 | p.on('error', err => { 44 | console.log(err) 45 | }) 46 | 47 | p.on('signal', data => { 48 | const msg = database.push({ 49 | sender: yourId, 50 | message: JSON.stringify(data), 51 | }) 52 | 53 | msg.remove() 54 | }) 55 | 56 | p.on('stream', stream => { 57 | console.log('streaming') 58 | console.log(stream) 59 | showFriendsFaceVideo.srcObject = stream 60 | }) 61 | } 62 | 63 | database.on('child_added', readMessage) 64 | 65 | showMyFaceButton.addEventListener('click', async e => { 66 | try { 67 | const stream = await navigator.mediaDevices.getUserMedia({ 68 | video: true, 69 | audio: true, 70 | }) 71 | 72 | p = new SimplePeer({ 73 | initiator: true, 74 | stream, 75 | config: { 76 | iceServers: [ 77 | { urls: 'stun:stun.l.google.com:19302' }, 78 | { urls: 'stun:global.stun.twilio.com:3478?transport=udp' }, 79 | { urls: 'stun:stun.services.mozilla.com' }, 80 | { 81 | urls: 'turn:numb.viagenie.ca', 82 | credential: 'hiragana', 83 | username: 'mornirmornir@hotmail.com', 84 | }, 85 | ], 86 | }, 87 | }) 88 | 89 | bindEvents(p) 90 | showMyFaceVideo.srcObject = stream 91 | } catch (e) { 92 | console.log(e.message) 93 | } 94 | }) 95 | -------------------------------------------------------------------------------- /firebase-init.js: -------------------------------------------------------------------------------- 1 | const config = { 2 | apiKey: 'AIzaSyDMZZs3Kiic0XEFAxKoZYnR6bbRZwCmGPE', 3 | authDomain: 'web-rtc-3f476.firebaseapp.com', 4 | databaseURL: 'https://web-rtc-3f476.firebaseio.com', 5 | projectId: 'web-rtc-3f476', 6 | storageBucket: 'web-rtc-3f476.appspot.com', 7 | messagingSenderId: '705697983314', 8 | } 9 | firebase.initializeApp(config) 10 | 11 | const database = firebase.database().ref() 12 | 13 | export { database } 14 | -------------------------------------------------------------------------------- /github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mornir/webrtc-firebase/595107ed7af1cb18e5efd8a375bdd07d90910dcf/github.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | WebRTC 9 | 10 | 11 | 12 |
13 | 19 | 20 |
21 |
22 | 23 |
24 |

Envoi

25 | 26 |

27 | 28 |

29 |
30 | 31 |
32 |

Réception

33 | 34 |
35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /vendor/simplePeer.js: -------------------------------------------------------------------------------- 1 | (function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?this:self:global:window,t.SimplePeer=e()}})(function(){var t=Math.floor,n=Math.abs,r=Math.pow;return function(){function d(s,e,n){function t(o,i){if(!e[o]){if(!s[o]){var l="function"==typeof require&&require;if(!i&&l)return l(o,!0);if(r)return r(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var a=e[o]={exports:{}};s[o][0].call(a.exports,function(e){var r=s[o][1][e];return t(r||e)},a,a.exports,d,s,e,n)}return e[o].exports}for(var r="function"==typeof require&&require,o=0;o>16,s[l++]=255&t>>8,s[l++]=255&t;return 2===d&&(t=p[e.charCodeAt(f)]<<2|p[e.charCodeAt(f+1)]>>4,s[l++]=255&t),1===d&&(t=p[e.charCodeAt(f)]<<10|p[e.charCodeAt(f+1)]<<4|p[e.charCodeAt(f+2)]>>2,s[l++]=255&t>>8,s[l++]=255&t),s}function d(e){return c[63&e>>18]+c[63&e>>12]+c[63&e>>6]+c[63&e]}function s(e,t,n){for(var r,o=[],a=t;al?l:d+a));return 1===r?(t=e[n-1],o.push(c[t>>2]+c[63&t<<4]+"==")):2===r&&(t=(e[n-2]<<8)+e[n-1],o.push(c[t>>10]+c[63&t>>4]+c[63&t<<2]+"=")),o.join("")}n.byteLength=function(e){var t=r(e),n=t[0],o=t[1];return 3*(n+o)/4-o},n.toByteArray=a,n.fromByteArray=l;for(var c=[],p=[],u="undefined"==typeof Uint8Array?Array:Uint8Array,f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",g=0,h=f.length;ge)throw new RangeError("\"size\" argument must not be negative")}function s(e,t,n){return i(e),0>=e?o(e):void 0===t?o(e):"string"==typeof n?o(e).fill(t,n):o(e).fill(t)}function l(e){return i(e),o(0>e?0:0|g(e))}function c(e,t){if(("string"!=typeof t||""===t)&&(t="utf8"),!d.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var n=0|h(e,t),r=o(n),a=r.write(e,t);return a!==n&&(r=r.slice(0,a)),r}function p(e){for(var t=0>e.length?0:0|g(e.length),n=o(t),r=0;rt||e.byteLength=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+2147483647 .toString(16)+" bytes");return 0|e}function h(e,t){if(d.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||V(e))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return U(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return H(e).length;default:if(r)return U(e).length;t=(""+t).toLowerCase(),r=!0;}}function m(e,t,n){var r=!1;if((void 0===t||0>t)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),0>=n)return"";if(n>>>=0,t>>>=0,n<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return I(this,t,n);case"utf8":case"utf-8":return T(this,t,n);case"ascii":return A(this,t,n);case"latin1":case"binary":return L(this,t,n);case"base64":return k(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0;}}function _(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function b(e,t,n,r,o){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):2147483647n&&(n=-2147483648),n=+n,G(n)&&(n=o?0:e.length-1),0>n&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(0>n)if(o)n=0;else return-1;if("string"==typeof t&&(t=d.from(t,r)),d.isBuffer(t))return 0===t.length?-1:y(e,t,n,r,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):y(e,[t],n,r,o);throw new TypeError("val must be string, number or Buffer")}function y(e,t,n,r,o){function a(e,t){return 1===d?e[t]:e.readUInt16BE(t*d)}var d=1,s=e.length,l=t.length;if(void 0!==r&&(r=(r+"").toLowerCase(),"ucs2"===r||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(2>e.length||2>t.length)return-1;d=2,s/=2,l/=2,n/=2}var c;if(o){var p=-1;for(c=n;cs&&(n=s-l),c=n;0<=c;c--){for(var u=!0,f=0;fo&&(r=o)):r=o;var a=t.length;r>a/2&&(r=a/2);for(var d,s=0;sa&&(d=a):2===s?(l=e[o+1],128==(192&l)&&(u=(31&a)<<6|63&l,127u||57343u&&(d=u))):void 0}null===d?(d=65533,s=1):65535>>10),d=56320|1023&d),r.push(d),o+=s}return E(r)}function E(e){var t=e.length;if(t<=4096)return Y.apply(String,e);for(var n="",r=0;rt)&&(t=0),(!n||0>n||n>r)&&(n=r);for(var o="",a=t;ae)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function N(e,t,n,r,o,a){if(!d.isBuffer(e))throw new TypeError("\"buffer\" argument must be a Buffer instance");if(t>o||te.length)throw new RangeError("Index out of range")}function M(e,t,n,r){if(n+r>e.length)throw new RangeError("Index out of range");if(0>n)throw new RangeError("Index out of range")}function D(e,t,n,r,o){return t=+t,n>>>=0,o||M(e,t,n,4,34028234663852886e22,-34028234663852886e22),$.write(e,t,n,r,23,4),n+4}function P(e,t,n,r,o){return t=+t,n>>>=0,o||M(e,t,n,8,17976931348623157e292,-17976931348623157e292),$.write(e,t,n,r,52,8),n+8}function j(e){if(e=e.split("=")[0],e=e.trim().replace(K,""),2>e.length)return"";for(;0!=e.length%4;)e+="=";return e}function O(e){return 16>e?"0"+e.toString(16):e.toString(16)}function U(e,t){t=t||1/0;for(var n,r=e.length,o=null,a=[],d=0;dn){if(!o){if(56319n){-1<(t-=3)&&a.push(239,191,189),o=n;continue}n=(o-55296<<10|n-56320)+65536}else o&&-1<(t-=3)&&a.push(239,191,189);if(o=null,128>n){if(0>(t-=1))break;a.push(n)}else if(2048>n){if(0>(t-=2))break;a.push(192|n>>6,128|63&n)}else if(65536>n){if(0>(t-=3))break;a.push(224|n>>12,128|63&n>>6,128|63&n)}else if(1114112>n){if(0>(t-=4))break;a.push(240|n>>18,128|63&n>>12,128|63&n>>6,128|63&n)}else throw new Error("Invalid code point")}return a}function W(e){for(var t=[],n=0;n(t-=2));++d)n=e.charCodeAt(d),r=n>>8,o=n%256,a.push(o),a.push(r);return a}function H(e){return J.toByteArray(j(e))}function z(e,t,n,r){for(var o=0;o=t.length||o>=e.length);++o)t[o+n]=e[o];return o}function V(e){return e instanceof ArrayBuffer||null!=e&&null!=e.constructor&&"ArrayBuffer"===e.constructor.name&&"number"==typeof e.byteLength}function G(e){return e!==e}var Y=String.fromCharCode,X=Math.min,J=e("base64-js"),$=e("ieee754");n.Buffer=d,n.SlowBuffer=function(e){return+e!=e&&(e=0),d.alloc(+e)},n.INSPECT_MAX_BYTES=50;n.kMaxLength=2147483647,d.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(t){return!1}}(),d.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(d.prototype,"parent",{get:function(){return this instanceof d?this.buffer:void 0}}),Object.defineProperty(d.prototype,"offset",{get:function(){return this instanceof d?this.byteOffset:void 0}}),"undefined"!=typeof Symbol&&Symbol.species&&d[Symbol.species]===d&&Object.defineProperty(d,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),d.poolSize=8192,d.from=function(e,t,n){return a(e,t,n)},d.prototype.__proto__=Uint8Array.prototype,d.__proto__=Uint8Array,d.alloc=function(e,t,n){return s(e,t,n)},d.allocUnsafe=function(e){return l(e)},d.allocUnsafeSlow=function(e){return l(e)},d.isBuffer=function(e){return null!=e&&!0===e._isBuffer},d.compare=function(e,t){if(!d.isBuffer(e)||!d.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,o=0,a=X(n,r);ot&&(e+=" ... ")),""},d.prototype.compare=function(e,t,n,r,o){if(!d.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),0>t||n>e.length||0>r||o>this.length)throw new RangeError("out of range index");if(r>=o&&t>=n)return 0;if(r>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,o>>>=0,this===e)return 0;for(var a=o-r,s=n-t,l=X(a,s),c=this.slice(r,o),p=e.slice(t,n),u=0;u>>=0,isFinite(n)?(n>>>=0,void 0===r&&(r="utf8")):(r=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var o=this.length-t;if((void 0===n||n>o)&&(n=o),0n||0>t)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var a=!1;;)switch(r){case"hex":return C(this,e,t,n);case"utf8":case"utf-8":return w(this,e,t,n);case"ascii":return S(this,e,t,n);case"latin1":case"binary":return v(this,e,t,n);case"base64":return x(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,t,n);default:if(a)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),a=!0;}},d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};d.prototype.slice=function(e,t){var n=this.length;e=~~e,t=void 0===t?n:~~t,0>e?(e+=n,0>e&&(e=0)):e>n&&(e=n),0>t?(t+=n,0>t&&(t=0)):t>n&&(t=n),t>>=0,t>>>=0,n||F(e,t,this.length);for(var r=this[e],o=1,a=0;++a>>=0,t>>>=0,n||F(e,t,this.length);for(var r=this[e+--t],o=1;0>>=0,t||F(e,1,this.length),this[e]},d.prototype.readUInt16LE=function(e,t){return e>>>=0,t||F(e,2,this.length),this[e]|this[e+1]<<8},d.prototype.readUInt16BE=function(e,t){return e>>>=0,t||F(e,2,this.length),this[e]<<8|this[e+1]},d.prototype.readUInt32LE=function(e,t){return e>>>=0,t||F(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},d.prototype.readUInt32BE=function(e,t){return e>>>=0,t||F(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},d.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||F(e,t,this.length);for(var o=this[e],a=1,d=0;++d=a&&(o-=r(2,8*t)),o},d.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||F(e,t,this.length);for(var o=t,a=1,d=this[e+--o];0=a&&(d-=r(2,8*t)),d},d.prototype.readInt8=function(e,t){return e>>>=0,t||F(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},d.prototype.readInt16LE=function(e,t){e>>>=0,t||F(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},d.prototype.readInt16BE=function(e,t){e>>>=0,t||F(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},d.prototype.readInt32LE=function(e,t){return e>>>=0,t||F(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},d.prototype.readInt32BE=function(e,t){return e>>>=0,t||F(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},d.prototype.readFloatLE=function(e,t){return e>>>=0,t||F(e,4,this.length),$.read(this,e,!0,23,4)},d.prototype.readFloatBE=function(e,t){return e>>>=0,t||F(e,4,this.length),$.read(this,e,!1,23,4)},d.prototype.readDoubleLE=function(e,t){return e>>>=0,t||F(e,8,this.length),$.read(this,e,!0,52,8)},d.prototype.readDoubleBE=function(e,t){return e>>>=0,t||F(e,8,this.length),$.read(this,e,!1,52,8)},d.prototype.writeUIntLE=function(e,t,n,o){if(e=+e,t>>>=0,n>>>=0,!o){var a=r(2,8*n)-1;N(this,e,t,n,a,0)}var d=1,s=0;for(this[t]=255&e;++s>>=0,n>>>=0,!o){var a=r(2,8*n)-1;N(this,e,t,n,a,0)}var d=n-1,s=1;for(this[t+d]=255&e;0<=--d&&(s*=256);)this[t+d]=255&e/s;return t+n},d.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,1,255,0),this[t]=255&e,t+1},d.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},d.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},d.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},d.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},d.prototype.writeIntLE=function(e,t,n,o){if(e=+e,t>>>=0,!o){var a=r(2,8*n-1);N(this,e,t,n,a-1,-a)}var d=0,s=1,l=0;for(this[t]=255&e;++de&&0===l&&0!==this[t+d-1]&&(l=1),this[t+d]=255&(e/s>>0)-l;return t+n},d.prototype.writeIntBE=function(e,t,n,o){if(e=+e,t>>>=0,!o){var a=r(2,8*n-1);N(this,e,t,n,a-1,-a)}var d=n-1,s=1,l=0;for(this[t+d]=255&e;0<=--d&&(s*=256);)0>e&&0===l&&0!==this[t+d+1]&&(l=1),this[t+d]=255&(e/s>>0)-l;return t+n},d.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,1,127,-128),0>e&&(e=255+e+1),this[t]=255&e,t+1},d.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},d.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},d.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},d.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||N(this,e,t,4,2147483647,-2147483648),0>e&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},d.prototype.writeFloatLE=function(e,t,n){return D(this,e,t,!0,n)},d.prototype.writeFloatBE=function(e,t,n){return D(this,e,t,!1,n)},d.prototype.writeDoubleLE=function(e,t,n){return P(this,e,t,!0,n)},d.prototype.writeDoubleBE=function(e,t,n){return P(this,e,t,!1,n)},d.prototype.copy=function(e,t,n,r){if(!d.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),0t)throw new RangeError("targetStart out of bounds");if(0>n||n>=this.length)throw new RangeError("Index out of range");if(0>r)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-to||"latin1"===r)&&(e=o)}}else"number"==typeof e&&(e&=255);if(0>t||this.length>>=0,n=n===void 0?this.length:n>>>0,e||(e=0);var a;if("number"==typeof e)for(a=t;aa)){d.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+d.length+" \""+(t+"\" listeners added. Use emitter.setMaxListeners() to increase limit."));s.name="MaxListenersExceededWarning",s.emitter=e,s.type=t,s.count=d.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",s.name,s.message)}return e}function p(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var e=Array(arguments.length),t=0;te||e!==e)throw new TypeError("\"defaultMaxListeners\" must be a positive number");w=e}}):n.defaultMaxListeners=w,n.prototype.setMaxListeners=function(e){if("number"!=typeof e||0>e||isNaN(e))throw new TypeError("\"n\" argument must be a positive number");return this._maxListeners=e,this},n.prototype.getMaxListeners=function(){return r(this)},n.prototype.emit=function(e){var t,n,r,o,p,u,f="error"===e;if(u=this._events,u)f=f&&null==u.error;else if(!f)return!1;if(f){if(1o)return this;0===o?n.shift():g(n,o),1===n.length&&(r[e]=n[0]),r.removeListener&&this.emit("removeListener",e,d||t)}return this},n.prototype.removeAllListeners=function(e){var t,n,r;if(n=this._events,!n)return this;if(!n.removeListener)return 0===arguments.length?(this._events=_(null),this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=_(null):delete n[e]),this;if(0===arguments.length){var o,a=b(n);for(r=0;r>1,h=-7,_=o?l-1:0,b=o?-1:1,d=t[n+_];for(_+=b,c=d&(1<<-h)-1,d>>=-h,h+=u;0>=-h,h+=a;0>1,w=23===u?5.960464477539063e-8-6.617444900424222e-24:0,S=p?0:f-1,v=p?1:-1,d=0>a||0===a&&0>1/a?1:0;for(a=n(a),isNaN(a)||a===1/0?(h=isNaN(a)?1:0,g=y):(g=t(Math.log(a)/Math.LN2),1>a*(_=r(2,-g))&&(g--,_*=2),a+=1<=g+C?w/_:w*r(2,1-C),2<=a*_&&(g++,_/=2),g+C>=y?(h=0,g=y):1<=g+C?(h=(a*_-1)*r(2,u),g+=C):(h=a*r(2,C-1)*r(2,u),g=0));8<=u;o[l+S]=255&h,S+=v,h/=256,u-=8);for(g=g<>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function h(e,t){return 0>=e||0===t.length&&t.ended?0:t.objectMode?1:e===e?(e>t.highWaterMark&&(t.highWaterMark=g(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0)):t.flowing&&t.length?t.buffer.head.data.length:t.length}function m(e,t){if(!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,_(e)}}function _(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(H("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?F.nextTick(b,e):b(e))}function b(e){H("emit readable"),e.emit("readable"),R(e)}function y(e,t){t.readingMore||(t.readingMore=!0,F.nextTick(C,e,t))}function C(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):n=T(e,t.buffer,t.decoder),n}function T(e,t,n){var r;return ei.length?i.length:e;if(a+=d===i.length?i:i.slice(0,e),e-=d,0===e){d===i.length?(++o,t.head=r.next?r.next:t.tail=null):(t.head=r,r.data=i.slice(d));break}++o}return t.length-=o,a}function A(e,t){var r=O.allocUnsafe(e),o=t.head,a=1;for(o.data.copy(r),e-=o.data.length;o=o.next;){var i=o.data,d=e>i.length?i.length:e;if(i.copy(r,r.length-e,0,d),e-=d,0===e){d===i.length?(++a,t.head=o.next?o.next:t.tail=null):(t.head=o,o.data=i.slice(d));break}++a}return t.length-=a,r}function L(e){var t=e._readableState;if(0=t.highWaterMark||t.ended))return H("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?L(this):_(this),null;if(e=h(e,t),0===e&&t.ended)return 0===t.length&&L(this),null;var o=t.needReadable;H("need readable",o),(0===t.length||t.length-e>>0),n=this.head,a=0;n;)r(n.data,t,a),a+=n.data.length,n=n.next;return t},e}(),a&&a.inspect&&a.inspect.custom&&(t.exports.prototype[a.inspect.custom]=function(){var e=a.inspect({length:this.length});return this.constructor.name+" "+e})},{"safe-buffer":26,util:2}],23:[function(e,t){"use strict";function n(e,t){e.emit("error",t)}var r=e("process-nextick-args");t.exports={destroy:function(e,t){var o=this,a=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return a||i?(t?t(e):e&&(!this._writableState||!this._writableState.errorEmitted)&&r.nextTick(n,this,e),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(e){!t&&e?(r.nextTick(n,o,e),o._writableState&&(o._writableState.errorEmitted=!0)):t&&t(e)}),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}}},{"process-nextick-args":14}],24:[function(e,t){t.exports=e("events").EventEmitter},{events:4}],25:[function(e,t,n){n=t.exports=e("./lib/_stream_readable.js"),n.Stream=n,n.Readable=n,n.Writable=e("./lib/_stream_writable.js"),n.Duplex=e("./lib/_stream_duplex.js"),n.Transform=e("./lib/_stream_transform.js"),n.PassThrough=e("./lib/_stream_passthrough.js")},{"./lib/_stream_duplex.js":17,"./lib/_stream_passthrough.js":18,"./lib/_stream_readable.js":19,"./lib/_stream_transform.js":20,"./lib/_stream_writable.js":21}],26:[function(e,t,n){function r(e,t){for(var n in e)t[n]=e[n]}function o(e,t,n){return i(e,t,n)}var a=e("buffer"),i=a.Buffer;i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?t.exports=a:(r(a,n),n.Buffer=o),r(i,o),o.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return i(e,t,n)},o.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var r=i(e);return void 0===t?r.fill(0):"string"==typeof n?r.fill(t,n):r.fill(t),r},o.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i(e)},o.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return a.SlowBuffer(e)}},{buffer:3}],27:[function(e,t,n){"use strict";function r(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0;}}function o(e){var t=r(e);if("string"!=typeof t&&(m.isEncoding===_||!_(e)))throw new Error("Unknown encoding: "+e);return t||e}function a(e){this.encoding=o(e);var t;switch(this.encoding){case"utf16le":this.text=c,this.end=p,t=4;break;case"utf8":this.fillLast=l,t=4;break;case"base64":this.text=u,this.end=f,t=3;break;default:return this.write=g,void(this.end=h);}this.lastNeed=0,this.lastTotal=0,this.lastChar=m.allocUnsafe(t)}function d(e){if(127>=e)return 0;return 6==e>>5?2:14==e>>4?3:30==e>>3?4:2==e>>6?-1:-2}function s(e,t,n){var r=t.length-1;if(r=r)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function p(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function u(e,t){var r=(e.length-t)%3;return 0==r?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,1==r?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function f(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function g(e){return e.toString(this.encoding)}function h(e){return e&&e.length?this.write(e):""}var m=e("safe-buffer").Buffer,_=m.isEncoding||function(e){switch(e=""+e,e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1;}};n.StringDecoder=a,a.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(t=this.fillLast(e),void 0===t)return"";n=this.lastNeed,this.lastNeed=0}else n=0;return narguments.length)&&d.call(arguments,1);return s[t]=!0,a(function(){s[t]&&(r?e.apply(null,r):e.call(null),n.clearImmediate(t))}),t},n.clearImmediate="function"==typeof r?r:function(e){delete s[e]}}).call(this,e("timers").setImmediate,e("timers").clearImmediate)},{"process/browser.js":15,timers:28}],29:[function(e,t){(function(e){function n(t){try{if(!e.localStorage)return!1}catch(e){return!1}var n=e.localStorage[t];return null!=n&&"true"===(n+"").toLowerCase()}t.exports=function(e,t){function r(){if(!o){if(n("throwDeprecation"))throw new Error(t);else n("traceDeprecation")?console.trace(t):console.warn(t);o=!0}return e.apply(this,arguments)}if(n("noDeprecation"))return e;var o=!1;return r}}).call(this,"undefined"==typeof global?"undefined"==typeof self?"undefined"==typeof window?{}:window:self:global)},{}],"/":[function(e,t){(function(n){function r(e){var t=this;if(!(t instanceof r))return new r(e);if(t._id=l(4).toString("hex").slice(0,7),t._debug("new peer %o",e),e=Object.assign({allowHalfOpen:!1},e),c.Duplex.call(t,e),t.channelName=e.initiator?e.channelName||l(20).toString("hex"):null,t._isChromium="undefined"!=typeof window&&!!window.webkitRTCPeerConnection,t.initiator=e.initiator||!1,t.channelConfig=e.channelConfig||r.channelConfig,t.config=e.config||r.config,t.constraints=t._transformConstraints(e.constraints||r.constraints),t.offerConstraints=t._transformConstraints(e.offerConstraints||{}),t.answerConstraints=t._transformConstraints(e.answerConstraints||{}),t.sdpTransform=e.sdpTransform||function(e){return e},t.streams=e.streams||(e.stream?[e.stream]:[]),t.trickle=void 0===e.trickle||e.trickle,t.destroyed=!1,t.connected=!1,t.remoteAddress=void 0,t.remoteFamily=void 0,t.remotePort=void 0,t.localAddress=void 0,t.localPort=void 0,t._wrtc=e.wrtc&&"object"==typeof e.wrtc?e.wrtc:d(),!t._wrtc)if("undefined"==typeof window)throw o("No WebRTC support: Specify `opts.wrtc` option in this environment","ERR_WEBRTC_SUPPORT");else throw o("No WebRTC support: Not a supported browser","ERR_WEBRTC_SUPPORT");t._pcReady=!1,t._channelReady=!1,t._iceComplete=!1,t._channel=null,t._pendingCandidates=[],t._isNegotiating=!1,t._batchedNegotiation=!1,t._queuedNegotiation=!1,t._sendersAwaitingStable=[],t._senderMap=new WeakMap,t._remoteTracks=[],t._remoteStreams=[],t._chunk=null,t._cb=null,t._interval=null,t._pc=new t._wrtc.RTCPeerConnection(t.config,t.constraints),t._isReactNativeWebrtc="number"==typeof t._pc._peerConnectionId,t._pc.oniceconnectionstatechange=function(){t._onIceStateChange()},t._pc.onicegatheringstatechange=function(){t._onIceStateChange()},t._pc.onsignalingstatechange=function(){t._onSignalingStateChange()},t._pc.onicecandidate=function(e){t._onIceCandidate(e)},t.initiator?t._setupData({channel:t._pc.createDataChannel(t.channelName,t.channelConfig)}):t._pc.ondatachannel=function(e){t._setupData(e)},"addTrack"in t._pc&&(t.streams&&t.streams.forEach(function(e){t.addStream(e)}),t._pc.ontrack=function(e){t._onTrack(e)}),t.initiator&&t._needsNegotiation(),t._onFinishBound=function(){t._onFinish()},t.once("finish",t._onFinishBound)}function o(e,t){var n=new Error(e);return n.code=t,n}function a(){}t.exports=r;var i=e("debug")("simple-peer"),d=e("get-browser-rtc"),s=e("inherits"),l=e("randombytes"),c=e("readable-stream"),p=65536;s(r,c.Duplex),r.WEBRTC_SUPPORT=!!d(),r.config={iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:global.stun.twilio.com:3478?transport=udp"}]},r.constraints={},r.channelConfig={},Object.defineProperty(r.prototype,"bufferSize",{get:function(){var e=this;return e._channel&&e._channel.bufferedAmount||0}}),r.prototype.address=function(){var e=this;return{port:e.localPort,family:"IPv4",address:e.localAddress}},r.prototype.signal=function(e){var t=this;if(t.destroyed)throw o("cannot signal after peer is destroyed","ERR_SIGNALING");if("string"==typeof e)try{e=JSON.parse(e)}catch(t){e={}}t._debug("signal()"),e.renegotiate&&(t._debug("got request to renegotiate"),t._needsNegotiation()),e.candidate&&(t._pc.remoteDescription&&t._pc.remoteDescription.type?t._addIceCandidate(e.candidate):t._pendingCandidates.push(e.candidate)),e.sdp&&t._pc.setRemoteDescription(new t._wrtc.RTCSessionDescription(e),function(){t.destroyed||(t._pendingCandidates.forEach(function(e){t._addIceCandidate(e)}),t._pendingCandidates=[],"offer"===t._pc.remoteDescription.type&&t._createAnswer())},function(e){t.destroy(o(e,"ERR_SET_REMOTE_DESCRIPTION"))}),e.sdp||e.candidate||e.renegotiate||t.destroy(o("signal() called with invalid signal data","ERR_SIGNALING"))},r.prototype._addIceCandidate=function(e){var t=this;try{t._pc.addIceCandidate(new t._wrtc.RTCIceCandidate(e),a,function(e){t.destroy(o(e,"ERR_ADD_ICE_CANDIDATE"))})}catch(e){t.destroy(o("error adding candidate: "+e.message,"ERR_ADD_ICE_CANDIDATE"))}},r.prototype.send=function(e){var t=this;t._channel.send(e)},r.prototype.addStream=function(e){var t=this;t._debug("addStream()"),e.getTracks().forEach(function(n){t.addTrack(n,e)})},r.prototype.addTrack=function(e,t){var n=this;n._debug("addTrack()");var r=n._pc.addTrack(e,t),o=n._senderMap.get(e)||new WeakMap;o.set(t,r),n._senderMap.set(e,o),n._needsNegotiation()},r.prototype.removeTrack=function(e,t){var n=this;n._debug("removeSender()");var r=n._senderMap.get(e),o=r?r.get(t):null;o||n.destroy(new Error("Cannot remove track that was never added."));try{n._pc.removeTrack(o)}catch(e){"NS_ERROR_UNEXPECTED"===e.name?n._sendersAwaitingStable.push(o):n.destroy(e)}},r.prototype.removeStream=function(e){var t=this;t._debug("removeSenders()"),e.getTracks().forEach(function(n){t.removeTrack(n,e)})},r.prototype._needsNegotiation=function(){var e=this;e._debug("_needsNegotiation"),e._batchedNegotiation||(e._batchedNegotiation=!0,setTimeout(function(){e._batchedNegotiation=!1,e._debug("starting batched negotiation"),e.negotiate()},0))},r.prototype.negotiate=function(){var e=this;e.initiator?e._isNegotiating?(e._queuedNegotiation=!0,e._debug("already negotiating, queueing")):(e._debug("start negotiation"),e._createOffer()):(e._debug("requesting negotiation from initiator"),e.emit("signal",{renegotiate:!0})),e._isNegotiating=!0},r.prototype.destroy=function(e){var t=this;t._destroy(e,function(){})},r.prototype._destroy=function(e,t){var n=this;if(!n.destroyed){if(n._debug("destroy (error: %s)",e&&(e.message||e)),n.readable=n.writable=!1,n._readableState.ended||n.push(null),n._writableState.finished||n.end(),n.destroyed=!0,n.connected=!1,n._pcReady=!1,n._channelReady=!1,n._remoteTracks=null,n._remoteStreams=null,n._senderMap=null,clearInterval(n._interval),n._interval=null,n._chunk=null,n._cb=null,n._onFinishBound&&n.removeListener("finish",n._onFinishBound),n._onFinishBound=null,n._channel){try{n._channel.close()}catch(e){}n._channel.onmessage=null,n._channel.onopen=null,n._channel.onclose=null,n._channel.onerror=null}if(n._pc){try{n._pc.close()}catch(e){}n._pc.oniceconnectionstatechange=null,n._pc.onicegatheringstatechange=null,n._pc.onsignalingstatechange=null,n._pc.onicecandidate=null,"addTrack"in n._pc&&(n._pc.ontrack=null),n._pc.ondatachannel=null}n._pc=null,n._channel=null,e&&n.emit("error",e),n.emit("close"),t()}},r.prototype._setupData=function(e){var t=this;return e.channel?void(t._channel=e.channel,t._channel.binaryType="arraybuffer","number"==typeof t._channel.bufferedAmountLowThreshold&&(t._channel.bufferedAmountLowThreshold=p),t.channelName=t._channel.label,t._channel.onmessage=function(e){t._onChannelMessage(e)},t._channel.onbufferedamountlow=function(){t._onChannelBufferedAmountLow()},t._channel.onopen=function(){t._onChannelOpen()},t._channel.onclose=function(){t._onChannelClose()},t._channel.onerror=function(e){t.destroy(o(e,"ERR_DATA_CHANNEL"))}):t.destroy(o("Data channel event is missing `channel` property","ERR_DATA_CHANNEL"))},r.prototype._read=function(){},r.prototype._write=function(e,t,n){var r=this;if(r.destroyed)return n(o("cannot write after peer is destroyed","ERR_DATA_CHANNEL"));if(r.connected){try{r.send(e)}catch(e){return r.destroy(o(e,"ERR_DATA_CHANNEL"))}r._channel.bufferedAmount>p?(r._debug("start backpressure: bufferedAmount %d",r._channel.bufferedAmount),r._cb=n):n(null)}else r._debug("write before connect"),r._chunk=e,r._cb=n},r.prototype._onFinish=function(){function e(){setTimeout(function(){t.destroy()},1e3)}var t=this;t.destroyed||(t.connected?e():t.once("connect",e))},r.prototype._createOffer=function(){var e=this;e.destroyed||e._pc.createOffer(function(t){function n(){var n=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:n.type,sdp:n.sdp})}e.destroyed||(t.sdp=e.sdpTransform(t.sdp),e._pc.setLocalDescription(t,function(){e._debug("createOffer success"),e.destroyed||(e.trickle||e._iceComplete?n():e.once("_iceComplete",n))},function(t){e.destroy(o(t,"ERR_SET_LOCAL_DESCRIPTION"))}))},function(t){e.destroy(o(t,"ERR_CREATE_OFFER"))},e.offerConstraints)},r.prototype._createAnswer=function(){var e=this;e.destroyed||e._pc.createAnswer(function(t){function n(){var n=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:n.type,sdp:n.sdp})}e.destroyed||(t.sdp=e.sdpTransform(t.sdp),e._pc.setLocalDescription(t,function(){e.destroyed||(e.trickle||e._iceComplete?n():e.once("_iceComplete",n))},function(t){e.destroy(o(t,"ERR_SET_LOCAL_DESCRIPTION"))}))},function(t){e.destroy(o(t,"ERR_CREATE_ANSWER"))},e.answerConstraints)},r.prototype._onIceStateChange=function(){var e=this;if(!e.destroyed){var t=e._pc.iceConnectionState,n=e._pc.iceGatheringState;e._debug("iceStateChange (connection: %s) (gathering: %s)",t,n),e.emit("iceStateChange",t,n),("connected"===t||"completed"===t)&&(e._pcReady=!0,e._maybeReady()),"failed"===t&&e.destroy(o("Ice connection failed.","ERR_ICE_CONNECTION_FAILURE")),"closed"===t&&e.destroy(new Error("Ice connection closed."))}},r.prototype.getStats=function(e){var t=this;0===t._pc.getStats.length?t._pc.getStats().then(function(t){var n=[];t.forEach(function(e){n.push(e)}),e(null,n)},function(t){e(t)}):t._isReactNativeWebrtc?t._pc.getStats(null,function(t){var n=[];t.forEach(function(e){n.push(e)}),e(null,n)},function(t){e(t)}):0p)&&e._onChannelBufferedAmountLow()},r.prototype._onSignalingStateChange=function(){var e=this;e.destroyed||("stable"===e._pc.signalingState&&(e._isNegotiating=!1,e._debug("flushing sender queue",e._sendersAwaitingStable),e._sendersAwaitingStable.forEach(function(t){e.removeTrack(t),e._queuedNegotiation=!0}),e._sendersAwaitingStable=[],e._queuedNegotiation&&(e._debug("flushing negotiation queue"),e._queuedNegotiation=!1,e._needsNegotiation()),e._debug("negotiate"),e.emit("negotiate")),e._debug("signalingStateChange %s",e._pc.signalingState),e.emit("signalingStateChange",e._pc.signalingState))},r.prototype._onIceCandidate=function(e){var t=this;t.destroyed||(e.candidate&&t.trickle?t.emit("signal",{candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}}):!e.candidate&&(t._iceComplete=!0,t.emit("_iceComplete")))},r.prototype._onChannelMessage=function(e){var t=this;if(!t.destroyed){var r=e.data;r instanceof ArrayBuffer&&(r=n.from(r)),t.push(r)}},r.prototype._onChannelBufferedAmountLow=function(){var e=this;if(!e.destroyed&&e._cb){e._debug("ending backpressure: bufferedAmount %d",e._channel.bufferedAmount);var t=e._cb;e._cb=null,t(null)}},r.prototype._onChannelOpen=function(){var e=this;e.connected||e.destroyed||(e._debug("on channel open"),e._channelReady=!0,e._maybeReady())},r.prototype._onChannelClose=function(){var e=this;e.destroyed||(e._debug("on channel close"),e.destroy())},r.prototype._onTrack=function(e){var t=this;t.destroyed||e.streams.forEach(function(n){t._debug("on track"),t.emit("track",e.track,n),t._remoteTracks.push({track:e.track,stream:n}),t._remoteStreams.some(function(e){return e.id===n.id})||(t._remoteStreams.push(n),setTimeout(function(){t.emit("stream",n)},0))})},r.prototype._debug=function(){var e=this,t=[].slice.call(arguments);t[0]="["+e._id+"] "+t[0],i.apply(null,t)},r.prototype._transformConstraints=function(e){var t=this;if(0===Object.keys(e).length)return e;if((e.mandatory||e.optional)&&!t._isChromium){var n=Object.assign({},e.optional,e.mandatory);return void 0!==n.OfferToReceiveVideo&&(n.offerToReceiveVideo=n.OfferToReceiveVideo,delete n.OfferToReceiveVideo),void 0!==n.OfferToReceiveAudio&&(n.offerToReceiveAudio=n.OfferToReceiveAudio,delete n.OfferToReceiveAudio),n}return e.mandatory||e.optional||!t._isChromium?e:(void 0!==e.offerToReceiveVideo&&(e.OfferToReceiveVideo=e.offerToReceiveVideo,delete e.offerToReceiveVideo),void 0!==e.offerToReceiveAudio&&(e.OfferToReceiveAudio=e.offerToReceiveAudio,delete e.offerToReceiveAudio),{mandatory:e})}}).call(this,e("buffer").Buffer)},{buffer:3,debug:6,"get-browser-rtc":8,inherits:10,randombytes:16,"readable-stream":25}]},{},[])("/")}); 2 | --------------------------------------------------------------------------------