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

@bfchain/bnrtc2-client

Package Overview
Dependencies
Maintainers
6
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bfchain/bnrtc2-client - npm Package Compare versions

Comparing version 0.0.1-alpha.19 to 0.0.1-alpha.21

build/bnrtc2Client.js

19

build/index.js

@@ -1,1 +0,18 @@

var B=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var U=B(b=>{"use strict";var v=b&&b.__awaiter||function(r,t,n,e){function s(i){return i instanceof n?i:new n(function(c){c(i)})}return new(n||(n=Promise))(function(i,c){function h(o){try{d(e.next(o))}catch(u){c(u)}}function p(o){try{d(e.throw(o))}catch(u){c(u)}}function d(o){o.done?i(o.value):s(o.value).then(h,p)}d((e=e.apply(r,t||[])).next())})};Object.defineProperty(b,"__esModule",{value:!0});b.Bnrtc2Client=void 0;var E=require("@bfchain/bnrtc2-client-api"),A=require("@bfchain/util-extends-promise"),m=require("@bfcs/util-evt");require("@bfchain/bnrtc2-client-typings");var M=require("@bfchain/bnrtc2-buffer"),I=require("@bfchain/util-extends-map"),F=3e4,f;(function(r){r[r.PORT=0]="PORT",r[r.DATA=1]="DATA",r[r.CLOSE=2]="CLOSE"})(f||(f={}));var P=r=>r;typeof Blob!="undefined"&&(P=r=>{let t=new FileReader;return r instanceof Blob?(t.readAsArrayBuffer(r),new Promise((n,e)=>{t.onload=s=>{s.loaded===s.total&&n(new Uint8Array(t.result))},t.onerror=e})):r});var y=class{constructor(t=E.DEFAULT_BASE_API_HOSTNAME,n=E.DEFAULT_BASE_API_PORT){this._msgIdAcc=new Uint32Array(1),this._dport2FunctionsMap=new Map,this._msg2TaskMap=I.EasyMap.from({creater:a=>{let O=new A.PromiseOut,L=(0,A.sleep)(F,()=>{O.reject(7)});return O.onFinished(()=>{(0,A.unsleep)(L),this._msg2TaskMap.delete(a)}),O}}),this._api=new E.Bnrtc2Api(t,n);let e=new m.StatefulEvt(0);this.onReadyStateChanged=e.attacher;let s=e.poster,i=new m.StatefulEvt(!1);this.onOpen=i.attacher;let c=i.poster,h=new m.StatefulEvt(!1);this.onClose=h.attacher;let p=h.poster,d=new m.Evt;this.onError=d.attacher;let o=d.poster,u=new m.Evt;this.onMessage=u.attacher;let D=u.poster;this.onReadyStateChanged.attach(a=>{a===1?this.onOpen.state===!1&&c.post(!0):a===3&&this.onClose.state===!1&&p.post(!0)});let _=this._api.connectChannel();_.addEventListener("open",()=>{s.post(1)}),_.addEventListener("close",()=>{s.post(3)}),_.addEventListener("error",a=>{o.post(new Error(`rtc error ${a}`))}),this.close=(a,O)=>{e.state===2||e.state===3||(s.post(2),this._close(a,O))},this.onOpen.attach(()=>{if(this.send=this._send.bind(this),this.port=_.send.bind(_),this._beforeOpenOperators!==void 0)for(let a of this._beforeOpenOperators){if(a[0]===f.DATA)this._doSend(a[1],a[2],a[3],a[4]);else if(a[0]===f.PORT)this.port(a[1]);else if(a[0]===f.CLOSE){this._close();break}this._beforeOpenOperators=void 0}}),this.onClose.attach(()=>{this.close()}),_.addEventListener("message",a=>{D.post(a.data)}),this._channel=_,this.onMessage.attach(this._runHandler.bind(this))}send(t,n,e){var s;return v(this,void 0,void 0,function*(){let i=this._getMessageId(),c=this._msg2TaskMap.forceGet(i);return((s=this._beforeOpenOperators)!==null&&s!==void 0?s:this._beforeOpenOperators=[]).push([f.DATA,i,t,n,e]),c.promise})}close(t,n){var e;((e=this._beforeOpenOperators)!==null&&e!==void 0?e:this._beforeOpenOperators=[]).push([f.CLOSE,t,n])}port(t){var n;((n=this._beforeOpenOperators)!==null&&n!==void 0?n:this._beforeOpenOperators=[]).push([f.PORT,t])}_getMessageId(){return this._msgIdAcc[0]++}_send(t,n,e){return v(this,void 0,void 0,function*(){let s=this._getMessageId(),i=this._msg2TaskMap.forceGet(s);return this._doSend(s,t,n,e),i.promise})}_doSend(t,n,e,s){s instanceof Uint8Array&&(s=M.Bnrtc2Buffer.from(s)),s.putU32(t);let i=s.putStr(n);s.putU8(i);let c=s.putStr(e);s.putU8(c),s.putU8(0),this._channel.send(s.data())}onData(t,n){return v(this,void 0,void 0,function*(){let e=this._dport2FunctionsMap.get(t);if(e){if(e.has(n))throw new Error("onData("+t+") error: handler already exist.");e.add(n)}else return e=new Set,e.add(n),this._dport2FunctionsMap.set(t,e),this._sendBindDportMsg(t)})}offData(t,n){return v(this,void 0,void 0,function*(){let e=this._dport2FunctionsMap.get(t);if(!e||e.size<=0)throw new Error("offData("+t+") error: dport not exist.");if(!n)return this._dport2FunctionsMap.delete(t),this._sendUnbindDportMsg(t);if(!e.delete(n))throw new Error("offData("+t+") error: handler not exist.");if(e.size===0)return this._dport2FunctionsMap.delete(t),this._sendUnbindDportMsg(t)})}_runHandler(t){return v(this,void 0,void 0,function*(){let n;try{n=yield P(t)}catch(d){return}let e=M.Bnrtc2Buffer.from(n),s=e.pullU8(),i=e.pullU8(),c=e.pullStr(i),h=e.pullU8(),p=e.pullStr(h);if(s===0){let d=this._dport2FunctionsMap.get(c);if(d)for(let o of d)o({address:p,dport:c,data:e.data()})}else if(s===1){let d=e.pullU32(),o=e.pullU8(),u=this._msg2TaskMap.tryGet(d);u&&(o===0?u.resolve():u.reject(o))}})}_sendBindDportMsg(t){return v(this,void 0,void 0,function*(){let n=M.Bnrtc2Buffer.create(0),e=this._getMessageId(),s=this._msg2TaskMap.forceGet(e);n.putU32(e);let i=n.putStr(t);return n.putU8(i),n.putU8(1),this.port(n.data()),s.promise})}_sendUnbindDportMsg(t){return v(this,void 0,void 0,function*(){let n=M.Bnrtc2Buffer.create(0),e=this._getMessageId(),s=this._msg2TaskMap.forceGet(e);n.putU32(e);let i=n.putStr(t);return n.putU8(i),n.putU8(2),this.port(n.data()),s.promise})}_close(t,n){return this._dport2FunctionsMap.clear(),this._msg2TaskMap.forEach(e=>{e.reject(1)}),this._msg2TaskMap.clear(),this._api.disconnectChannel(this._channel,t,n),!0}};b.Bnrtc2Client=y});var T=B(l=>{"use strict";var g=l&&l.__awaiter||function(r,t,n,e){function s(i){return i instanceof n?i:new n(function(c){c(i)})}return new(n||(n=Promise))(function(i,c){function h(o){try{d(e.next(o))}catch(u){c(u)}}function p(o){try{d(e.throw(o))}catch(u){c(u)}}function d(o){o.done?i(o.value):s(o.value).then(h,p)}d((e=e.apply(r,t||[])).next())})};Object.defineProperty(l,"__esModule",{value:!0});l.bnrtc2Controller=l.Bnrtc2Controller=void 0;var w=require("@bfchain/bnrtc2-client-api"),S=class{constructor(t=w.DEFAULT_BASE_API_HOSTNAME,n=w.DEFAULT_BASE_API_PORT){this._api=new w.Bnrtc2Api(t,n)}bindAddress(t){return g(this,void 0,void 0,function*(){return this._api.bindAddress(t)})}unbindAddress(t){return g(this,void 0,void 0,function*(){return this._api.unbindAddress(t)})}isOnline(t){return g(this,void 0,void 0,function*(){return this._api.isOnline(t)})}addPeers(t){return g(this,void 0,void 0,function*(){return this._api.addPeers(t)})}deletePeers(t){return g(this,void 0,void 0,function*(){return this._api.delPeers(t)})}getPeers(){return g(this,void 0,void 0,function*(){return this._api.getPeers()})}};l.Bnrtc2Controller=S;l.bnrtc2Controller=new S});"use strict";var k=exports&&exports.__createBinding||(Object.create?function(r,t,n,e){e===void 0&&(e=n),Object.defineProperty(r,e,{enumerable:!0,get:function(){return t[n]}})}:function(r,t,n,e){e===void 0&&(e=n),r[e]=t[n]}),C=exports&&exports.__exportStar||function(r,t){for(var n in r)n!=="default"&&!Object.prototype.hasOwnProperty.call(t,n)&&k(t,r,n)};Object.defineProperty(exports,"__esModule",{value:!0});exports.bnrtc2Global=void 0;require("@bfchain/bnrtc2-client-typings");var q=require("@bfchain/bnrtc2-client-api");Object.defineProperty(exports,"bnrtc2Global",{enumerable:!0,get:function(){return q.bnrtc2Global}});C(U(),exports);C(T(),exports);
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.bnrtc2Global = void 0;
require("@bfchain/bnrtc2-client-typings");
var bnrtc2_client_api_1 = require("@bfchain/bnrtc2-client-api");
Object.defineProperty(exports, "bnrtc2Global", { enumerable: true, get: function () { return bnrtc2_client_api_1.bnrtc2Global; } });
__exportStar(require("./bnrtc2Client"), exports);
__exportStar(require("./bnrtc2Controller"), exports);

7

package.json
{
"name": "@bfchain/bnrtc2-client",
"version": "0.0.1-alpha.19",
"version": "0.0.1-alpha.21",
"main": "./build/index.js",

@@ -8,4 +8,5 @@ "types": "./build/index.d.ts",

"dependencies": {
"@bfchain/bnrtc2-client-typings": "^0.0.1-alpha.19",
"@bfchain/bnrtc2-client-api": "^0.0.1-alpha.19",
"@bfchain/bnrtc2-buffer": "^0.0.1-alpha.21",
"@bfchain/bnrtc2-client-typings": "^0.0.1-alpha.21",
"@bfchain/bnrtc2-client-api": "^0.0.1-alpha.21",
"@bfcs/util-evt": "^0.0.1-alpha.2"

@@ -12,0 +13,0 @@ },

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