New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@webrtc-remote-control/core

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webrtc-remote-control/core - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

dist/index.modern.js

@@ -1,2 +0,2 @@

import e from"eventemitter3";function n(){return n=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var o=arguments[n];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},n.apply(this,arguments)}function o(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:n=>n.metadata===e,connMetadata:e}}function r({sessionStorageKey:e,humanErrors:r}={}){const t=function({mapping:e,withTechicalErrorMessage:o}={mapping:{},withTechicalErrorMessage:!0}){const r=n({"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:"")},e);return function(e){const n=r[e.type]||("function"==typeof r.default?r.default(e):r.default);return n&&e.message&&o?`${n} (${e.message})`:n}}(r),{isConnectionFromRemote:i}=o(),{getPeerId:s,setPeerIdToSessionStorage:a}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(n){sessionStorage.setItem(e,n)}}}(e);return{humanizeError:t,isConnectionFromRemote:i,getPeerId:s,setPeerIdToSessionStorage:a}}var t={__proto__:null,default:function({humanizeError:n,isConnectionFromRemote:o,getPeerId:r,setPeerIdToSessionStorage:t}){return{humanizeError:n,isConnectionFromRemote:o,getPeerId:r,bindConnection:n=>new Promise(r=>{const i=new e,s=[],a={sendTo(e,n){const o=s.find(n=>n.peer===e);return o?o.send(n):null},sendAll(e){s.forEach(n=>{n.send(e)})},on:i.on.bind(i),off:i.off.bind(i)};n.on("open",e=>{t(e),r(a)}),n.on("connection",e=>{if(o(e)){if(s.findIndex(({peer:n})=>n===e.peer)>-1){const n=s.findIndex(({peer:n})=>n===e.peer);s[n]=e}else s.push(e);console.log("connections",s),e.on("open",()=>{i.emit("remote.connect",{id:e.peer})}),e.on("data",n=>{i.emit("data",{id:e.peer,from:"remote"},n)}),e.on("close",()=>{i.emit("remote.disconnect",{id:e.peer})})}})})}},prepareUtils:r},i={__proto__:null,default:function({humanizeError:n,getPeerId:r,setPeerIdToSessionStorage:t}){return{humanizeError:n,getPeerId:r,bindConnection:(n,r)=>new Promise(i=>{let s=null;const a=new e,c={send(e){s?s.send(e):console.warning("You called `send` with no connection")},on:a.on.bind(a),off:a.off.bind(a)},d=e=>{s=null,s=function(e,n,r,t){const{connMetadata:i}=o(),s=e.connect(n,{serialization:"json",metadata:i});return s.on("open",()=>{"function"==typeof t&&t()}),s.on("data",e=>{r.emit("data",{from:"master"},e)}),s}(n,r,a,e),s.on("close",()=>{a.emit("remote.disconnect",{id:n.id}),d(()=>{a.emit("remote.reconnect",{id:n.id})})})};n.on("open",e=>{t(e),d(()=>i(c)),s.on("error",e=>{console.log("conn.error",e)}),window.addEventListener("beforeunload",()=>{s&&s.disconnect&&s.disconnect()})})})}},prepareUtils:r};export{t as master,r as prepareUtils,i as remote};
import e from"eventemitter3";function o(){return o=Object.assign||function(e){for(var o=1;o<arguments.length;o++){var n=arguments[o];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},o.apply(this,arguments)}function n(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:o=>o.metadata===e,connMetadata:e}}function t({sessionStorageKey:e,humanErrors:t}={}){const r=function({mapping:e,withTechicalErrorMessage:n}={mapping:{},withTechicalErrorMessage:!0}){const t=o({"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:"")},e);return function(e){const o=t[e.type]||("function"==typeof t.default?t.default(e):t.default);return o&&e.message&&n?`${o} (${e.message})`:o}}(t),{isConnectionFromRemote:s}=n(),{getPeerId:i,setPeerIdToSessionStorage:a}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(o){sessionStorage.setItem(e,o)}}}(e);return{humanizeError:r,isConnectionFromRemote:s,getPeerId:i,setPeerIdToSessionStorage:a}}var r={__proto__:null,default:function({humanizeError:o,isConnectionFromRemote:n,getPeerId:t,setPeerIdToSessionStorage:r}){return{humanizeError:o,isConnectionFromRemote:n,getPeerId:t,bindConnection:o=>new Promise(t=>{const s=new e,i=new Map,a={sendTo(e,o){const n=i.get(e);return n?n.send(o):null},sendAll(e){[...i.values()].forEach(o=>{o.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};o.on("open",e=>{r(e),t(a)}),o.on("connection",e=>{n(e)&&(i.set(e.peer,e),e.on("open",()=>{s.emit("remote.connect",{id:e.peer}),console.log("connections",i)}),e.on("data",o=>{s.emit("data",{id:e.peer,from:"remote"},o)}),e.on("close",()=>{i.delete(e.peer),s.emit("remote.disconnect",{id:e.peer}),console.log("connections",i)}))})})}},prepareUtils:t},s={__proto__:null,default:function({humanizeError:o,getPeerId:t,setPeerIdToSessionStorage:r}){return{humanizeError:o,getPeerId:t,bindConnection:(o,t)=>new Promise(s=>{let i=null;const a=new e,c={send(e){i?i.send(e):console.warning("You called `send` with no connection")},on:a.on.bind(a),off:a.off.bind(a)},d=e=>{i=null,i=function(e,o,t,r){const{connMetadata:s}=n(),i=e.connect(o,{serialization:"json",metadata:s});return i.on("open",()=>{"function"==typeof r&&r()}),i.on("data",e=>{t.emit("data",{from:"master"},e)}),i}(o,t,a,e),i.on("close",()=>{a.emit("remote.disconnect",{id:o.id}),d(()=>{a.emit("remote.reconnect",{id:o.id})})})};o.on("open",e=>{r(e),d(()=>s(c)),i.on("error",e=>{console.log("conn.error",e)}),window.addEventListener("beforeunload",()=>{i&&i.disconnect&&i.disconnect()})})})}},prepareUtils:t};export{r as master,t as prepareUtils,s as remote};
//# sourceMappingURL=index.modern.js.map

@@ -1,2 +0,2 @@

import e from"eventemitter3";function o(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:o=>o.metadata===e,connMetadata:e}}function n({sessionStorageKey:e,humanErrors:n}={}){const r=function({mapping:e,withTechicalErrorMessage:o}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const r=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return r&&e.message&&o?`${r} (${e.message})`:r}}(n),{isConnectionFromRemote:t}=o(),{getPeerId:i,setPeerIdToSessionStorage:s}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(o){sessionStorage.setItem(e,o)}}}(e);return{humanizeError:r,isConnectionFromRemote:t,getPeerId:i,setPeerIdToSessionStorage:s}}var r={__proto__:null,default:function({humanizeError:o,isConnectionFromRemote:n,getPeerId:r,setPeerIdToSessionStorage:t}){return{humanizeError:o,isConnectionFromRemote:n,getPeerId:r,bindConnection:o=>new Promise(r=>{const i=new e,s=[],c={sendTo(e,o){const n=s.find(o=>o.peer===e);return n?n.send(o):null},sendAll(e){s.forEach(o=>{o.send(e)})},on:i.on.bind(i),off:i.off.bind(i)};o.on("open",e=>{t(e),r(c)}),o.on("connection",e=>{if(n(e)){if(s.findIndex(({peer:o})=>o===e.peer)>-1){const o=s.findIndex(({peer:o})=>o===e.peer);s[o]=e}else s.push(e);console.log("connections",s),e.on("open",()=>{i.emit("remote.connect",{id:e.peer})}),e.on("data",o=>{i.emit("data",{id:e.peer,from:"remote"},o)}),e.on("close",()=>{i.emit("remote.disconnect",{id:e.peer})})}})})}},prepareUtils:n},t={__proto__:null,default:function({humanizeError:n,getPeerId:r,setPeerIdToSessionStorage:t}){return{humanizeError:n,getPeerId:r,bindConnection:(n,r)=>new Promise(i=>{let s=null;const c=new e,a={send(e){s?s.send(e):console.warning("You called `send` with no connection")},on:c.on.bind(c),off:c.off.bind(c)},d=e=>{s=null,s=function(e,n,r,t){const{connMetadata:i}=o(),s=e.connect(n,{serialization:"json",metadata:i});return s.on("open",()=>{"function"==typeof t&&t()}),s.on("data",e=>{r.emit("data",{from:"master"},e)}),s}(n,r,c,e),s.on("close",()=>{c.emit("remote.disconnect",{id:n.id}),d(()=>{c.emit("remote.reconnect",{id:n.id})})})};n.on("open",e=>{t(e),d(()=>i(a)),s.on("error",e=>{console.log("conn.error",e)}),window.addEventListener("beforeunload",()=>{s&&s.disconnect&&s.disconnect()})})})}},prepareUtils:n};export{r as master,n as prepareUtils,t as remote};
import e from"eventemitter3";function o(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:o=>o.metadata===e,connMetadata:e}}function n({sessionStorageKey:e,humanErrors:n}={}){const t=function({mapping:e,withTechicalErrorMessage:o}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const t=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return t&&e.message&&o?`${t} (${e.message})`:t}}(n),{isConnectionFromRemote:r}=o(),{getPeerId:s,setPeerIdToSessionStorage:i}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(o){sessionStorage.setItem(e,o)}}}(e);return{humanizeError:t,isConnectionFromRemote:r,getPeerId:s,setPeerIdToSessionStorage:i}}var t={__proto__:null,default:function({humanizeError:o,isConnectionFromRemote:n,getPeerId:t,setPeerIdToSessionStorage:r}){return{humanizeError:o,isConnectionFromRemote:n,getPeerId:t,bindConnection:o=>new Promise(t=>{const s=new e,i=new Map,c={sendTo(e,o){const n=i.get(e);return n?n.send(o):null},sendAll(e){[...i.values()].forEach(o=>{o.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};o.on("open",e=>{r(e),t(c)}),o.on("connection",e=>{n(e)&&(i.set(e.peer,e),e.on("open",()=>{s.emit("remote.connect",{id:e.peer}),console.log("connections",i)}),e.on("data",o=>{s.emit("data",{id:e.peer,from:"remote"},o)}),e.on("close",()=>{i.delete(e.peer),s.emit("remote.disconnect",{id:e.peer}),console.log("connections",i)}))})})}},prepareUtils:n},r={__proto__:null,default:function({humanizeError:n,getPeerId:t,setPeerIdToSessionStorage:r}){return{humanizeError:n,getPeerId:t,bindConnection:(n,t)=>new Promise(s=>{let i=null;const c=new e,a={send(e){i?i.send(e):console.warning("You called `send` with no connection")},on:c.on.bind(c),off:c.off.bind(c)},d=e=>{i=null,i=function(e,n,t,r){const{connMetadata:s}=o(),i=e.connect(n,{serialization:"json",metadata:s});return i.on("open",()=>{"function"==typeof r&&r()}),i.on("data",e=>{t.emit("data",{from:"master"},e)}),i}(n,t,c,e),i.on("close",()=>{c.emit("remote.disconnect",{id:n.id}),d(()=>{c.emit("remote.reconnect",{id:n.id})})})};n.on("open",e=>{r(e),d(()=>s(a)),i.on("error",e=>{console.log("conn.error",e)}),window.addEventListener("beforeunload",()=>{i&&i.disconnect&&i.disconnect()})})})}},prepareUtils:n};export{t as master,n as prepareUtils,r as remote};
//# sourceMappingURL=index.module.js.map

@@ -1,2 +0,2 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("eventemitter3")):"function"==typeof define&&define.amd?define(["exports","eventemitter3"],n):n((e||self).webrtcRemoteControl={},e.eventemitter3)}(this,function(e,n){function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=/*#__PURE__*/o(n);function r(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:n=>n.metadata===e,connMetadata:e}}function i({sessionStorageKey:e,humanErrors:n}={}){const o=function({mapping:e,withTechicalErrorMessage:n}={mapping:{},withTechicalErrorMessage:!0}){const o={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const t=o[e.type]||("function"==typeof o.default?o.default(e):o.default);return t&&e.message&&n?`${t} (${e.message})`:t}}(n),{isConnectionFromRemote:t}=r(),{getPeerId:i,setPeerIdToSessionStorage:s}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(n){sessionStorage.setItem(e,n)}}}(e);return{humanizeError:o,isConnectionFromRemote:t,getPeerId:i,setPeerIdToSessionStorage:s}}var s={__proto__:null,default:function({humanizeError:e,getPeerId:n,setPeerIdToSessionStorage:o}){return{humanizeError:e,getPeerId:n,bindConnection:(e,n)=>new Promise(i=>{let s=null;const c=new t.default,a={send(e){s?s.send(e):console.warning("You called `send` with no connection")},on:c.on.bind(c),off:c.off.bind(c)},d=o=>{s=null,s=function(e,n,o,t){const{connMetadata:i}=r(),s=e.connect(n,{serialization:"json",metadata:i});return s.on("open",()=>{"function"==typeof t&&t()}),s.on("data",e=>{o.emit("data",{from:"master"},e)}),s}(e,n,c,o),s.on("close",()=>{c.emit("remote.disconnect",{id:e.id}),d(()=>{c.emit("remote.reconnect",{id:e.id})})})};e.on("open",e=>{o(e),d(()=>i(a)),s.on("error",e=>{console.log("conn.error",e)}),window.addEventListener("beforeunload",()=>{s&&s.disconnect&&s.disconnect()})})})}},prepareUtils:i};e.master={__proto__:null,default:function({humanizeError:e,isConnectionFromRemote:n,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,isConnectionFromRemote:n,getPeerId:o,bindConnection:e=>new Promise(o=>{const i=new t.default,s=[],c={sendTo(e,n){const o=s.find(n=>n.peer===e);return o?o.send(n):null},sendAll(e){s.forEach(n=>{n.send(e)})},on:i.on.bind(i),off:i.off.bind(i)};e.on("open",e=>{r(e),o(c)}),e.on("connection",e=>{if(n(e)){if(s.findIndex(({peer:n})=>n===e.peer)>-1){const n=s.findIndex(({peer:n})=>n===e.peer);s[n]=e}else s.push(e);console.log("connections",s),e.on("open",()=>{i.emit("remote.connect",{id:e.peer})}),e.on("data",n=>{i.emit("data",{id:e.peer,from:"remote"},n)}),e.on("close",()=>{i.emit("remote.disconnect",{id:e.peer})})}})})}},prepareUtils:i},e.prepareUtils=i,e.remote=s});
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("eventemitter3")):"function"==typeof define&&define.amd?define(["exports","eventemitter3"],o):o((e||self).webrtcRemoteControl={},e.eventemitter3)}(this,function(e,o){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=/*#__PURE__*/n(o);function r(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:o=>o.metadata===e,connMetadata:e}}function i({sessionStorageKey:e,humanErrors:o}={}){const n=function({mapping:e,withTechicalErrorMessage:o}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const t=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return t&&e.message&&o?`${t} (${e.message})`:t}}(o),{isConnectionFromRemote:t}=r(),{getPeerId:i,setPeerIdToSessionStorage:s}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(o){sessionStorage.setItem(e,o)}}}(e);return{humanizeError:n,isConnectionFromRemote:t,getPeerId:i,setPeerIdToSessionStorage:s}}var s={__proto__:null,default:function({humanizeError:e,getPeerId:o,setPeerIdToSessionStorage:n}){return{humanizeError:e,getPeerId:o,bindConnection:(e,o)=>new Promise(i=>{let s=null;const c=new t.default,a={send(e){s?s.send(e):console.warning("You called `send` with no connection")},on:c.on.bind(c),off:c.off.bind(c)},d=n=>{s=null,s=function(e,o,n,t){const{connMetadata:i}=r(),s=e.connect(o,{serialization:"json",metadata:i});return s.on("open",()=>{"function"==typeof t&&t()}),s.on("data",e=>{n.emit("data",{from:"master"},e)}),s}(e,o,c,n),s.on("close",()=>{c.emit("remote.disconnect",{id:e.id}),d(()=>{c.emit("remote.reconnect",{id:e.id})})})};e.on("open",e=>{n(e),d(()=>i(a)),s.on("error",e=>{console.log("conn.error",e)}),window.addEventListener("beforeunload",()=>{s&&s.disconnect&&s.disconnect()})})})}},prepareUtils:i};e.master={__proto__:null,default:function({humanizeError:e,isConnectionFromRemote:o,getPeerId:n,setPeerIdToSessionStorage:r}){return{humanizeError:e,isConnectionFromRemote:o,getPeerId:n,bindConnection:e=>new Promise(n=>{const i=new t.default,s=new Map,c={sendTo(e,o){const n=s.get(e);return n?n.send(o):null},sendAll(e){[...s.values()].forEach(o=>{o.send(e)})},on:i.on.bind(i),off:i.off.bind(i)};e.on("open",e=>{r(e),n(c)}),e.on("connection",e=>{o(e)&&(s.set(e.peer,e),e.on("open",()=>{i.emit("remote.connect",{id:e.peer}),console.log("connections",s)}),e.on("data",o=>{i.emit("data",{id:e.peer,from:"remote"},o)}),e.on("close",()=>{s.delete(e.peer),i.emit("remote.disconnect",{id:e.peer}),console.log("connections",s)}))})})}},prepareUtils:i},e.prepareUtils=i,e.remote=s});
//# sourceMappingURL=index.umd.js.map

