Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

zero-remote

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zero-remote - npm Package Compare versions

Comparing version
1.1.2
to
1.1.3
+1
-0
demo1.ts

@@ -14,2 +14,3 @@

this.getReceiver<T2>("fuck").getPid(async () => {
throw "fuck"
this.a++

@@ -16,0 +17,0 @@ return this.a

@@ -25,4 +25,9 @@ import { ICSMessage, ISCMessage, ZeroRemoteClient } from "."

})
// sender.tt("sss").then((a)=>{
// console.log(a)
// }).catch((b)=>{
// console.log(b)
// })
}, 500)
}, 2000)

@@ -45,2 +45,3 @@ "use strict";

this.getReceiver("fuck").getPid(() => __awaiter(this, void 0, void 0, function* () {
throw "fuck";
this.a++;

@@ -47,0 +48,0 @@ return this.a;

@@ -22,3 +22,8 @@ "use strict";

});
// sender.tt("sss").then((a)=>{
// console.log(a)
// }).catch((b)=>{
// console.log(b)
// })
}, 500);
}, 2000);
+65
-31

@@ -18,3 +18,7 @@ "use strict";

this.server = server;
this.isClear = false;
}
clear() {
this.isClear = true;
}
start() {

@@ -116,5 +120,5 @@ }

send: (body) => {
let value = pack.stringify(body);
if (value != null) {
if (socket.readyState < 2) {
if (socket.readyState < 2) {
let value = pack.stringify(body);
if (value != null) {
socket.send(value, (err) => {

@@ -128,7 +132,7 @@ if (err) {

else {
console.warn("ZeroServer: socket close");
console.warn("ZeroServer: can't stringify for Json");
}
}
else {
console.warn("ZeroServer: can't stringify for Json");
console.log("ZeroServer: socket close");
}

@@ -177,7 +181,9 @@ }

body.data[key] = (...cbArgs) => {
this.channel.send({
code: ReportCode.CALLBACK,
callbackIndex: element,
args: cbArgs
});
if (!this.isClear) {
this.channel.send({
code: ReportCode.CALLBACK,
ci: element,
args: cbArgs
});
}
};

@@ -190,7 +196,9 @@ }

back = (isError, data) => {
this.channel.send({
code: ReportCode.CALLBACK,
callbackIndex: body.index,
args: [isError, data]
});
if (!this.isClear) {
this.channel.send({
code: ReportCode.CALLBACK,
ci: body.index,
args: [isError, data]
});
}
};

@@ -213,4 +221,4 @@ }

back(true, valueThen);
}).catch(() => {
back(false);
}).catch((error) => {
back(false, error);
});

@@ -225,7 +233,17 @@ }

if (back != null) {
back(false);
back(false, error);
}
}
}
else {
if (back != null) {
back(false, "这个接口没有实现");
}
}
}
else {
if (back != null) {
back(false, "这个路由没有实现");
}
}
}

@@ -297,3 +315,3 @@ getReceiver(route) {

this.callbackPool = {};
this.callbackIndex = 0;
this.ci = 0;
this.pingIndex = 0;

@@ -345,2 +363,3 @@ this._mask = false;

reject(value);
this.emit("error", value);
}

@@ -370,9 +389,9 @@ });

if (typeof element == "function") {
this.callbackIndex++;
delete this.callbackPool[this.callbackIndex - this.callBackMaxIndex];
this.callbackPool[this.callbackIndex] = element;
this.ci++;
delete this.callbackPool[this.ci - this.callBackMaxIndex];
this.callbackPool[this.ci] = element;
if (cbs == null) {
cbs = {};
}
cbs[key] = this.callbackIndex;
cbs[key] = this.ci;
}

@@ -383,6 +402,6 @@ }

if (callback != null) {
this.callbackIndex++;
delete this.callbackPool[this.callbackIndex - this.callBackMaxIndex];
index = this.callbackIndex;
this.callbackPool[this.callbackIndex] = callback;
this.ci++;
delete this.callbackPool[this.ci - this.callBackMaxIndex];
index = this.ci;
this.callbackPool[this.ci] = callback;
}

@@ -406,3 +425,4 @@ this.ws.send(this.pack.stringify({ route: route, key: key, data: data, cbs: cbs, index: index }));

