Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mercuryworkshop/bare-mux

Package Overview
Dependencies
Maintainers
0
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mercuryworkshop/bare-mux - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

2

dist/baretypes.d.ts

@@ -12,3 +12,3 @@ export type BareHeaders = Record<string, string | string[]>;

ready: boolean;
connect: (url: URL, origin: string, protocols: string[], requestHeaders: BareHeaders, onopen: (protocol: string) => void, onmessage: (data: Blob | ArrayBuffer | string) => void, onclose: (code: number, reason: string) => void, onerror: (error: string) => void) => [(data: Blob | ArrayBuffer | string) => void, (code: number, reason: string) => void];
connect: (url: URL, protocols: string[], requestHeaders: BareHeaders, onopen: (protocol: string) => void, onmessage: (data: Blob | ArrayBuffer | string) => void, onclose: (code: number, reason: string) => void, onerror: (error: string) => void) => [(data: Blob | ArrayBuffer | string) => void, (code: number, reason: string) => void];
request: (remote: URL, method: string, body: BodyInit | null, headers: BareHeaders, signal: AbortSignal | undefined) => Promise<TransferrableResponse>;

@@ -15,0 +15,0 @@ meta: () => BareMeta;

@@ -12,3 +12,2 @@ import { BareHeaders, TransferrableResponse } from "./baretypes";

url: string;
origin: string;
protocols: string[];

@@ -15,0 +14,0 @@ requestHeaders: BareHeaders;