@@ -443,6 +443,6 @@ (function (global, factory) {

const ee = new eventemitter3();
const connections = [];
const connections = new Map();
const wrcMaster = {
sendTo(id, payload) {
const conn = connections.find(currentConn => currentConn.peer === id);
const conn = connections.get(id);

@@ -457,3 +457,3 @@ if (conn) {

sendAll(payload) {
connections.forEach(conn => {
[...connections.values()].forEach(conn => {
conn.send(payload);

@@ -477,14 +477,3 @@ });

if (connections.findIndex(({
peer: id
}) => id === conn.peer) > -1) {
const index = connections.findIndex(({
peer: id
}) => id === conn.peer);
connections[index] = conn;
} else {
connections.push(conn);
}
console.log("connections", connections);
connections.set(conn.peer, conn);
conn.on("open", () => {

@@ -494,2 +483,3 @@ ee.emit("remote.connect", {

});
console.log("connections", connections);
});

@@ -503,5 +493,7 @@ conn.on("data", data => {

conn.on("close", () => {
connections.delete(conn.peer);
ee.emit("remote.disconnect", {
id: conn.peer
});
console.log("connections", connections);
});

@@ -508,0 +500,0 @@ });

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).webrtcRemoteControl={})}(this,function(e){var t=function(e){var t={exports:{}};return function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,o,s,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var c=new r(o,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function c(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)t.call(e,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var o=0,r=t.length,s=new Array(r);o<r;o++)s[o]=t[o].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,o,r,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,f,u=this._events[c],l=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),l){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,o),!0;case 4:return u.fn.call(u.context,t,o,r),!0;case 5:return u.fn.call(u.context,t,o,r,s),!0;case 6:return u.fn.call(u.context,t,o,r,s,i),!0}for(f=1,a=new Array(l-1);f<l;f++)a[f-1]=arguments[f];u.fn.apply(u.context,a)}else{var p,d=u.length;for(f=0;f<d;f++)switch(u[f].once&&this.removeListener(e,u[f].fn,void 0,!0),l){case 1:u[f].fn.call(u[f].context);break;case 2:u[f].fn.call(u[f].context,t);break;case 3:u[f].fn.call(u[f].context,t,o);break;case 4:u[f].fn.call(u[f].context,t,o,r);break;default:if(!a)for(p=1,a=new Array(l-1);p<l;p++)a[p-1]=arguments[p];u[f].fn.apply(u[f].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,o,r){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||r&&!c.once||o&&c.context!==o||i(this,s);else{for(var a=0,f=[],u=c.length;a<u;a++)(c[a].fn!==t||r&&!c[a].once||o&&c[a].context!==o)&&f.push(c[a]);f.length?this._events[s]=1===f.length?f[0]:f:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new o,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c}(t),t.exports}();function n(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}function o({sessionStorageKey:e,humanErrors:t}={}){const o=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const o=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return o&&e.message&&t?`${o} (${e.message})`:o}}(t),{isConnectionFromRemote:r}=n(),{getPeerId:s,setPeerIdToSessionStorage:i}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:o,isConnectionFromRemote:r,getPeerId:s,setPeerIdToSessionStorage:i}}var r={__proto__:null,default:function({humanizeError:e,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,getPeerId:o,bindConnection:(e,o)=>new Promise(s=>{let i=null;const c=new t,a={send(e){i?i.send(e):console.warning("You called `send` with no connection")},on:c.on.bind(c),off:c.off.bind(c)},f=t=>{i=null,i=function(e,t,o,r){const{connMetadata:s}=n(),i=e.connect(t,{serialization:"json",metadata:s});return i.on("open",()=>{"function"==typeof r&&r()}),i.on("data",e=>{o.emit("data",{from:"master"},e)}),i}(e,o,c,t),i.on("close",()=>{c.emit("remote.disconnect",{id:e.id}),f(()=>{c.emit("remote.reconnect",{id:e.id})})})};e.on("open",e=>{r(e),f(()=>s(a)),i.on("error",e=>{console.log("conn.error",e)}),window.addEventListener("beforeunload",()=>{i&&i.disconnect&&i.disconnect()})})})}},prepareUtils:o};e.master={__proto__:null,default:function({humanizeError:e,isConnectionFromRemote:n,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,isConnectionFromRemote:n,getPeerId:o,bindConnection:e=>new Promise(o=>{const s=new t,i=[],c={sendTo(e,t){const n=i.find(t=>t.peer===e);return n?n.send(t):null},sendAll(e){i.forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{r(e),o(c)}),e.on("connection",e=>{if(n(e)){if(i.findIndex(({peer:t})=>t===e.peer)>-1){const t=i.findIndex(({peer:t})=>t===e.peer);i[t]=e}else i.push(e);console.log("connections",i),e.on("open",()=>{s.emit("remote.connect",{id:e.peer})}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{s.emit("remote.disconnect",{id:e.peer})})}})})}},prepareUtils:o},e.prepareUtils=o,e.remote=r});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).webrtcRemoteControl={})}(this,function(e){var t=function(e){var t={exports:{}};return function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,o,s,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var c=new r(o,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function c(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)t.call(e,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var o=0,r=t.length,s=new Array(r);o<r;o++)s[o]=t[o].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,o,r,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,f,u=this._events[c],l=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),l){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,o),!0;case 4:return u.fn.call(u.context,t,o,r),!0;case 5:return u.fn.call(u.context,t,o,r,s),!0;case 6:return u.fn.call(u.context,t,o,r,s,i),!0}for(f=1,a=new Array(l-1);f<l;f++)a[f-1]=arguments[f];u.fn.apply(u.context,a)}else{var p,d=u.length;for(f=0;f<d;f++)switch(u[f].once&&this.removeListener(e,u[f].fn,void 0,!0),l){case 1:u[f].fn.call(u[f].context);break;case 2:u[f].fn.call(u[f].context,t);break;case 3:u[f].fn.call(u[f].context,t,o);break;case 4:u[f].fn.call(u[f].context,t,o,r);break;default:if(!a)for(p=1,a=new Array(l-1);p<l;p++)a[p-1]=arguments[p];u[f].fn.apply(u[f].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,o,r){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||r&&!c.once||o&&c.context!==o||i(this,s);else{for(var a=0,f=[],u=c.length;a<u;a++)(c[a].fn!==t||r&&!c[a].once||o&&c[a].context!==o)&&f.push(c[a]);f.length?this._events[s]=1===f.length?f[0]:f:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new o,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c}(t),t.exports}();function n(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}function o({sessionStorageKey:e,humanErrors:t}={}){const o=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const o=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return o&&e.message&&t?`${o} (${e.message})`:o}}(t),{isConnectionFromRemote:r}=n(),{getPeerId:s,setPeerIdToSessionStorage:i}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:o,isConnectionFromRemote:r,getPeerId:s,setPeerIdToSessionStorage:i}}var r={__proto__:null,default:function({humanizeError:e,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,getPeerId:o,bindConnection:(e,o)=>new Promise(s=>{let i=null;const c=new t,a={send(e){i?i.send(e):console.warning("You called `send` with no connection")},on:c.on.bind(c),off:c.off.bind(c)},f=t=>{i=null,i=function(e,t,o,r){const{connMetadata:s}=n(),i=e.connect(t,{serialization:"json",metadata:s});return i.on("open",()=>{"function"==typeof r&&r()}),i.on("data",e=>{o.emit("data",{from:"master"},e)}),i}(e,o,c,t),i.on("close",()=>{c.emit("remote.disconnect",{id:e.id}),f(()=>{c.emit("remote.reconnect",{id:e.id})})})};e.on("open",e=>{r(e),f(()=>s(a)),i.on("error",e=>{console.log("conn.error",e)}),window.addEventListener("beforeunload",()=>{i&&i.disconnect&&i.disconnect()})})})}},prepareUtils:o};e.master={__proto__:null,default:function({humanizeError:e,isConnectionFromRemote:n,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,isConnectionFromRemote:n,getPeerId:o,bindConnection:e=>new Promise(o=>{const s=new t,i=new Map,c={sendTo(e,t){const n=i.get(e);return n?n.send(t):null},sendAll(e){[...i.values()].forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{r(e),o(c)}),e.on("connection",e=>{n(e)&&(i.set(e.peer,e),e.on("open",()=>{s.emit("remote.connect",{id:e.peer}),console.log("connections",i)}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{i.delete(e.peer),s.emit("remote.disconnect",{id:e.peer}),console.log("connections",i)}))})})}},prepareUtils:o},e.prepareUtils=o,e.remote=r});
//# sourceMappingURL=webrtc-remote-control.umd.prod.js.map

