cgserver 8.9.14 → 8.9.16

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.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ 8.9.16
2
+ 1、ws暴露当时请求的req
3
+ 8.9.15
4
+ 1、暴露mongo的objectid
1
5
  8.9.14
2
6
  1、字节操作能力
3
7
  8.9.13
@@ -26,6 +26,9 @@ class MongoBaseService {
26
26
  let id = await MongoManager_1.GMongoMgr.getAutoIds(this._table);
27
27
  return id;
28
28
  }
29
+ toObjectId(id) {
30
+ return MongoManager_1.GMongoMgr.toObjectId(id);
31
+ }
29
32
  /**
30
33
  * 没有id(非_id)的表不能使用该函数
31
34
  * @param id
@@ -133,7 +133,7 @@ class MongoManager {
133
133
  if (Core_1.core.isString(where._id) && where._id.length == 24) {
134
134
  let _id = where._id;
135
135
  try {
136
- where._id = new mongo.ObjectId(_id);
136
+ where._id = this.toObjectId(_id);
137
137
  }
138
138
  catch (e) {
139
139
  where._id = _id;
@@ -141,6 +141,9 @@ class MongoManager {
141
141
  }
142
142
  return where;
143
143
  }
144
+ toObjectId(id) {
145
+ return new mongo.ObjectId(id);
146
+ }
144
147
  /**
145
148
  * 获取单条消息
146
149
  * @param collection
@@ -149,13 +149,13 @@ class ISocketServer {
149
149
  }
150
150
  Log_1.GLog.info((new Date()) + ' Connection accepted.');
151
151
  let server_name = this._getServerNameByCookies(req.cookies);
152
- this.createWebSocketObjectByProtocol(server_name, conn);
152
+ this.createWebSocketObjectByProtocol(server_name, conn, req);
153
153
  }
154
154
  catch (e) {
155
155
  Log_1.GLog.info(' protocol reject');
156
156
  }
157
157
  }
158
- createWebSocketObjectByProtocol(server_name, _ws) {
158
+ createWebSocketObjectByProtocol(server_name, _ws, req) {
159
159
  server_name = server_name || "default";
160
160
  let cls = this._name_vs_class[server_name];
161
161
  if (!cls) {
@@ -164,7 +164,7 @@ class ISocketServer {
164
164
  }
165
165
  let ws_server = (new cls(this));
166
166
  this.addClient(ws_server);
167
- ws_server.onConnect(_ws);
167
+ ws_server.onConnect(_ws, req);
168
168
  return ws_server;
169
169
  }
170
170
  _getServerNameByCookies(cookies) {
@@ -43,6 +43,7 @@ class IWebSocket {
43
43
  return this._tipKey;
44
44
  }
45
45
  _ws = null;
46
+ _req = null;
46
47
  _protoType = IProtoFilter_1.EProtoType.Json;
47
48
  _protoFilter = null;
48
49
  _protoPath = "";
@@ -78,8 +79,9 @@ class IWebSocket {
78
79
  let msg = this.getNewMsg("heartbeat");
79
80
  this.send(msg);
80
81
  }
81
- onConnect(_ws) {
82
+ onConnect(_ws, _req) {
82
83
  this._ws = _ws;
84
+ this._req = _req;
83
85
  if (!this._protoFilter) {
84
86
  this._protoFilter = ProtoFactory_1.GProtoFactory.createFilter(this._protoType);
85
87
  this._protoFilter.init(this._protoPath);
@@ -12,6 +12,7 @@ export declare class MongoBaseService<T> {
12
12
  new (): T;
13
13
  });
14
14
  getNextId(key?: string): Promise<number>;
15
+ toObjectId(id: string): mongo.BSON.ObjectId;
15
16
  /**
16
17
  * 没有id(非_id)的表不能使用该函数
17
18
  * @param id
@@ -7,7 +7,7 @@ export declare class MongoConfig {
7
7
  database: string;
8
8
  }
9
9
  export declare class MongoBaseModel {
10
- _id: any;
10
+ _id: mongo.ObjectId;
11
11
  }
12
12
  export declare class MrResult {
13
13
  /**
@@ -59,6 +59,7 @@ export declare class MongoManager {
59
59
  */
60
60
  getAutoIds(key: string): Promise<number>;
61
61
  protected _convertWhere(where?: any): any;
62
+ toObjectId(id: string): mongo.BSON.ObjectId;
62
63
  /**
63
64
  * 获取单条消息
64
65
  * @param collection
@@ -30,7 +30,7 @@ export declare class ISocketServer {
30
30
  onClose(connection: ws.connection, reason: number, desc: string): void;
31
31
  onListenning(): void;
32
32
  onRequest(req: ws.request): void;
33
- createWebSocketObjectByProtocol(server_name: string, _ws: ws.connection): IClientWebSocket;
33
+ createWebSocketObjectByProtocol(server_name: string, _ws: ws.connection, req: ws.request): IClientWebSocket;
34
34
  protected _getServerNameByCookies(cookies: any): string;
35
35
  /**
36
36
  * 广播消息
@@ -27,6 +27,7 @@ export declare class IWebSocket {
27
27
  protected _tipKey: string;
28
28
  get tipKey(): string;
29
29
  protected _ws: ws.connection;
30
+ protected _req: ws.request;
30
31
  protected _protoType: EProtoType;
31
32
  protected _protoFilter: IProtoFilter;
32
33
  protected _protoPath: string;
@@ -40,7 +41,7 @@ export declare class IWebSocket {
40
41
  }): BaseMsg | any;
41
42
  receive_heartbeat(jsonData: any): void;
42
43
  send_heartbeat(): void;
43
- onConnect(_ws: ws.connection): void;
44
+ onConnect(_ws: ws.connection, _req: ws.request): void;
44
45
  onMessage(message: ws.Message): void;
45
46
  protected _onDecode(message: ws.Message, ...params: any[]): any;
46
47
  protected _onEncode(data: any, ...params: any[]): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "8.9.14",
3
+ "version": "8.9.16",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",