@azteam/express 1.2.498 → 1.2.499

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/lib/Server.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+ var _SocketEvent = _interopRequireDefault(require("backend/express-server/src/controller/SocketEvent"));
7
8
  var _bodyParser = _interopRequireDefault(require("body-parser"));
8
9
  var _compression = _interopRequireDefault(require("compression"));
9
10
  var _cookieParser = _interopRequireDefault(require("cookie-parser"));
@@ -453,7 +454,7 @@ var Server = /*#__PURE__*/function () {
453
454
  console.log('listening', "ServerIO start at http://localhost:".concat(httpServer.address().port));
454
455
  });
455
456
  var listenEventList = [];
456
- var scheduleEventList = [];
457
+ var staticEventList = [];
457
458
  var msg = [];
458
459
  _lodash["default"].map(socketEvents, function (data) {
459
460
  var event = data.event;
@@ -465,8 +466,8 @@ var Server = /*#__PURE__*/function () {
465
466
  type = method.type;
466
467
  if (type === 'listen') {
467
468
  listenEventList.push(event[name]);
468
- } else if (type === 'schedule') {
469
- scheduleEventList.push(event[name]);
469
+ } else if (type === 'static') {
470
+ staticEventList.push(event[name]);
470
471
  }
471
472
  msg.push({
472
473
  name: eventName,
@@ -477,10 +478,13 @@ var Server = /*#__PURE__*/function () {
477
478
  });
478
479
  });
479
480
  console.table(msg);
480
- _lodash["default"].map(scheduleEventList, function (event) {
481
+ _lodash["default"].map(staticEventList, function (event) {
481
482
  event(io);
482
483
  });
483
484
  io.on('connection', function (socket) {
485
+ socket.emit('ping', _SocketEvent["default"].compressJson({
486
+ ts: Date.now()
487
+ }));
484
488
  _lodash["default"].map(listenEventList, function (event) {
485
489
  event(io, socket);
486
490
  });
@@ -26,7 +26,7 @@ var SocketEvent = /*#__PURE__*/function () {
26
26
  while (Object.getPrototypeOf(child.__proto__)) {
27
27
  var data = Object.getOwnPropertyNames(Object.getPrototypeOf(child));
28
28
  data.map(function (methodName) {
29
- var matches = methodName.match(/^(schedule|listen)/);
29
+ var matches = methodName.match(/^(listen|static)/);
30
30
  if (matches) {
31
31
  result.push({
32
32
  type: matches[0],
@@ -40,7 +40,7 @@ var SocketEvent = /*#__PURE__*/function () {
40
40
  }
41
41
  return result;
42
42
  }
43
- }, {
43
+ }], [{
44
44
  key: "compressJson",
45
45
  value: function compressJson(message) {
46
46
  return _pako["default"].deflate(JSON.stringify(message));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.498",
3
+ "version": "1.2.499",
4
4
  "license": "MIT",
5
5
  "author": "toda <sp.azsolution.net@gmail.com>",
6
6
  "main": "./lib/index.js",
package/src/Server.js CHANGED
@@ -1,3 +1,4 @@
1
+ import SocketEvent from 'backend/express-server/src/controller/SocketEvent';
1
2
  import bodyParser from 'body-parser';
2
3
  import compression from 'compression';
3
4
  import cookieParser from 'cookie-parser';
@@ -435,7 +436,7 @@ class Server {
435
436
  });
436
437
 
437
438
  const listenEventList = [];
438
- const scheduleEventList = [];
439
+ const staticEventList = [];
439
440
  const msg = [];
440
441
 
441
442
  _.map(socketEvents, (data) => {
@@ -448,8 +449,8 @@ class Server {
448
449
  const {name, type} = method;
449
450
  if (type === 'listen') {
450
451
  listenEventList.push(event[name]);
451
- } else if (type === 'schedule') {
452
- scheduleEventList.push(event[name]);
452
+ } else if (type === 'static') {
453
+ staticEventList.push(event[name]);
453
454
  }
454
455
  msg.push({
455
456
  name: eventName,
@@ -462,11 +463,18 @@ class Server {
462
463
 
463
464
  console.table(msg);
464
465
 
465
- _.map(scheduleEventList, (event) => {
466
+ _.map(staticEventList, (event) => {
466
467
  event(io);
467
468
  });
468
469
 
469
470
  io.on('connection', (socket) => {
471
+ socket.emit(
472
+ 'ping',
473
+ SocketEvent.compressJson({
474
+ ts: Date.now(),
475
+ })
476
+ );
477
+
470
478
  _.map(listenEventList, (event) => {
471
479
  event(io, socket);
472
480
  });
@@ -10,7 +10,7 @@ class SocketEvent {
10
10
  const data = Object.getOwnPropertyNames(Object.getPrototypeOf(child));
11
11
 
12
12
  data.map(function (methodName) {
13
- const matches = methodName.match(/^(schedule|listen)/);
13
+ const matches = methodName.match(/^(listen|static)/);
14
14
  if (matches) {
15
15
  result.push({
16
16
  type: matches[0],
@@ -25,7 +25,7 @@ class SocketEvent {
25
25
  return result;
26
26
  }
27
27
 
28
- compressJson(message) {
28
+ static compressJson(message) {
29
29
  return pako.deflate(JSON.stringify(message));
30
30
  }
31
31
  }