@azteam/express 1.2.497 → 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"));
@@ -17,7 +18,6 @@ var _http = _interopRequireWildcard(require("http"));
17
18
  var _lodash = _interopRequireDefault(require("lodash"));
18
19
  var _methodOverride = _interopRequireDefault(require("method-override"));
19
20
  var _morgan = _interopRequireDefault(require("morgan"));
20
- var _pako = _interopRequireDefault(require("pako"));
21
21
  var _path = _interopRequireDefault(require("path"));
22
22
  var _psl = _interopRequireDefault(require("psl"));
23
23
  var _socket = require("socket.io");
@@ -49,9 +49,6 @@ var RES_TYPE = {
49
49
  OBJECT: 'OBJECT',
50
50
  DOCS: 'DOCS'
51
51
  };
52
- function compressJson(message) {
53
- return _pako["default"].deflate(JSON.stringify(message));
54
- }
55
52
  var Server = /*#__PURE__*/function () {
56
53
  function Server() {
57
54
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -447,13 +444,17 @@ var Server = /*#__PURE__*/function () {
447
444
  var httpServer = (0, _http.createServer)();
448
445
  var app = this.createExpressApp();
449
446
  httpServer.on('request', app);
450
- var io = new _socket.Server(httpServer);
447
+ var io = new _socket.Server(httpServer, {
448
+ cors: {
449
+ origin: '*'
450
+ }
451
+ });
451
452
  httpServer.listen(port);
452
453
  httpServer.on('listening', 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
  });
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+ var _pako = _interopRequireDefault(require("pako"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
7
9
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
11
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
@@ -24,7 +26,7 @@ var SocketEvent = /*#__PURE__*/function () {
24
26
  while (Object.getPrototypeOf(child.__proto__)) {
25
27
  var data = Object.getOwnPropertyNames(Object.getPrototypeOf(child));
26
28
  data.map(function (methodName) {
27
- var matches = methodName.match(/^(schedule|listen)/);
29
+ var matches = methodName.match(/^(listen|static)/);
28
30
  if (matches) {
29
31
  result.push({
30
32
  type: matches[0],
@@ -38,6 +40,11 @@ var SocketEvent = /*#__PURE__*/function () {
38
40
  }
39
41
  return result;
40
42
  }
43
+ }], [{
44
+ key: "compressJson",
45
+ value: function compressJson(message) {
46
+ return _pako["default"].deflate(JSON.stringify(message));
47
+ }
41
48
  }]);
42
49
  return SocketEvent;
43
50
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.497",
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';
@@ -11,7 +12,6 @@ import http, {createServer} from 'http';
11
12
  import _ from 'lodash';
12
13
  import methodOverride from 'method-override';
13
14
  import morgan from 'morgan';
14
- import pako from 'pako';
15
15
  import path from 'path';
16
16
  import psl from 'psl';
17
17
  import {Server as SocketIO} from 'socket.io';
@@ -25,10 +25,6 @@ const RES_TYPE = {
25
25
  DOCS: 'DOCS',
26
26
  };
27
27
 
28
- function compressJson(message) {
29
- return pako.deflate(JSON.stringify(message));
30
- }
31
-
32
28
  class Server {
33
29
  constructor(options = {}, errorCallback = () => {}) {
34
30
  this.options = {
@@ -428,7 +424,11 @@ class Server {
428
424
  const app = this.createExpressApp();
429
425
  httpServer.on('request', app);
430
426
 
431
- const io = new SocketIO(httpServer);
427
+ const io = new SocketIO(httpServer, {
428
+ cors: {
429
+ origin: '*',
430
+ },
431
+ });
432
432
  httpServer.listen(port);
433
433
 
434
434
  httpServer.on('listening', () => {
@@ -436,7 +436,7 @@ class Server {
436
436
  });
437
437
 
438
438
  const listenEventList = [];
439
- const scheduleEventList = [];
439
+ const staticEventList = [];
440
440
  const msg = [];
441
441
 
442
442
  _.map(socketEvents, (data) => {
@@ -449,8 +449,8 @@ class Server {
449
449
  const {name, type} = method;
450
450
  if (type === 'listen') {
451
451
  listenEventList.push(event[name]);
452
- } else if (type === 'schedule') {
453
- scheduleEventList.push(event[name]);
452
+ } else if (type === 'static') {
453
+ staticEventList.push(event[name]);
454
454
  }
455
455
  msg.push({
456
456
  name: eventName,
@@ -463,11 +463,18 @@ class Server {
463
463
 
464
464
  console.table(msg);
465
465
 
466
- _.map(scheduleEventList, (event) => {
466
+ _.map(staticEventList, (event) => {
467
467
  event(io);
468
468
  });
469
469
 
470
470
  io.on('connection', (socket) => {
471
+ socket.emit(
472
+ 'ping',
473
+ SocketEvent.compressJson({
474
+ ts: Date.now(),
475
+ })
476
+ );
477
+
471
478
  _.map(listenEventList, (event) => {
472
479
  event(io, socket);
473
480
  });
@@ -1,3 +1,5 @@
1
+ import pako from 'pako';
2
+
1
3
  class SocketEvent {
2
4
  __getPublicEvents() {
3
5
  let child = this;
@@ -8,7 +10,7 @@ class SocketEvent {
8
10
  const data = Object.getOwnPropertyNames(Object.getPrototypeOf(child));
9
11
 
10
12
  data.map(function (methodName) {
11
- const matches = methodName.match(/^(schedule|listen)/);
13
+ const matches = methodName.match(/^(listen|static)/);
12
14
  if (matches) {
13
15
  result.push({
14
16
  type: matches[0],
@@ -22,6 +24,10 @@ class SocketEvent {
22
24
  }
23
25
  return result;
24
26
  }
27
+
28
+ static compressJson(message) {
29
+ return pako.deflate(JSON.stringify(message));
30
+ }
25
31
  }
26
32
 
27
33
  export default SocketEvent;