@@ -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="undefined"!=typeof globalThis?globalThis:e||self).BareMux={})}(this,(function(e){"use strict";const t=globalThis.fetch,r=globalThis.SharedWorker,o=globalThis.localStorage,s=globalThis.navigator.serviceWorker,a=MessagePort.prototype.postMessage,n={prototype:{send:WebSocket.prototype.send},CLOSED:WebSocket.CLOSED,CLOSING:WebSocket.CLOSING,CONNECTING:WebSocket.CONNECTING,OPEN:WebSocket.OPEN};async function c(){const e=(await self.clients.matchAll({type:"window",includeUncontrolled:!0})).map((async e=>{const t=await function(e){let t=new MessageChannel;return new Promise((r=>{e.postMessage({type:"getPort",port:t.port2},[t.port2]),t.port1.onmessage=e=>{r(e.data)}}))}(e);return await i(t),t})),t=Promise.race([Promise.any(e),new Promise(((e,t)=>setTimeout(t,1e3,new TypeError("timeout"))))]);try{return await t}catch(e){if(e instanceof AggregateError)throw console.error("bare-mux: failed to get a bare-mux SharedWorker MessagePort as all clients returned an invalid MessagePort."),new Error("All clients returned an invalid MessagePort.");return console.warn("bare-mux: failed to get a bare-mux SharedWorker MessagePort within 1s, retrying"),await c()}}function i(e){const t=new MessageChannel,r=new Promise(((e,r)=>{t.port1.onmessage=t=>{"pong"===t.data.type&&e()},setTimeout(r,1500)}));return a.call(e,{message:{type:"ping"},port:t.port2},[t.port2]),r}function l(e,t){const o=new r(e,"bare-mux-worker");return t&&s.addEventListener("message",(t=>{if("getPort"===t.data.type&&t.data.port){console.debug("bare-mux: recieved request for port from sw");const o=new r(e,"bare-mux-worker");a.call(t.data.port,o.port,[o.port])}})),o.port}let h=null;function d(){if(null===h){const e=new MessageChannel,t=new ReadableStream;let r;try{a.call(e.port1,t,[t]),r=!0}catch(e){r=!1}return h=r,r}return h}class p{constructor(e){this.channel=new BroadcastChannel("bare-mux"),e instanceof MessagePort||e instanceof Promise?this.port=e:this.createChannel(e,!0)}createChannel(e,t){if(self.clients)this.port=c(),this.channel.onmessage=e=>{"refreshPort"===e.data.type&&(this.port=c())};else if(e&&SharedWorker){if(!e.startsWith("/")&&!e.includes("://"))throw new Error("Invalid URL. Must be absolute or start at the root.");this.port=l(e,t),console.debug("bare-mux: setting localStorage bare-mux-path to",e),o["bare-mux-path"]=e}else{if(!SharedWorker)throw new Error("Unable to get a channel to the SharedWorker.");{const e=o["bare-mux-path"];if(console.debug("bare-mux: got localStorage bare-mux-path:",e),!e)throw new Error("Unable to get bare-mux workerPath from localStorage.");this.port=l(e,t)}}}async sendMessage(e,t){this.port instanceof Promise&&(this.port=await this.port);try{await i(this.port)}catch{return console.warn("bare-mux: Failed to get a ping response from the worker within 1.5s. Assuming port is dead."),this.createChannel(),await this.sendMessage(e,t)}const r=new MessageChannel,o=[r.port2,...t||[]],s=new Promise(((e,t)=>{r.port1.onmessage=r=>{const o=r.data;"error"===o.type?t(o.error):e(o)}}));return a.call(this.port,{message:e,port:r.port2},o),await s}}class w extends EventTarget{constructor(e,t=[],r,o){super(),this.protocols=t,this.readyState=n.CONNECTING,this.url=e.toString(),this.protocols=t;const s=e=>{this.protocols=e,this.readyState=n.OPEN;const t=new Event("open");this.dispatchEvent(t)},a=async e=>{const t=new MessageEvent("message",{data:e});this.dispatchEvent(t)},c=(e,t)=>{this.readyState=n.CLOSED;const r=new CloseEvent("close",{code:e,reason:t});this.dispatchEvent(r)},i=()=>{this.readyState=n.CLOSED;const e=new Event("error");this.dispatchEvent(e)};this.channel=new MessageChannel,this.channel.port1.onmessage=e=>{"open"===e.data.type?s(e.data.args[0]):"message"===e.data.type?a(e.data.args[0]):"close"===e.data.type?c(e.data.args[0],e.data.args[1]):"error"===e.data.type&&i()},r.sendMessage({type:"websocket",websocket:{url:e.toString(),origin:origin,protocols:t,requestHeaders:o,channel:this.channel.port2}},[this.channel.port2])}send(...e){if(this.readyState===n.CONNECTING)throw new DOMException("Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.");let t=e[0];t.buffer&&(t=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)),a.call(this.channel.port1,{type:"data",data:t},t instanceof ArrayBuffer?[t]:[])}close(e,t){a.call(this.channel.port1,{type:"close",closeCode:e,closeReason:t})}}function u(e,t,r){console.error(`error while processing '${r}': `,t),e.postMessage({type:"error",error:t})}function f(e){for(let t=0;t<e.length;t++){const r=e[t];if(!"!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz|~".includes(r))return!1}return!0}const g=["ws:","wss:"],b=[101,204,205,304],y=[301,302,303,307,308];class m{constructor(e){this.worker=new p(e)}createWebSocket(e,t=[],r,o){try{e=new URL(e)}catch(t){throw new DOMException(`Faiiled to construct 'WebSocket': The URL '${e}' is invalid.`)}if(!g.includes(e.protocol))throw new DOMException(`Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${e.protocol}' is not allowed.`);Array.isArray(t)||(t=[t]),t=t.map(String);for(const e of t)if(!f(e))throw new DOMException(`Failed to construct 'WebSocket': The subprotocol '${e}' is invalid.`);o=o||{};return new w(e,t,this.worker,o)}async fetch(e,r){const o=new Request(e,r),s=r?.headers||o.headers,a=s instanceof Headers?Object.fromEntries(s):s,n=o.body;let c=new URL(o.url);if(c.protocol.startsWith("blob:")){const e=await t(c),r=new Response(e.body,e);return r.rawHeaders=Object.fromEntries(e.headers),r.rawResponse=e,r}for(let e=0;;e++){"host"in a?a.host=c.host:a.Host=c.host;let t=(await this.worker.sendMessage({type:"fetch",fetch:{remote:c.toString(),method:o.method,headers:a,body:n||void 0}},n?[n]:[])).fetch,s=new Response(b.includes(t.status)?void 0:t.body,{headers:new Headers(t.headers),status:t.status,statusText:t.statusText});s.rawHeaders=t.headers,s.rawResponse=new Response(t.body),s.finalURL=c.toString();const i=r?.redirect||o.redirect;if(!y.includes(s.status))return s;switch(i){case"follow":{const t=s.headers.get("location");if(20>e&&null!==t){c=new URL(t,c);continue}throw new TypeError("Failed to fetch")}case"error":throw new TypeError("Failed to fetch");case"manual":return s}}}}console.debug("bare-mux: running v2.1.3 (build 83330ed)"),e.BareClient=m,e.BareMuxConnection=class{constructor(e){this.worker=new p(e)}async getTransport(){return(await this.worker.sendMessage({type:"get"})).name}async setTransport(e,t,r){await this.setManualTransport(`\n\t\t\tconst { default: BareTransport } = await import("${e}");\n\t\t\treturn [BareTransport, "${e}"];\n\t\t`,t,r)}async setManualTransport(e,t,r){if("bare-mux-remote"===e)throw new Error("Use setRemoteTransport.");await this.worker.sendMessage({type:"set",client:{function:e,args:t}},r)}async setRemoteTransport(e,t){const r=new MessageChannel;r.port1.onmessage=async t=>{const r=t.data.port,o=t.data.message;if("fetch"===o.type)try{e.ready||await e.init(),await async function(e,t,r){const o=await r.request(new URL(e.fetch.remote),e.fetch.method,e.fetch.body,e.fetch.headers,null);if(!d()&&o.body instanceof ReadableStream){const e=new Response(o.body);o.body=await e.arrayBuffer()}o.body instanceof ReadableStream||o.body instanceof ArrayBuffer?a.call(t,{type:"fetch",fetch:o},[o.body]):a.call(t,{type:"fetch",fetch:o})}(o,r,e)}catch(e){u(r,e,"fetch")}else if("websocket"===o.type)try{e.ready||await e.init(),await async function(e,t,r){const[o,s]=r.connect(new URL(e.websocket.url),e.websocket.origin,e.websocket.protocols,e.websocket.requestHeaders,(t=>{a.call(e.websocket.channel,{type:"open",args:[t]})}),(t=>{t instanceof ArrayBuffer?a.call(e.websocket.channel,{type:"message",args:[t]},[t]):a.call(e.websocket.channel,{type:"message",args:[t]})}),((t,r)=>{a.call(e.websocket.channel,{type:"close",args:[t,r]})}),(t=>{a.call(e.websocket.channel,{type:"error",args:[t]})}));e.websocket.channel.onmessage=e=>{"data"===e.data.type?o(e.data.data):"close"===e.data.type&&s(e.data.closeCode,e.data.closeReason)},a.call(t,{type:"websocket"})}(o,r,e)}catch(e){u(r,e,"websocket")}},await this.worker.sendMessage({type:"set",client:{function:"bare-mux-remote",args:[r.port2,t]}},[r.port2])}getInnerPort(){return this.worker.port}},e.BareWebSocket=w,e.WebSocketFields=n,e.WorkerConnection=p,e.browserSupportsTransferringStreams=d,e.default=m,e.maxRedirects=20,e.validProtocol=f,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BareMux={})}(this,(function(e){"use strict";const t=globalThis.fetch,r=globalThis.SharedWorker,o=globalThis.localStorage,s=globalThis.navigator.serviceWorker,a=MessagePort.prototype.postMessage,n={prototype:{send:WebSocket.prototype.send},CLOSED:WebSocket.CLOSED,CLOSING:WebSocket.CLOSING,CONNECTING:WebSocket.CONNECTING,OPEN:WebSocket.OPEN};async function c(){const e=(await self.clients.matchAll({type:"window",includeUncontrolled:!0})).map((async e=>{const t=await function(e){let t=new MessageChannel;return new Promise((r=>{e.postMessage({type:"getPort",port:t.port2},[t.port2]),t.port1.onmessage=e=>{r(e.data)}}))}(e);return await i(t),t})),t=Promise.race([Promise.any(e),new Promise(((e,t)=>setTimeout(t,1e3,new TypeError("timeout"))))]);try{return await t}catch(e){if(e instanceof AggregateError)throw console.error("bare-mux: failed to get a bare-mux SharedWorker MessagePort as all clients returned an invalid MessagePort."),new Error("All clients returned an invalid MessagePort.");return console.warn("bare-mux: failed to get a bare-mux SharedWorker MessagePort within 1s, retrying"),await c()}}function i(e){const t=new MessageChannel,r=new Promise(((e,r)=>{t.port1.onmessage=t=>{"pong"===t.data.type&&e()},setTimeout(r,1500)}));return a.call(e,{message:{type:"ping"},port:t.port2},[t.port2]),r}function l(e,t){const o=new r(e,"bare-mux-worker");return t&&s.addEventListener("message",(t=>{if("getPort"===t.data.type&&t.data.port){console.debug("bare-mux: recieved request for port from sw");const o=new r(e,"bare-mux-worker");a.call(t.data.port,o.port,[o.port])}})),o.port}let h=null;function d(){if(null===h){const e=new MessageChannel,t=new ReadableStream;let r;try{a.call(e.port1,t,[t]),r=!0}catch(e){r=!1}return h=r,r}return h}class p{constructor(e){this.channel=new BroadcastChannel("bare-mux"),e instanceof MessagePort||e instanceof Promise?this.port=e:this.createChannel(e,!0)}createChannel(e,t){if(self.clients)this.port=c(),this.channel.onmessage=e=>{"refreshPort"===e.data.type&&(this.port=c())};else if(e&&SharedWorker){if(!e.startsWith("/")&&!e.includes("://"))throw new Error("Invalid URL. Must be absolute or start at the root.");this.port=l(e,t),console.debug("bare-mux: setting localStorage bare-mux-path to",e),o["bare-mux-path"]=e}else{if(!SharedWorker)throw new Error("Unable to get a channel to the SharedWorker.");{const e=o["bare-mux-path"];if(console.debug("bare-mux: got localStorage bare-mux-path:",e),!e)throw new Error("Unable to get bare-mux workerPath from localStorage.");this.port=l(e,t)}}}async sendMessage(e,t){this.port instanceof Promise&&(this.port=await this.port);try{await i(this.port)}catch{return console.warn("bare-mux: Failed to get a ping response from the worker within 1.5s. Assuming port is dead."),this.createChannel(),await this.sendMessage(e,t)}const r=new MessageChannel,o=[r.port2,...t||[]],s=new Promise(((e,t)=>{r.port1.onmessage=r=>{const o=r.data;"error"===o.type?t(o.error):e(o)}}));return a.call(this.port,{message:e,port:r.port2},o),await s}}class u extends EventTarget{constructor(e,t=[],r,o){super(),this.protocols=t,this.readyState=n.CONNECTING,this.url=e.toString(),this.protocols=t;const s=e=>{this.protocols=e,this.readyState=n.OPEN;const t=new Event("open");this.dispatchEvent(t)},a=async e=>{const t=new MessageEvent("message",{data:e});this.dispatchEvent(t)},c=(e,t)=>{this.readyState=n.CLOSED;const r=new CloseEvent("close",{code:e,reason:t});this.dispatchEvent(r)},i=()=>{this.readyState=n.CLOSED;const e=new Event("error");this.dispatchEvent(e)};this.channel=new MessageChannel,this.channel.port1.onmessage=e=>{"open"===e.data.type?s(e.data.args[0]):"message"===e.data.type?a(e.data.args[0]):"close"===e.data.type?c(e.data.args[0],e.data.args[1]):"error"===e.data.type&&i()},r.sendMessage({type:"websocket",websocket:{url:e.toString(),protocols:t,requestHeaders:o,channel:this.channel.port2}},[this.channel.port2])}send(...e){if(this.readyState===n.CONNECTING)throw new DOMException("Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.");let t=e[0];t.buffer&&(t=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)),a.call(this.channel.port1,{type:"data",data:t},t instanceof ArrayBuffer?[t]:[])}close(e,t){a.call(this.channel.port1,{type:"close",closeCode:e,closeReason:t})}}function w(e,t,r){console.error(`error while processing '${r}': `,t),e.postMessage({type:"error",error:t})}function f(e){for(let t=0;t<e.length;t++){const r=e[t];if(!"!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz|~".includes(r))return!1}return!0}const g=["ws:","wss:"],y=[101,204,205,304],b=[301,302,303,307,308];class m{constructor(e){this.worker=new p(e)}createWebSocket(e,t=[],r,o){try{e=new URL(e)}catch(t){throw new DOMException(`Faiiled to construct 'WebSocket': The URL '${e}' is invalid.`)}if(!g.includes(e.protocol))throw new DOMException(`Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${e.protocol}' is not allowed.`);Array.isArray(t)||(t=[t]),t=t.map(String);for(const e of t)if(!f(e))throw new DOMException(`Failed to construct 'WebSocket': The subprotocol '${e}' is invalid.`);o=o||{};return new u(e,t,this.worker,o)}async fetch(e,r){const o=new Request(e,r),s=r?.headers||o.headers,a=s instanceof Headers?Object.fromEntries(s):s,n=o.body;let c=new URL(o.url);if(c.protocol.startsWith("blob:")){const e=await t(c),r=new Response(e.body,e);return r.rawHeaders=Object.fromEntries(e.headers),r.rawResponse=e,r}for(let e=0;;e++){"host"in a?a.host=c.host:a.Host=c.host;let t=(await this.worker.sendMessage({type:"fetch",fetch:{remote:c.toString(),method:o.method,headers:a,body:n||void 0}},n?[n]:[])).fetch,s=new Response(y.includes(t.status)?void 0:t.body,{headers:new Headers(t.headers),status:t.status,statusText:t.statusText});s.rawHeaders=t.headers,s.rawResponse=new Response(t.body),s.finalURL=c.toString();const i=r?.redirect||o.redirect;if(!b.includes(s.status))return s;switch(i){case"follow":{const t=s.headers.get("location");if(20>e&&null!==t){c=new URL(t,c);continue}throw new TypeError("Failed to fetch")}case"error":throw new TypeError("Failed to fetch");case"manual":return s}}}}console.debug("bare-mux: running v2.1.4 (build 4c62e7a)"),e.BareClient=m,e.BareMuxConnection=class{constructor(e){this.worker=new p(e)}async getTransport(){return(await this.worker.sendMessage({type:"get"})).name}async setTransport(e,t,r){await this.setManualTransport(`\n\t\t\tconst { default: BareTransport } = await import("${e}");\n\t\t\treturn [BareTransport, "${e}"];\n\t\t`,t,r)}async setManualTransport(e,t,r){if("bare-mux-remote"===e)throw new Error("Use setRemoteTransport.");await this.worker.sendMessage({type:"set",client:{function:e,args:t}},r)}async setRemoteTransport(e,t){const r=new MessageChannel;r.port1.onmessage=async t=>{const r=t.data.port,o=t.data.message;if("fetch"===o.type)try{e.ready||await e.init(),await async function(e,t,r){const o=await r.request(new URL(e.fetch.remote),e.fetch.method,e.fetch.body,e.fetch.headers,null);if(!d()&&o.body instanceof ReadableStream){const e=new Response(o.body);o.body=await e.arrayBuffer()}o.body instanceof ReadableStream||o.body instanceof ArrayBuffer?a.call(t,{type:"fetch",fetch:o},[o.body]):a.call(t,{type:"fetch",fetch:o})}(o,r,e)}catch(e){w(r,e,"fetch")}else if("websocket"===o.type)try{e.ready||await e.init(),await async function(e,t,r){const[o,s]=r.connect(new URL(e.websocket.url),e.websocket.protocols,e.websocket.requestHeaders,(t=>{a.call(e.websocket.channel,{type:"open",args:[t]})}),(t=>{t instanceof ArrayBuffer?a.call(e.websocket.channel,{type:"message",args:[t]},[t]):a.call(e.websocket.channel,{type:"message",args:[t]})}),((t,r)=>{a.call(e.websocket.channel,{type:"close",args:[t,r]})}),(t=>{a.call(e.websocket.channel,{type:"error",args:[t]})}));e.websocket.channel.onmessage=e=>{"data"===e.data.type?o(e.data.data):"close"===e.data.type&&s(e.data.closeCode,e.data.closeReason)},a.call(t,{type:"websocket"})}(o,r,e)}catch(e){w(r,e,"websocket")}},await this.worker.sendMessage({type:"set",client:{function:"bare-mux-remote",args:[r.port2,t]}},[r.port2])}getInnerPort(){return this.worker.port}},e.BareWebSocket=u,e.WebSocketFields=n,e.WorkerConnection=p,e.browserSupportsTransferringStreams=d,e.default=m,e.maxRedirects=20,e.validProtocol=f,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map

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

!function(){"use strict";const e=MessagePort.prototype.postMessage;let t=null;function a(e,t,a){console.error(`error while processing '${a}': `,t),e.postMessage({type:"error",error:t})}async function n(a,n,s){const o=await s.request(new URL(a.fetch.remote),a.fetch.method,a.fetch.body,a.fetch.headers,null);if(!function(){if(null===t){const a=new MessageChannel,n=new ReadableStream;let s;try{e.call(a.port1,n,[n]),s=!0}catch(e){s=!1}return t=s,s}return t}()&&o.body instanceof ReadableStream){const e=new Response(o.body);o.body=await e.arrayBuffer()}o.body instanceof ReadableStream||o.body instanceof ArrayBuffer?e.call(n,{type:"fetch",fetch:o},[o.body]):e.call(n,{type:"fetch",fetch:o})}let s=null,o="";function c(){return new Error("there are no bare clients",{cause:"No BareTransport was set. Try creating a BareMuxConnection and calling setTransport() or setManualTransport() on it before using BareClient."})}function r(t,a){const n=s;let o=[a];t.fetch?.body&&o.push(t.fetch.body),t.websocket?.channel&&o.push(t.websocket.channel),e.call(n,{message:t,port:a},o)}function l(t){t.onmessage=async t=>{const l=t.data.port,i=t.data.message;if("ping"===i.type)e.call(l,{type:"pong"});else if("set"===i.type)try{const t=async function(){}.constructor;if("bare-mux-remote"===i.client.function)s=i.client.args[0],o=`bare-mux-remote (${i.client.args[1]})`;else{const e=new t(i.client.function),[a,n]=await e();s=new a(...i.client.args),o=n}console.log("set transport to ",s,o),e.call(l,{type:"set"})}catch(e){a(l,e,"set")}else if("get"===i.type)l.postMessage({type:"get",name:o});else if("fetch"===i.type)try{if(!s)throw c();if(s instanceof MessagePort)return void r(i,l);s.ready||await s.init(),await n(i,l,s)}catch(e){a(l,e,"fetch")}else if("websocket"===i.type)try{if(!s)throw c();if(s instanceof MessagePort)return void r(i,l);s.ready||await s.init(),await async function(t,a,n){const[s,o]=n.connect(new URL(t.websocket.url),t.websocket.origin,t.websocket.protocols,t.websocket.requestHeaders,(a=>{e.call(t.websocket.channel,{type:"open",args:[a]})}),(a=>{a instanceof ArrayBuffer?e.call(t.websocket.channel,{type:"message",args:[a]},[a]):e.call(t.websocket.channel,{type:"message",args:[a]})}),((a,n)=>{e.call(t.websocket.channel,{type:"close",args:[a,n]})}),(a=>{e.call(t.websocket.channel,{type:"error",args:[a]})}));t.websocket.channel.onmessage=e=>{"data"===e.data.type?s(e.data.data):"close"===e.data.type&&o(e.data.closeCode,e.data.closeReason)},e.call(a,{type:"websocket"})}(i,l,s)}catch(e){a(l,e,"websocket")}}}new BroadcastChannel("bare-mux").postMessage({type:"refreshPort"}),self.onconnect=e=>{l(e.ports[0])},console.debug("bare-mux: running v2.1.3 (build 83330ed)")}();
!function(){"use strict";const e=MessagePort.prototype.postMessage;let t=null;function a(e,t,a){console.error(`error while processing '${a}': `,t),e.postMessage({type:"error",error:t})}async function n(a,n,s){const o=await s.request(new URL(a.fetch.remote),a.fetch.method,a.fetch.body,a.fetch.headers,null);if(!function(){if(null===t){const a=new MessageChannel,n=new ReadableStream;let s;try{e.call(a.port1,n,[n]),s=!0}catch(e){s=!1}return t=s,s}return t}()&&o.body instanceof ReadableStream){const e=new Response(o.body);o.body=await e.arrayBuffer()}o.body instanceof ReadableStream||o.body instanceof ArrayBuffer?e.call(n,{type:"fetch",fetch:o},[o.body]):e.call(n,{type:"fetch",fetch:o})}let s=null,o="";function c(){return new Error("there are no bare clients",{cause:"No BareTransport was set. Try creating a BareMuxConnection and calling setTransport() or setManualTransport() on it before using BareClient."})}function r(t,a){const n=s;let o=[a];t.fetch?.body&&o.push(t.fetch.body),t.websocket?.channel&&o.push(t.websocket.channel),e.call(n,{message:t,port:a},o)}function l(t){t.onmessage=async t=>{const l=t.data.port,i=t.data.message;if("ping"===i.type)e.call(l,{type:"pong"});else if("set"===i.type)try{const t=async function(){}.constructor;if("bare-mux-remote"===i.client.function)s=i.client.args[0],o=`bare-mux-remote (${i.client.args[1]})`;else{const e=new t(i.client.function),[a,n]=await e();s=new a(...i.client.args),o=n}console.log("set transport to ",s,o),e.call(l,{type:"set"})}catch(e){a(l,e,"set")}else if("get"===i.type)l.postMessage({type:"get",name:o});else if("fetch"===i.type)try{if(!s)throw c();if(s instanceof MessagePort)return void r(i,l);s.ready||await s.init(),await n(i,l,s)}catch(e){a(l,e,"fetch")}else if("websocket"===i.type)try{if(!s)throw c();if(s instanceof MessagePort)return void r(i,l);s.ready||await s.init(),await async function(t,a,n){const[s,o]=n.connect(new URL(t.websocket.url),t.websocket.protocols,t.websocket.requestHeaders,(a=>{e.call(t.websocket.channel,{type:"open",args:[a]})}),(a=>{a instanceof ArrayBuffer?e.call(t.websocket.channel,{type:"message",args:[a]},[a]):e.call(t.websocket.channel,{type:"message",args:[a]})}),((a,n)=>{e.call(t.websocket.channel,{type:"close",args:[a,n]})}),(a=>{e.call(t.websocket.channel,{type:"error",args:[a]})}));t.websocket.channel.onmessage=e=>{"data"===e.data.type?s(e.data.data):"close"===e.data.type&&o(e.data.closeCode,e.data.closeReason)},e.call(a,{type:"websocket"})}(i,l,s)}catch(e){a(l,e,"websocket")}}}new BroadcastChannel("bare-mux").postMessage({type:"refreshPort"}),self.onconnect=e=>{l(e.ports[0])},console.debug("bare-mux: running v2.1.4 (build 4c62e7a)")}();
//# sourceMappingURL=worker.js.map
{
"name": "@mercuryworkshop/bare-mux",
"version": "2.1.3",
"version": "2.1.4",
"description": "",

@@ -24,5 +24,5 @@ "type": "module",

"devDependencies": {
"@rollup/plugin-replace": "^6.0.1",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-replace": "^5.0.5",
"rollup": "^4.9.6",
"rollup": "^4.24.0",
"rollup-plugin-typescript2": "^0.36.0"

@@ -29,0 +29,0 @@ },

@@ -19,3 +19,2 @@ # bare-mux

url: URL,
origin: string,
protocols: string[],

@@ -22,0 +21,0 @@ requestHeaders: BareHeaders,

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