@@ -1,2 +0,2 @@

var e,t,n=(e=function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,r,s,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var c=new o(r,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function c(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var r=0,o=t.length,s=new Array(o);r<o;r++)s[r]=t[r].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,r,o,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,f,u=this._events[c],p=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),p){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,r),!0;case 4:return u.fn.call(u.context,t,r,o),!0;case 5:return u.fn.call(u.context,t,r,o,s),!0;case 6:return u.fn.call(u.context,t,r,o,s,i),!0}for(f=1,a=new Array(p-1);f<p;f++)a[f-1]=arguments[f];u.fn.apply(u.context,a)}else{var l,h=u.length;for(f=0;f<h;f++)switch(u[f].once&&this.removeListener(e,u[f].fn,void 0,!0),p){case 1:u[f].fn.call(u[f].context);break;case 2:u[f].fn.call(u[f].context,t);break;case 3:u[f].fn.call(u[f].context,t,r);break;case 4:u[f].fn.call(u[f].context,t,r,o);break;default:if(!a)for(l=1,a=new Array(p-1);l<p;l++)a[l-1]=arguments[l];u[f].fn.apply(u[f].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,r,o){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||o&&!c.once||r&&c.context!==r||i(this,s);else{for(var a=0,f=[],u=c.length;a<u;a++)(c[a].fn!==t||o&&!c[a].once||r&&c[a].context!==r)&&f.push(c[a]);f.length?this._events[s]=1===f.length?f[0]:f:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new r,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c},e(t={exports:{}}),t.exports);exports.default=function({humanizeError:e,isConnectionFromRemote:t,getPeerId:r,setPeerIdToSessionStorage:o}){return{humanizeError:e,isConnectionFromRemote:t,getPeerId:r,bindConnection:e=>new Promise(r=>{const s=new n,i=[],c={sendTo(e,t){const n=i.find(t=>t.peer===e);return n?n.send(t):null},sendAll(e){i.forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{o(e),r(c)}),e.on("connection",e=>{if(t(e)){if(i.findIndex(({peer:t})=>t===e.peer)>-1){const t=i.findIndex(({peer:t})=>t===e.peer);i[t]=e}else i.push(e);console.log("connections",i),e.on("open",()=>{s.emit("remote.connect",{id:e.peer})}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{s.emit("remote.disconnect",{id:e.peer})})}})})}},exports.prepareUtils=function({sessionStorageKey:e,humanErrors:t}={}){const n=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const r=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return r&&e.message&&t?`${r} (${e.message})`:r}}(t),{isConnectionFromRemote:r}=function(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}(),{getPeerId:o,setPeerIdToSessionStorage:s}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:n,isConnectionFromRemote:r,getPeerId:o,setPeerIdToSessionStorage:s}};
var e,t,n=(e=function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,o,s,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var c=new r(o,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function c(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)t.call(e,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var o=0,r=t.length,s=new Array(r);o<r;o++)s[o]=t[o].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,o,r,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,u,f=this._events[c],l=arguments.length;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),l){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,o),!0;case 4:return f.fn.call(f.context,t,o,r),!0;case 5:return f.fn.call(f.context,t,o,r,s),!0;case 6:return f.fn.call(f.context,t,o,r,s,i),!0}for(u=1,a=new Array(l-1);u<l;u++)a[u-1]=arguments[u];f.fn.apply(f.context,a)}else{var p,h=f.length;for(u=0;u<h;u++)switch(f[u].once&&this.removeListener(e,f[u].fn,void 0,!0),l){case 1:f[u].fn.call(f[u].context);break;case 2:f[u].fn.call(f[u].context,t);break;case 3:f[u].fn.call(f[u].context,t,o);break;case 4:f[u].fn.call(f[u].context,t,o,r);break;default:if(!a)for(p=1,a=new Array(l-1);p<l;p++)a[p-1]=arguments[p];f[u].fn.apply(f[u].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,o,r){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||r&&!c.once||o&&c.context!==o||i(this,s);else{for(var a=0,u=[],f=c.length;a<f;a++)(c[a].fn!==t||r&&!c[a].once||o&&c[a].context!==o)&&u.push(c[a]);u.length?this._events[s]=1===u.length?u[0]:u:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new o,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c},e(t={exports:{}}),t.exports);exports.default=function({humanizeError:e,isConnectionFromRemote:t,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,isConnectionFromRemote:t,getPeerId:o,bindConnection:e=>new Promise(o=>{const s=new n,i=new Map,c={sendTo(e,t){const n=i.get(e);return n?n.send(t):null},sendAll(e){[...i.values()].forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{r(e),o(c)}),e.on("connection",e=>{t(e)&&(i.set(e.peer,e),e.on("open",()=>{s.emit("remote.connect",{id:e.peer}),console.log("connections",i)}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{i.delete(e.peer),s.emit("remote.disconnect",{id:e.peer}),console.log("connections",i)}))})})}},exports.prepareUtils=function({sessionStorageKey:e,humanErrors:t}={}){const n=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const o=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return o&&e.message&&t?`${o} (${e.message})`:o}}(t),{isConnectionFromRemote:o}=function(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}(),{getPeerId:r,setPeerIdToSessionStorage:s}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:n,isConnectionFromRemote:o,getPeerId:r,setPeerIdToSessionStorage:s}};
//# sourceMappingURL=master.js.map