if (this.relinkCount < this.relinkMaxCount) {
setTimeout(() => {
this.relinkTimeOut = setTimeout(() => {
this.relinkTimeOut == null;
this.relinkCount++;

@@ -437,7 +457,7 @@ this.link();

else if (obj.code == ReportCode.CALLBACK) {
if (obj.callbackIndex != null) {
let method = this.callbackPool[obj.callbackIndex];
if (obj.ci != null) {
let method = this.callbackPool[obj.ci];
if (method) {
method.apply(this, obj.args);
delete this.callbackPool[obj.callbackIndex];
delete this.callbackPool[obj.ci];
}

@@ -493,5 +513,15 @@ }

this.emit("suspend");
for (const key in this.callbackPool) {
if (Object.prototype.hasOwnProperty.call(this.callbackPool, key)) {
const element = this.callbackPool[key];
element(false, "网络断开");
delete this.callbackPool[key];
}
}
if (this.isRelink) {
this.reLink();
}
else {
this.emit("stop");
}
};

@@ -505,2 +535,6 @@ this.ws.onmessage = (evt) => {

close() {
if (this.relinkTimeOut) {
clearTimeout(this.relinkTimeOut);
this.relinkTimeOut == null;
}
this.isRelink = false;

@@ -507,0 +541,0 @@ this.isOpen = false;

+95
-34

@@ -22,3 +22,6 @@

abstract receive(body: CSV): void
abstract clear(): void
isClear: boolean = false
clear(): void {
this.isClear = true
}
start(): void {

@@ -78,3 +81,3 @@

error?: string//错误消息
callbackIndex?: number
ci?: number
args?: any[]//回调参数

@@ -146,5 +149,5 @@ }

send: (body) => {
let value = pack.stringify(body)
if (value != null) {
if (socket.readyState < 2) {
if (socket.readyState < 2) {
let value = pack.stringify(body)
if (value != null) {
socket.send(value, (err) => {

@@ -157,6 +160,6 @@ if (err) {

} else {
console.warn("ZeroServer: socket close")
console.warn("ZeroServer: can't stringify for Json")
}
} else {
console.warn("ZeroServer: can't stringify for Json")
console.log("ZeroServer: socket close")
}

@@ -190,3 +193,3 @@ }

*/
export abstract class GameVisitor extends Visitor<ICSMessage, ISCMessage> {
export class GameVisitor extends Visitor<ICSMessage, ISCMessage> {
// protected routerPool: { [key: string]: ZeroDispatcher } = {}

@@ -204,7 +207,9 @@ protected routerPool: { [key: string]: { [key: string]: Function } } = {}

body.data[key] = (...cbArgs: any[]) => {
this.channel.send({
code: ReportCode.CALLBACK,
callbackIndex: element,
args: cbArgs
} as any)
if (!this.isClear) {
this.channel.send({
code: ReportCode.CALLBACK,
ci: element,
args: cbArgs
} as any)
}
}

@@ -217,7 +222,9 @@ }

back = (isError: boolean, data?: any) => {
this.channel.send({
code: ReportCode.CALLBACK,
callbackIndex: body.index,
args: [isError, data]
} as any)
if (!this.isClear) {
this.channel.send({
code: ReportCode.CALLBACK,
ci: body.index,
args: [isError, data]
} as any)
}
}

@@ -240,4 +247,4 @@ }

back!(true, valueThen)
}).catch(() => {
back!(false)
}).catch((error) => {
back!(false, error)
})

@@ -250,6 +257,14 @@ } else {

if (back != null) {
back(false)
back(false, error)
}
}
} else {
if (back != null) {
back(false, "这个接口没有实现")
}
}
} else {
if (back != null) {
back(false, "这个路由没有实现")
}
}

@@ -313,10 +328,39 @@ }

export class ZeroRemoteClient extends ZeroDispatcher<{
/**
* 消息阻塞
*/
showMask: []
/**
* 阻塞后收到消息
*/
hideMask: []
/**
* 主动错误
* 用于debug
*/
error: [string?]
/**
* 重连提示
*/
popup: []
/**
* 心跳
*/
heartbeat: []
/**
* 开始连接
*/
linking: []
/**
* 连接完成
*/
linked: []
/**
* 连接中断
*/
suspend: []
/**
* 连接结束
*/
stop: []
}> {

@@ -341,5 +385,6 @@ relinkMaxCount: number = 3

protected callbackPool: { [key: number]: Function } = {}
private callbackIndex: number = 0
private ci: number = 0
private pingIndex: number = 0
private _mask: boolean = false
relinkTimeOut?: NodeJS.Timeout;
public get mask(): boolean {

@@ -389,2 +434,3 @@ return this._mask

reject(value)
this.emit("error", value)
}

@@ -414,9 +460,9 @@ })

if (typeof element == "function") {
this.callbackIndex++
delete this.callbackPool[this.callbackIndex - this.callBackMaxIndex]
this.callbackPool[this.callbackIndex] = element
this.ci++
delete this.callbackPool[this.ci - this.callBackMaxIndex]
this.callbackPool[this.ci] = element
if (cbs == null) {
cbs = {}
}
cbs[key] = this.callbackIndex
cbs[key] = this.ci
}

@@ -427,6 +473,6 @@ }

if (callback != null) {
this.callbackIndex++
delete this.callbackPool[this.callbackIndex - this.callBackMaxIndex]
index = this.callbackIndex
this.callbackPool[this.callbackIndex] = callback
this.ci++
delete this.callbackPool[this.ci - this.callBackMaxIndex]
index = this.ci
this.callbackPool[this.ci] = callback
}

@@ -450,3 +496,4 @@ this.ws.send(this.pack.stringify(

if (this.relinkCount < this.relinkMaxCount) {
setTimeout(() => {
this.relinkTimeOut = setTimeout(() => {
this.relinkTimeOut == null
this.relinkCount++

@@ -477,7 +524,7 @@ this.link()

} else if (obj.code == ReportCode.CALLBACK) {
if (obj.callbackIndex != null) {
let method = this.callbackPool[obj.callbackIndex]
if (obj.ci != null) {
let method = this.callbackPool[obj.ci]
if (method) {
method.apply(this, obj.args);
delete this.callbackPool[obj.callbackIndex]
delete this.callbackPool[obj.ci]
}

@@ -530,4 +577,13 @@ }

this.emit("suspend")
for (const key in this.callbackPool) {
if (Object.prototype.hasOwnProperty.call(this.callbackPool, key)) {
const element = this.callbackPool[key];
element(false, "网络断开")
delete this.callbackPool[key]
}
}
if (this.isRelink) {
this.reLink()
} else {
this.emit("stop")
}

@@ -542,2 +598,7 @@ }

close() {
if (this.relinkTimeOut) {
clearTimeout(this.relinkTimeOut)
this.relinkTimeOut == null
}
this.isRelink = false

@@ -544,0 +605,0 @@ this.isOpen = false

{
"name": "zero-remote",
"version": "1.1.2",
"version": "1.1.3",
"description": "常连接网络",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

+1
-0

@@ -6,2 +6,3 @@ // interface T1 {

getPid: () => number;
tt: (message: string) => void;
}