cgserver 10.4.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,10 @@ class RpcMsg extends IWebSocket_1.BaseMsg {
21
21
  * 目的分组下的某个具体对象id
22
22
  */
23
23
  to_id = "";
24
+ /**
25
+ * 监听的对象,比如,发送给push服务器的,监听了10086的服务器listem="10086",listem,也可以理解为子group
26
+ */
27
+ listen = "";
24
28
  /**
25
29
  * 消息携带的数据
26
30
  */
@@ -13,6 +13,7 @@ class IRpcClientWebSocket extends IClientWebSocket_1.IClientWebSocket {
13
13
  _id = "";
14
14
  //超时时间
15
15
  _timeout = 3000;
16
+ _listens = {};
16
17
  _genId(pre = "") {
17
18
  return pre + "_" + Core_1.core.getUuid();
18
19
  }
@@ -60,6 +61,61 @@ class IRpcClientWebSocket extends IClientWebSocket_1.IClientWebSocket {
60
61
  super.send(msg);
61
62
  });
62
63
  }
64
+ receive_init(req_msg) {
65
+ if (req_msg.__rpcid) {
66
+ req_msg.__return = true;
67
+ }
68
+ if (!req_msg.from_group) {
69
+ let ret_msg = this.toRetMsg(req_msg, req_msg.data, { id: 10004, des: "初始化消息必须带有identity" });
70
+ this.send(ret_msg);
71
+ return;
72
+ }
73
+ this._group = req_msg.from_group;
74
+ this._id = req_msg.from_id;
75
+ let ret_msg = this.toRetMsg(req_msg, null);
76
+ this.send(ret_msg);
77
+ }
78
+ receive_listen(req_msg) {
79
+ if (req_msg.__rpcid) {
80
+ req_msg.__return = true;
81
+ }
82
+ let data = req_msg.data;
83
+ if (!data || !Core_1.core.isArray(data)) {
84
+ let ret_msg = this.toRetMsg(req_msg, req_msg.data, { id: 10005, des: "listen data not correct must be string[]" });
85
+ this.send(ret_msg);
86
+ return;
87
+ }
88
+ for (let i = 0; i < data.length; i++) {
89
+ let listen = data[i];
90
+ if (!listen) {
91
+ continue;
92
+ }
93
+ this._listens[listen] = true;
94
+ }
95
+ let ret_msg = this.toRetMsg(req_msg, null);
96
+ this.send(ret_msg);
97
+ }
98
+ receive_unlisten(req_msg) {
99
+ if (req_msg.__rpcid) {
100
+ req_msg.__return = true;
101
+ }
102
+ let data = req_msg.data;
103
+ if (!data || !Core_1.core.isArray(data)) {
104
+ let ret_msg = this.toRetMsg(req_msg, req_msg.data, { id: 10005, des: "listen data not correct must be string[]" });
105
+ this.send(ret_msg);
106
+ return;
107
+ }
108
+ for (let i = 0; i < data.length; i++) {
109
+ let listen = data[i];
110
+ if (!listen) {
111
+ continue;
112
+ }
113
+ this._listens[listen] = undefined;
114
+ delete this._listens[listen];
115
+ }
116
+ let ret_msg = this.toRetMsg(req_msg, null);
117
+ this.send(ret_msg);
118
+ }
63
119
  receive_other_all(msg) {
64
120
  Log_1.gLog.error({ des: "no handle", msg });
65
121
  }
@@ -19,12 +19,25 @@ class CgMqServerWebsocket extends IRpcServerWebSocket_1.IRpcServerWebSocket {
19
19
  let jsonData = await this.callRemote(msg);
20
20
  return jsonData;
21
21
  }
22
+ async listen(data) {
23
+ let msg = this.getNewMsg("listen");
24
+ msg.data = data;
25
+ let jsonData = await this.callRemote(msg);
26
+ return jsonData;
27
+ }
28
+ async unlisten(data) {
29
+ let msg = this.getNewMsg("unlisten");
30
+ msg.data = data;
31
+ let jsonData = await this.callRemote(msg);
32
+ return jsonData;
33
+ }
22
34
  //把消息发送给rpc服务器,目的是调用远程函数
23
- async push(to_group, data, to_id = "") {
35
+ async push(to_group, data, to_id = "", listen = "") {
24
36
  let msg = this.getNewMsg("msg");
25
37
  msg.to_group = to_group;
26
38
  msg.to_id = to_id;
27
39
  msg.data = data;
40
+ msg.listen = listen;
28
41
  let ret_rpcmsg = await this.callRemote(msg);
29
42
  return ret_rpcmsg;
30
43
  }
@@ -18,6 +18,10 @@ export declare class RpcMsg extends BaseMsg {
18
18
  * 目的分组下的某个具体对象id
19
19
  */
20
20
  to_id: string;
21
+ /**
22
+ * 监听的对象,比如,发送给push服务器的,监听了10086的服务器listem="10086",listem,也可以理解为子group
23
+ */
24
+ listen: string;
21
25
  /**
22
26
  * 消息携带的数据
23
27
  */
@@ -7,6 +7,9 @@ export declare class IRpcClientWebSocket extends IClientWebSocket implements IRp
7
7
  protected _group: string;
8
8
  protected _id: string;
9
9
  protected _timeout: number;
10
+ protected _listens: {
11
+ [key: string]: boolean;
12
+ };
10
13
  protected _genId(pre?: string): string;
11
14
  getNewMsg(cmd: string, errcode?: {
12
15
  id: number;
@@ -17,6 +20,9 @@ export declare class IRpcClientWebSocket extends IClientWebSocket implements IRp
17
20
  des: string;
18
21
  }): RpcMsg;
19
22
  callRemote(msg: RpcMsg): Promise<unknown>;
23
+ receive_init(req_msg: RpcMsg): void;
24
+ receive_listen(req_msg: RpcMsg): void;
25
+ receive_unlisten(req_msg: RpcMsg): void;
20
26
  receive_other_all(msg: RpcMsg): void;
21
27
  protected _onMessage(msg: RpcMsg): Promise<void>;
22
28
  }
@@ -5,7 +5,9 @@ declare class CgMqServerWebsocket extends IRpcServerWebSocket {
5
5
  constructor(cgmq: CgMq);
6
6
  onOpen(e?: any): void;
7
7
  init(): Promise<RpcMsg>;
8
- push(to_group: string, data: any, to_id?: string): Promise<RpcMsg>;
8
+ listen(data: string[]): Promise<RpcMsg>;
9
+ unlisten(data: string[]): Promise<RpcMsg>;
10
+ push(to_group: string, data: any, to_id?: string, listen?: string): Promise<RpcMsg>;
9
11
  receive_msg(req_msg: RpcMsg): Promise<void>;
10
12
  }
11
13
  export declare class RpcConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "10.4.0",
3
+ "version": "11.0.0",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",