@@ -1,2 +0,2 @@

var e,t,n=(e=function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,r,s,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var c=new o(r,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function c(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var r=0,o=t.length,s=new Array(o);r<o;r++)s[r]=t[r].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,r,o,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,f,u=this._events[c],p=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),p){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,r),!0;case 4:return u.fn.call(u.context,t,r,o),!0;case 5:return u.fn.call(u.context,t,r,o,s),!0;case 6:return u.fn.call(u.context,t,r,o,s,i),!0}for(f=1,a=new Array(p-1);f<p;f++)a[f-1]=arguments[f];u.fn.apply(u.context,a)}else{var l,h=u.length;for(f=0;f<h;f++)switch(u[f].once&&this.removeListener(e,u[f].fn,void 0,!0),p){case 1:u[f].fn.call(u[f].context);break;case 2:u[f].fn.call(u[f].context,t);break;case 3:u[f].fn.call(u[f].context,t,r);break;case 4:u[f].fn.call(u[f].context,t,r,o);break;default:if(!a)for(l=1,a=new Array(p-1);l<p;l++)a[l-1]=arguments[l];u[f].fn.apply(u[f].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,r,o){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||o&&!c.once||r&&c.context!==r||i(this,s);else{for(var a=0,f=[],u=c.length;a<u;a++)(c[a].fn!==t||o&&!c[a].once||r&&c[a].context!==r)&&f.push(c[a]);f.length?this._events[s]=1===f.length?f[0]:f:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new r,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c},e(t={exports:{}}),t.exports);function r(){return r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},r.apply(this,arguments)}function o({sessionStorageKey:e,humanErrors:t}={}){const n=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n=r({"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:"")},e);return function(e){const r=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return r&&e.message&&t?`${r} (${e.message})`:r}}(t),{isConnectionFromRemote:o}=function(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}(),{getPeerId:s,setPeerIdToSessionStorage:i}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:n,isConnectionFromRemote:o,getPeerId:s,setPeerIdToSessionStorage:i}}function s({humanizeError:e,isConnectionFromRemote:t,getPeerId:r,setPeerIdToSessionStorage:o}){return{humanizeError:e,isConnectionFromRemote:t,getPeerId:r,bindConnection:e=>new Promise(r=>{const s=new n,i=[],c={sendTo(e,t){const n=i.find(t=>t.peer===e);return n?n.send(t):null},sendAll(e){i.forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{o(e),r(c)}),e.on("connection",e=>{if(t(e)){if(i.findIndex(({peer:t})=>t===e.peer)>-1){const t=i.findIndex(({peer:t})=>t===e.peer);i[t]=e}else i.push(e);console.log("connections",i),e.on("open",()=>{s.emit("remote.connect",{id:e.peer})}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{s.emit("remote.disconnect",{id:e.peer})})}})})}}export{s as default,o as prepareUtils};
var e,t,n=(e=function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,o,s,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var c=new r(o,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function c(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)t.call(e,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var o=0,r=t.length,s=new Array(r);o<r;o++)s[o]=t[o].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,o,r,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,u,f=this._events[c],l=arguments.length;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),l){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,o),!0;case 4:return f.fn.call(f.context,t,o,r),!0;case 5:return f.fn.call(f.context,t,o,r,s),!0;case 6:return f.fn.call(f.context,t,o,r,s,i),!0}for(u=1,a=new Array(l-1);u<l;u++)a[u-1]=arguments[u];f.fn.apply(f.context,a)}else{var p,h=f.length;for(u=0;u<h;u++)switch(f[u].once&&this.removeListener(e,f[u].fn,void 0,!0),l){case 1:f[u].fn.call(f[u].context);break;case 2:f[u].fn.call(f[u].context,t);break;case 3:f[u].fn.call(f[u].context,t,o);break;case 4:f[u].fn.call(f[u].context,t,o,r);break;default:if(!a)for(p=1,a=new Array(l-1);p<l;p++)a[p-1]=arguments[p];f[u].fn.apply(f[u].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,o,r){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||r&&!c.once||o&&c.context!==o||i(this,s);else{for(var a=0,u=[],f=c.length;a<f;a++)(c[a].fn!==t||r&&!c[a].once||o&&c[a].context!==o)&&u.push(c[a]);u.length?this._events[s]=1===u.length?u[0]:u:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new o,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c},e(t={exports:{}}),t.exports);function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},o.apply(this,arguments)}function r({sessionStorageKey:e,humanErrors:t}={}){const n=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n=o({"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:"")},e);return function(e){const o=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return o&&e.message&&t?`${o} (${e.message})`:o}}(t),{isConnectionFromRemote:r}=function(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}(),{getPeerId:s,setPeerIdToSessionStorage:i}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:n,isConnectionFromRemote:r,getPeerId:s,setPeerIdToSessionStorage:i}}function s({humanizeError:e,isConnectionFromRemote:t,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,isConnectionFromRemote:t,getPeerId:o,bindConnection:e=>new Promise(o=>{const s=new n,i=new Map,c={sendTo(e,t){const n=i.get(e);return n?n.send(t):null},sendAll(e){[...i.values()].forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{r(e),o(c)}),e.on("connection",e=>{t(e)&&(i.set(e.peer,e),e.on("open",()=>{s.emit("remote.connect",{id:e.peer}),console.log("connections",i)}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{i.delete(e.peer),s.emit("remote.disconnect",{id:e.peer}),console.log("connections",i)}))})})}}export{s as default,r as prepareUtils};
//# sourceMappingURL=master.modern.js.map

@@ -1,2 +0,2 @@

var e,t,n=(e=function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,r,s,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var c=new o(r,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function c(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var r=0,o=t.length,s=new Array(o);r<o;r++)s[r]=t[r].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,r,o,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,f,u=this._events[c],p=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),p){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,r),!0;case 4:return u.fn.call(u.context,t,r,o),!0;case 5:return u.fn.call(u.context,t,r,o,s),!0;case 6:return u.fn.call(u.context,t,r,o,s,i),!0}for(f=1,a=new Array(p-1);f<p;f++)a[f-1]=arguments[f];u.fn.apply(u.context,a)}else{var l,h=u.length;for(f=0;f<h;f++)switch(u[f].once&&this.removeListener(e,u[f].fn,void 0,!0),p){case 1:u[f].fn.call(u[f].context);break;case 2:u[f].fn.call(u[f].context,t);break;case 3:u[f].fn.call(u[f].context,t,r);break;case 4:u[f].fn.call(u[f].context,t,r,o);break;default:if(!a)for(l=1,a=new Array(p-1);l<p;l++)a[l-1]=arguments[l];u[f].fn.apply(u[f].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,r,o){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||o&&!c.once||r&&c.context!==r||i(this,s);else{for(var a=0,f=[],u=c.length;a<u;a++)(c[a].fn!==t||o&&!c[a].once||r&&c[a].context!==r)&&f.push(c[a]);f.length?this._events[s]=1===f.length?f[0]:f:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new r,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c},e(t={exports:{}}),t.exports);function r({sessionStorageKey:e,humanErrors:t}={}){const n=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const r=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return r&&e.message&&t?`${r} (${e.message})`:r}}(t),{isConnectionFromRemote:r}=function(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}(),{getPeerId:o,setPeerIdToSessionStorage:s}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:n,isConnectionFromRemote:r,getPeerId:o,setPeerIdToSessionStorage:s}}function o({humanizeError:e,isConnectionFromRemote:t,getPeerId:r,setPeerIdToSessionStorage:o}){return{humanizeError:e,isConnectionFromRemote:t,getPeerId:r,bindConnection:e=>new Promise(r=>{const s=new n,i=[],c={sendTo(e,t){const n=i.find(t=>t.peer===e);return n?n.send(t):null},sendAll(e){i.forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{o(e),r(c)}),e.on("connection",e=>{if(t(e)){if(i.findIndex(({peer:t})=>t===e.peer)>-1){const t=i.findIndex(({peer:t})=>t===e.peer);i[t]=e}else i.push(e);console.log("connections",i),e.on("open",()=>{s.emit("remote.connect",{id:e.peer})}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{s.emit("remote.disconnect",{id:e.peer})})}})})}}export{o as default,r as prepareUtils};
var e,t,n=(e=function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,o,s,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var c=new r(o,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function c(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)t.call(e,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var o=0,r=t.length,s=new Array(r);o<r;o++)s[o]=t[o].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,o,r,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,u,f=this._events[c],l=arguments.length;if(f.fn){switch(f.once&&this.removeListener(e,f.fn,void 0,!0),l){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,t),!0;case 3:return f.fn.call(f.context,t,o),!0;case 4:return f.fn.call(f.context,t,o,r),!0;case 5:return f.fn.call(f.context,t,o,r,s),!0;case 6:return f.fn.call(f.context,t,o,r,s,i),!0}for(u=1,a=new Array(l-1);u<l;u++)a[u-1]=arguments[u];f.fn.apply(f.context,a)}else{var p,h=f.length;for(u=0;u<h;u++)switch(f[u].once&&this.removeListener(e,f[u].fn,void 0,!0),l){case 1:f[u].fn.call(f[u].context);break;case 2:f[u].fn.call(f[u].context,t);break;case 3:f[u].fn.call(f[u].context,t,o);break;case 4:f[u].fn.call(f[u].context,t,o,r);break;default:if(!a)for(p=1,a=new Array(l-1);p<l;p++)a[p-1]=arguments[p];f[u].fn.apply(f[u].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,o,r){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||r&&!c.once||o&&c.context!==o||i(this,s);else{for(var a=0,u=[],f=c.length;a<f;a++)(c[a].fn!==t||r&&!c[a].once||o&&c[a].context!==o)&&u.push(c[a]);u.length?this._events[s]=1===u.length?u[0]:u:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new o,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c},e(t={exports:{}}),t.exports);function o({sessionStorageKey:e,humanErrors:t}={}){const n=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const o=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return o&&e.message&&t?`${o} (${e.message})`:o}}(t),{isConnectionFromRemote:o}=function(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}(),{getPeerId:r,setPeerIdToSessionStorage:s}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:n,isConnectionFromRemote:o,getPeerId:r,setPeerIdToSessionStorage:s}}function r({humanizeError:e,isConnectionFromRemote:t,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,isConnectionFromRemote:t,getPeerId:o,bindConnection:e=>new Promise(o=>{const s=new n,i=new Map,c={sendTo(e,t){const n=i.get(e);return n?n.send(t):null},sendAll(e){[...i.values()].forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{r(e),o(c)}),e.on("connection",e=>{t(e)&&(i.set(e.peer,e),e.on("open",()=>{s.emit("remote.connect",{id:e.peer}),console.log("connections",i)}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{i.delete(e.peer),s.emit("remote.disconnect",{id:e.peer}),console.log("connections",i)}))})})}}export{r as default,o as prepareUtils};
//# sourceMappingURL=master.module.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).webrtcRemoteControlMaster={})}(this,function(e){var t=function(e){var t={exports:{}};return function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,o,s,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var c=new r(o,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function c(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)t.call(e,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var o=0,r=t.length,s=new Array(r);o<r;o++)s[o]=t[o].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,o,r,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,f,u=this._events[c],p=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),p){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,o),!0;case 4:return u.fn.call(u.context,t,o,r),!0;case 5:return u.fn.call(u.context,t,o,r,s),!0;case 6:return u.fn.call(u.context,t,o,r,s,i),!0}for(f=1,a=new Array(p-1);f<p;f++)a[f-1]=arguments[f];u.fn.apply(u.context,a)}else{var l,d=u.length;for(f=0;f<d;f++)switch(u[f].once&&this.removeListener(e,u[f].fn,void 0,!0),p){case 1:u[f].fn.call(u[f].context);break;case 2:u[f].fn.call(u[f].context,t);break;case 3:u[f].fn.call(u[f].context,t,o);break;case 4:u[f].fn.call(u[f].context,t,o,r);break;default:if(!a)for(l=1,a=new Array(p-1);l<p;l++)a[l-1]=arguments[l];u[f].fn.apply(u[f].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,o,r){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||r&&!c.once||o&&c.context!==o||i(this,s);else{for(var a=0,f=[],u=c.length;a<u;a++)(c[a].fn!==t||r&&!c[a].once||o&&c[a].context!==o)&&f.push(c[a]);f.length?this._events[s]=1===f.length?f[0]:f:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new o,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c}(t),t.exports}();e.default=function({humanizeError:e,isConnectionFromRemote:n,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,isConnectionFromRemote:n,getPeerId:o,bindConnection:e=>new Promise(o=>{const s=new t,i=[],c={sendTo(e,t){const n=i.find(t=>t.peer===e);return n?n.send(t):null},sendAll(e){i.forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{r(e),o(c)}),e.on("connection",e=>{if(n(e)){if(i.findIndex(({peer:t})=>t===e.peer)>-1){const t=i.findIndex(({peer:t})=>t===e.peer);i[t]=e}else i.push(e);console.log("connections",i),e.on("open",()=>{s.emit("remote.connect",{id:e.peer})}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{s.emit("remote.disconnect",{id:e.peer})})}})})}},e.prepareUtils=function({sessionStorageKey:e,humanErrors:t}={}){const n=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const o=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return o&&e.message&&t?`${o} (${e.message})`:o}}(t),{isConnectionFromRemote:o}=function(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}(),{getPeerId:r,setPeerIdToSessionStorage:s}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:n,isConnectionFromRemote:o,getPeerId:r,setPeerIdToSessionStorage:s}}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).webrtcRemoteControlMaster={})}(this,function(e){var t=function(e){var t={exports:{}};return function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function s(e,t,o,s,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var c=new r(o,s||e,i),a=n?n+t:t;return e._events[a]?e._events[a].fn?e._events[a]=[e._events[a],c]:e._events[a].push(c):(e._events[a]=c,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function c(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),c.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)t.call(e,o)&&r.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},c.prototype.listeners=function(e){var t=this._events[n?n+e:e];if(!t)return[];if(t.fn)return[t.fn];for(var o=0,r=t.length,s=new Array(r);o<r;o++)s[o]=t[o].fn;return s},c.prototype.listenerCount=function(e){var t=this._events[n?n+e:e];return t?t.fn?1:t.length:0},c.prototype.emit=function(e,t,o,r,s,i){var c=n?n+e:e;if(!this._events[c])return!1;var a,f,u=this._events[c],l=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),l){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,o),!0;case 4:return u.fn.call(u.context,t,o,r),!0;case 5:return u.fn.call(u.context,t,o,r,s),!0;case 6:return u.fn.call(u.context,t,o,r,s,i),!0}for(f=1,a=new Array(l-1);f<l;f++)a[f-1]=arguments[f];u.fn.apply(u.context,a)}else{var p,h=u.length;for(f=0;f<h;f++)switch(u[f].once&&this.removeListener(e,u[f].fn,void 0,!0),l){case 1:u[f].fn.call(u[f].context);break;case 2:u[f].fn.call(u[f].context,t);break;case 3:u[f].fn.call(u[f].context,t,o);break;case 4:u[f].fn.call(u[f].context,t,o,r);break;default:if(!a)for(p=1,a=new Array(l-1);p<l;p++)a[p-1]=arguments[p];u[f].fn.apply(u[f].context,a)}}return!0},c.prototype.on=function(e,t,n){return s(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return s(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,o,r){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return i(this,s),this;var c=this._events[s];if(c.fn)c.fn!==t||r&&!c.once||o&&c.context!==o||i(this,s);else{for(var a=0,f=[],u=c.length;a<u;a++)(c[a].fn!==t||r&&!c[a].once||o&&c[a].context!==o)&&f.push(c[a]);f.length?this._events[s]=1===f.length?f[0]:f:i(this,s)}return this},c.prototype.removeAllListeners=function(e){var t;return e?this._events[t=n?n+e:e]&&i(this,t):(this._events=new o,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,e.exports=c}(t),t.exports}();e.default=function({humanizeError:e,isConnectionFromRemote:n,getPeerId:o,setPeerIdToSessionStorage:r}){return{humanizeError:e,isConnectionFromRemote:n,getPeerId:o,bindConnection:e=>new Promise(o=>{const s=new t,i=new Map,c={sendTo(e,t){const n=i.get(e);return n?n.send(t):null},sendAll(e){[...i.values()].forEach(t=>{t.send(e)})},on:s.on.bind(s),off:s.off.bind(s)};e.on("open",e=>{r(e),o(c)}),e.on("connection",e=>{n(e)&&(i.set(e.peer,e),e.on("open",()=>{s.emit("remote.connect",{id:e.peer}),console.log("connections",i)}),e.on("data",t=>{s.emit("data",{id:e.peer,from:"remote"},t)}),e.on("close",()=>{i.delete(e.peer),s.emit("remote.disconnect",{id:e.peer}),console.log("connections",i)}))})})}},e.prepareUtils=function({sessionStorageKey:e,humanErrors:t}={}){const n=function({mapping:e,withTechicalErrorMessage:t}={mapping:{},withTechicalErrorMessage:!0}){const n={"browser-incompatible":"Your browser doesn't support WebRTC features, please try with a recent browser.",disconnected:"You are disconnected and can't make any more peer connection, please reload.",network:"It seems you're experimenting some network problems.","peer-unavailable":"The peer you were connected to seems to have lost connection, try to reload it.","server-error":"An error occured on the signaling server. Sorry, try to come back later.",default:e=>"An error occured"+(e.type?` - type: ${e.type}`:""),...e};return function(e){const o=n[e.type]||("function"==typeof n.default?n.default(e):n.default);return o&&e.message&&t?`${o} (${e.message})`:o}}(t),{isConnectionFromRemote:o}=function(){const e="from-webrtc-remote-control";return{isConnectionFromRemote:t=>t.metadata===e,connMetadata:e}}(),{getPeerId:r,setPeerIdToSessionStorage:s}=function(e="webrtc-remote-control-peer-id"){return{getPeerId:()=>sessionStorage.getItem(e),setPeerIdToSessionStorage(t){sessionStorage.setItem(e,t)}}}(e);return{humanizeError:n,isConnectionFromRemote:o,getPeerId:r,setPeerIdToSessionStorage:s}}});
//# sourceMappingURL=master.umd.js.map

@@ -10,2 +10,4 @@ import EventEmitter from "eventemitter3";

export { prepareUtils } from "../../shared/common";
export default function ({

@@ -12,0 +14,0 @@ humanizeError,

@@ -19,8 +19,6 @@ /* eslint-disable import/no-relative-packages,import/no-extraneous-dependencies */

const ee = new EventEmitter();
const connections = [];
const connections = new Map();
const wrcMaster = {
sendTo(id, payload) {
const conn = connections.find(
(currentConn) => currentConn.peer === id
);
const conn = connections.get(id);
if (conn) {

@@ -32,3 +30,3 @@ return conn.send(payload);

sendAll(payload) {
connections.forEach((conn) => {
[...connections.values()].forEach((conn) => {
conn.send(payload);

@@ -50,13 +48,6 @@ });

// if this is a reconnect from the same peer, replace connection with the latest one
if (connections.findIndex(({ peer: id }) => id === conn.peer) > -1) {
const index = connections.findIndex(
({ peer: id }) => id === conn.peer
);
connections[index] = conn;
} else {
connections.push(conn);
}
console.log("connections", connections);
connections.set(conn.peer, conn);
conn.on("open", () => {
ee.emit("remote.connect", { id: conn.peer });
console.log("connections", connections);
});

@@ -67,3 +58,5 @@ conn.on("data", (data) => {

conn.on("close", () => {
connections.delete(conn.peer);
ee.emit("remote.disconnect", { id: conn.peer });
console.log("connections", connections);
});

@@ -70,0 +63,0 @@ });

{
"name": "@webrtc-remote-control/core",
"amdName": "webrtcRemoteControl",
"version": "0.1.0",
"version": "0.1.1",
"repository": {

@@ -67,3 +67,3 @@ "type": "git",

},
"gitHead": "0f5db41c8333255627099e2ceecd9210de60b6ff"
"gitHead": "250c71a342dce12be8d759d279b43bd7170f1926"
}

@@ -11,6 +11,2 @@ # @webrtc-remote-control/core

Check the [demos](https://github.com/topheman/webrtc-remote-control/tree/master/demo#readme) to have a better understanding.
[More infos on topheman/webrtc-remote-control](https://github.com/topheman/webrtc-remote-control#readme).
## Installation

@@ -22,10 +18,6 @@

## Usage
This package is the core one. Implementations for popular frameworks such as react or vue are available [here](https://github.com/topheman/webrtc-remote-control/tree/master/packages).
## Example code
## Usage
More examples in [demo](https://github.com/topheman/webrtc-remote-control/tree/master/demo).
Add the peerjs library as a script tag in your html page. You'll have access to `Peer` constructor.

@@ -37,2 +29,4 @@

Direct link to the [demo](https://webrtc-remote-control.vercel.app/counter-vanilla/master.html) source code: [master.js](https://github.com/topheman/webrtc-remote-control/blob/master/demo/counter-vanilla/js/master.js) / [remote.js](https://github.com/topheman/webrtc-remote-control/blob/master/demo/counter-vanilla/js/remote.js)
### master

@@ -39,0 +33,0 @@

@@ -9,2 +9,4 @@ import EventEmitter from "eventemitter3";

export { prepareUtils } from "../../shared/common";
export default function ({

@@ -11,0 +13,0 @@ humanizeError,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc