zero-remote
Advanced tools
+10
-5
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.GameVisitor = exports.Visitor = void 0; | ||
| const zero_mvc_1 = require("zero-mvc"); | ||
| const zero_dispatcher_1 = __importDefault(require("zero-dispatcher")); | ||
| const IZeroRomeote_1 = require("./IZeroRomeote"); | ||
@@ -34,3 +37,3 @@ /** | ||
| */ | ||
| class ZeroRemote extends zero_mvc_1.ZeroDispatcher { | ||
| class ZeroRemote extends zero_dispatcher_1.default { | ||
| constructor(ws, callback, pack = IZeroRomeote_1.jsonPack) { | ||
@@ -169,3 +172,3 @@ super(); | ||
| if (back != null) { | ||
| back(false, "这个接口没有实现"); | ||
| back(false, route + " " + key + "这个接口没有实现"); | ||
| } | ||
@@ -183,3 +186,3 @@ } | ||
| get: (target, p, receiver) => { | ||
| return (data) => { | ||
| return (callback) => { | ||
| let router = this.routerPool[route]; | ||
@@ -190,3 +193,5 @@ if (router == null) { | ||
| } | ||
| router[p] = data; | ||
| router[p] = (data) => { | ||
| return callback(...data); | ||
| }; | ||
| }; | ||
@@ -193,0 +198,0 @@ } |
@@ -8,3 +8,3 @@ "use strict"; | ||
| const ws_1 = __importDefault(require("ws")); | ||
| const zero_mvc_1 = require("zero-mvc"); | ||
| const zero_dispatcher_1 = __importDefault(require("zero-dispatcher")); | ||
| const IZeroRomeote_1 = require("./IZeroRomeote"); | ||
@@ -20,3 +20,3 @@ /** | ||
| */ | ||
| class ZeroRemoteClient extends zero_mvc_1.ZeroDispatcher { | ||
| class ZeroRemoteClient extends zero_dispatcher_1.default { | ||
| constructor(url) { | ||
@@ -27,2 +27,3 @@ super(); | ||
| this.relinkTime = 2000; | ||
| this.relinkAddTime = 1000; | ||
| /** | ||
@@ -39,3 +40,3 @@ * 回调函数缓存个数 | ||
| this.relinkCount = 0; | ||
| this.router = new zero_mvc_1.ZeroDispatcher(); | ||
| this.router = new zero_dispatcher_1.default(); | ||
| this.callbackPool = {}; | ||
@@ -83,3 +84,3 @@ this.ci = 0; | ||
| get: (target, p, receiver) => { | ||
| return (data) => { | ||
| return (...data) => { | ||
| return new Promise((resolve, reject) => { | ||
@@ -103,4 +104,4 @@ this.send(route, p, data, (isError, value) => { | ||
| get: (target, p, receiver) => { | ||
| return (data) => { | ||
| this.receive(r, p, data); | ||
| return (callback) => { | ||
| this.receive(r, p, callback); | ||
| }; | ||
@@ -156,5 +157,7 @@ } | ||
| this.link(); | ||
| this.relinkTime += this.relinkAddTime; | ||
| }, this.relinkTime); | ||
| } | ||
| else { | ||
| this.mask = 0; | ||
| this.relinkCount = 0; | ||
@@ -180,2 +183,3 @@ this.emit("popup"); | ||
| this.router.emit(obj.route + "." + obj.key, obj.data); | ||
| this.emit("message", obj.route, obj.key, obj.data); | ||
| } | ||
@@ -241,3 +245,2 @@ } | ||
| this.ws.onclose = () => { | ||
| this.mask = 0; | ||
| this.isOpen = false; | ||
@@ -244,0 +247,0 @@ this.isBusy = false; |
+8
-7
| import WebSocket from "ws" | ||
| import { ZeroDispatcher } from "zero-mvc"; | ||
| import ZeroDispatcher from "zero-dispatcher"; | ||
| import { IChannel, ICSMessage, IPack, ISCMessage, jsonPack, ReportCode, ReturnReceiver, Sender } from "./IZeroRomeote"; | ||
| /** | ||
@@ -11,3 +10,3 @@ * Ginger用户基础 | ||
| */ | ||
| export abstract class Visitor<CSV, SCV> { | ||
| export abstract class Visitor<CSV, SCV> { | ||
| constructor(public channel: IChannel<SCV>, public server: ZeroRemote) { | ||
@@ -160,3 +159,3 @@ } | ||
| if (back != null) { | ||
| back(false, "这个接口没有实现") | ||
| back(false, route + " " + key + "这个接口没有实现") | ||
| } | ||
@@ -173,3 +172,3 @@ } | ||
| get: (target: any, p: string, receiver: any) => { | ||
| return (data: any) => { | ||
| return (callback: any) => { | ||
| let router = this.routerPool[route] | ||
@@ -180,3 +179,5 @@ if (router == null) { | ||
| } | ||
| router[p] = data | ||
| router[p] = (data: any[]) => { | ||
| return callback(...data) | ||
| } | ||
| } | ||
@@ -207,2 +208,2 @@ } | ||
| } | ||
| } | ||
| } |
+1
-1
| { | ||
| "name": "zero-remote", | ||
| "version": "1.2.3", | ||
| "version": "1.2.5", | ||
| "description": "常连接网络", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+13
-9
@@ -1,5 +0,4 @@ | ||
| import WebSocket from "ws"; | ||
| import { ZeroDispatcher } from "zero-mvc"; | ||
| import WebSocket from "ws" | ||
| import ZeroDispatcher from "zero-dispatcher"; | ||
| import { IPack, jsonPack, PromiseSender, Receiver, ISCMessage, ReportCode } from "./IZeroRomeote"; | ||
| /** | ||
@@ -15,3 +14,4 @@ * 错误错误会弹窗 | ||
| export class ZeroRemoteClient extends ZeroDispatcher<{ | ||
| export class ZeroRemoteClient extends ZeroDispatcher<{ | ||
| message: [string, string, any] | ||
| /** | ||
@@ -57,2 +57,3 @@ * 消息阻塞 | ||
| relinkTime: number = 2000; | ||
| relinkAddTime: number = 1000; | ||
| /** | ||
@@ -111,2 +112,3 @@ * 回调函数缓存个数 | ||
| } | ||
| /** | ||
@@ -120,3 +122,3 @@ * 本条结构协议 | ||
| get: (target: any, p: string, receiver: any) => { | ||
| return (data: any) => { | ||
| return (...data: any[]) => { | ||
| return new Promise((resolve: (value: any) => void, reject: (reason?: any) => void) => { | ||
@@ -139,4 +141,4 @@ this.send(route, p, data, (isError: boolean, value: any) => { | ||
| get: (target: any, p: string, receiver: any) => { | ||
| return (data: any) => { | ||
| this.receive(r, p, data); | ||
| return (callback: any) => { | ||
| this.receive(r, p, callback); | ||
| }; | ||
@@ -192,4 +194,6 @@ } | ||
| this.link(); | ||
| this.relinkTime+=this.relinkAddTime | ||
| }, this.relinkTime); | ||
| } else { | ||
| this.mask = 0; | ||
| this.relinkCount = 0; | ||
@@ -213,2 +217,3 @@ this.emit("popup"); | ||
| this.router.emit(obj.route + "." + obj.key, obj.data); | ||
| this.emit("message", obj.route, obj.key, obj.data); | ||
| } | ||
@@ -269,3 +274,2 @@ } else { | ||
| this.ws.onclose = () => { | ||
| this.mask = 0; | ||
| this.isOpen = false; | ||
@@ -303,2 +307,2 @@ this.isBusy = false; | ||
| } | ||
| } | ||
| } |
43972
1.81%1129
1.07%