gis-common 1.2.1 → 2.0.1

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.
Files changed (2) hide show
  1. package/dist/resource.min.js +175 -11
  2. package/package.json +6 -6
@@ -1,13 +1,13 @@
1
1
  (function webpackUniversalModuleDefinition(root, factory) {
2
2
  if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory();
3
+ module.exports = factory(require("mqtt"));
4
4
  else if(typeof define === 'function' && define.amd)
5
- define("Gis", [], factory);
5
+ define("Gis", ["mqtt"], factory);
6
6
  else if(typeof exports === 'object')
7
- exports["Gis"] = factory();
7
+ exports["Gis"] = factory(require("mqtt"));
8
8
  else
9
- root["Gis"] = factory();
10
- })(window, function() {
9
+ root["Gis"] = factory(root["mqtt"]);
10
+ })(window, function(__WEBPACK_EXTERNAL_MODULE__0__) {
11
11
  return /******/ (function(modules) { // webpackBootstrap
12
12
  /******/ // The module cache
13
13
  /******/ var installedModules = {};
@@ -91,11 +91,17 @@ return /******/ (function(modules) { // webpackBootstrap
91
91
  /******/
92
92
  /******/
93
93
  /******/ // Load entry module and return exports
94
- /******/ return __webpack_require__(__webpack_require__.s = 0);
94
+ /******/ return __webpack_require__(__webpack_require__.s = 1);
95
95
  /******/ })
96
96
  /************************************************************************/
97
97
  /******/ ([
98
98
  /* 0 */
99
+ /***/ (function(module, exports) {
100
+
101
+ module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
102
+
103
+ /***/ }),
104
+ /* 1 */
99
105
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
100
106
 
101
107
  "use strict";
@@ -124,6 +130,7 @@ __webpack_require__.d(__webpack_exports__, "CanvasDrawer", function() { return /
124
130
  __webpack_require__.d(__webpack_exports__, "ElQuery", function() { return /* reexport */ core_ElQuery; });
125
131
  __webpack_require__.d(__webpack_exports__, "EventDispatcher", function() { return /* reexport */ core_EventDispatcher; });
126
132
  __webpack_require__.d(__webpack_exports__, "HashMap", function() { return /* reexport */ core_HashMap; });
133
+ __webpack_require__.d(__webpack_exports__, "MqttClient", function() { return /* reexport */ core_MqttClient; });
127
134
  __webpack_require__.d(__webpack_exports__, "WebSocketClient", function() { return /* reexport */ core_WebSocketClient; });
128
135
  __webpack_require__.d(__webpack_exports__, "WebStorage", function() { return /* reexport */ core_WebStorage; });
129
136
 
@@ -2039,27 +2046,184 @@ var HashMap = function () {
2039
2046
  }();
2040
2047
 
2041
2048
  /* harmony default export */ var core_HashMap = (HashMap);
2049
+ // EXTERNAL MODULE: external "mqtt"
2050
+ var external_mqtt_ = __webpack_require__(0);
2051
+
2052
+ // CONCATENATED MODULE: ./src/core/MqttClient.js
2053
+ var MqttClient_createClass = function () { 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, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2054
+
2055
+ function MqttClient_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2056
+
2057
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2058
+
2059
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2060
+
2061
+
2062
+
2063
+
2064
+
2065
+
2066
+
2067
+ var MqttClient_MqttClient = function (_EventDispatcher) {
2068
+ _inherits(MqttClient, _EventDispatcher);
2069
+
2070
+ /**
2071
+ * Creates an instance of MqttClient.
2072
+ * @param {*} config mqtt实例参数
2073
+ */
2074
+ function MqttClient() {
2075
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2076
+
2077
+ MqttClient_classCallCheck(this, MqttClient);
2078
+
2079
+ var _this = _possibleConstructorReturn(this, (MqttClient.__proto__ || Object.getPrototypeOf(MqttClient)).call(this));
2080
+
2081
+ _this.context = CommUtils.extend(MqttClient.defaultContext, config);
2082
+ _this.options = {
2083
+ connectTimeout: _this.context.MQTT_TIMEOUTM,
2084
+ clientId: CommUtils.generateGuid(),
2085
+ username: _this.context.MQTT_USERNAME,
2086
+ password: _this.context.MQTT_PASSWORD,
2087
+ clean: true
2088
+ };
2089
+ _this.client = Object(external_mqtt_["connect"])(_this.context.MQTT_SERVICE, _this.options);
2090
+ _this._onConnect();
2091
+ _this._onMessage();
2092
+ MqttClient.instance = _this;
2093
+ return _this;
2094
+ }
2095
+
2096
+ MqttClient_createClass(MqttClient, [{
2097
+ key: "_onConnect",
2098
+ value: function _onConnect() {
2099
+ var _this2 = this;
2100
+
2101
+ this.client.on("connect", function () {
2102
+ console.log("链接mqtt成功==>" + _this2.context.MQTT_SERVICE);
2103
+ _this2.dispatchEvent({ type: EventTypeConstant.MQTT_CONNECT, message: _this2 });
2104
+ });
2105
+ this.client.on("error", function (err) {
2106
+ console.log("链接mqtt报错", err);
2107
+ _this2.dispatchEvent({ type: EventTypeConstant.MQTT_ERROR, message: _this2 });
2108
+ _this2.client.end();
2109
+ _this2.client.reconnect();
2110
+ });
2111
+ }
2112
+ }, {
2113
+ key: "_onMessage",
2114
+ value: function _onMessage() {
2115
+ var _this3 = this;
2116
+
2117
+ this.client.on("message", function (topic, message) {
2118
+ var dataString = message;
2119
+ var data = "";
2120
+ if (message instanceof Uint8Array) {
2121
+ dataString = message.toString();
2122
+ }
2123
+ try {
2124
+ data = JSON.parse(dataString);
2125
+ } catch (error) {
2126
+ throw new Error(ErrorTypeConstant.JSON_PARSE_ERROR);
2127
+ }
2128
+ _this3.dispatchEvent({
2129
+ type: EventTypeConstant.MQTT_MESSAGE,
2130
+ message: { topic: topic, data: data }
2131
+ });
2132
+ });
2133
+ }
2134
+ }, {
2135
+ key: "sendMsg",
2136
+ value: function sendMsg(topic, msg) {
2137
+ if (!this.client.connected) {
2138
+ console.error("客户端未连接");
2139
+ return;
2140
+ }
2141
+ this.client.publish(topic, msg, { qos: 1, retain: true });
2142
+ }
2143
+ }, {
2144
+ key: "subscribe",
2145
+ value: function subscribe(topic) {
2146
+ this.client.subscribe(topic, { qos: 1 }, function (error, res) {
2147
+ if (error instanceof Error || res.length === 0) {
2148
+ console.error("\u8BA2\u9605\u5931\u8D25==>" + topic, error);
2149
+ } else {
2150
+ console.log("\u8BA2\u9605\u6210\u529F==>" + topic);
2151
+ }
2152
+ });
2153
+ return this;
2154
+ }
2155
+ }, {
2156
+ key: "unsubscribe",
2157
+ value: function unsubscribe(topic) {
2158
+ this.client.unsubscribe(topic, { qos: 1 }, function (error, res) {
2159
+ if (error instanceof Error || res.length === 0) {
2160
+ console.error("\u53D6\u6D88\u8BA2\u9605\u5931\u8D25==>" + topic, error);
2161
+ } else {
2162
+ console.log("\u53D6\u6D88\u8BA2\u9605\u6210\u529F==>" + topic);
2163
+ }
2164
+ });
2165
+ return this;
2166
+ }
2167
+ }, {
2168
+ key: "unconnect",
2169
+ value: function unconnect() {
2170
+ this.client.end();
2171
+ this.client = null;
2172
+ this.dispatchEvent({ type: EventTypeConstant.MQTT_CLOSE, message: null });
2173
+ console.log("断开mqtt成功==>" + this.context.MQTT_SERVICE);
2174
+ }
2175
+ /**
2176
+ * @description 获取并冻结mqtt实例
2177
+ * @static
2178
+ * @param {*} [config={}]
2179
+ * @returns {MqttClient}
2180
+ */
2181
+
2182
+ }], [{
2183
+ key: "getInstance",
2184
+ value: function getInstance() {
2185
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2186
+
2187
+ if (MqttClient.instance) {
2188
+ return Object.freeze(MqttClient.instance);
2189
+ } else {
2190
+ return Object.freeze(new MqttClient(config));
2191
+ }
2192
+ }
2193
+ }]);
2194
+
2195
+ return MqttClient;
2196
+ }(core_EventDispatcher);
2197
+
2198
+ /* harmony default export */ var core_MqttClient = (MqttClient_MqttClient);
2199
+
2200
+ MqttClient_MqttClient.defaultContext = {
2201
+ MQTT_TIMEOUTM: 20000,
2202
+ MQTT_USERNAME: "iRVMS-WEB",
2203
+ MQTT_PASSWORD: "novasky888",
2204
+ MQTT_SERVICE: "ws://" + window.document.domain + ":20007/mqtt"
2205
+ };
2042
2206
  // CONCATENATED MODULE: ./src/core/WebSocketClient.js
2043
2207
  var WebSocketClient_createClass = function () { 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, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2044
2208
 
2045
2209
  function WebSocketClient_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2046
2210
 
2047
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2211
+ function WebSocketClient_possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2048
2212
 
2049
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2213
+ function WebSocketClient_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2050
2214
 
2051
2215
 
2052
2216
 
2053
2217
 
2054
2218
  var WebSocketClient_WebSocketClient = function (_EventDispatcher) {
2055
- _inherits(WebSocketClient, _EventDispatcher);
2219
+ WebSocketClient_inherits(WebSocketClient, _EventDispatcher);
2056
2220
 
2057
2221
  function WebSocketClient() {
2058
2222
  var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "ws://127.0.0.1:10088";
2059
2223
 
2060
2224
  WebSocketClient_classCallCheck(this, WebSocketClient);
2061
2225
 
2062
- var _this = _possibleConstructorReturn(this, (WebSocketClient.__proto__ || Object.getPrototypeOf(WebSocketClient)).call(this));
2226
+ var _this = WebSocketClient_possibleConstructorReturn(this, (WebSocketClient.__proto__ || Object.getPrototypeOf(WebSocketClient)).call(this));
2063
2227
 
2064
2228
  _this.maxCheckTimes = 10;
2065
2229
  _this.url = url;
@@ -2298,7 +2462,7 @@ var WebStorage_WebStorage = function () {
2298
2462
 
2299
2463
 
2300
2464
 
2301
- // export { default as MqttClient } from "./core/MqttClient";
2465
+
2302
2466
 
2303
2467
 
2304
2468
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "gis-common",
3
3
  "description": "gis-common",
4
4
  "main": "dist/resource.min.js",
5
- "version": "1.2.1",
5
+ "version": "2.0.1",
6
6
  "author": "Guo.Yan <luv02@vip.qq.com>",
7
7
  "license": "MIT",
8
8
  "private": false,
@@ -10,9 +10,6 @@
10
10
  "dev": "cross-env NODE_ENV=development webpack-dev-server --hot --port 7000",
11
11
  "build": "cross-env NODE_ENV=production webpack --progress"
12
12
  },
13
- "dependencies": {
14
- "mqtt": "^4.2.8"
15
- },
16
13
  "browserslist": [
17
14
  "> 1%",
18
15
  "last 2 versions",
@@ -24,12 +21,15 @@
24
21
  "babel-loader": "^7.1.2",
25
22
  "babel-preset-env": "^1.6.0",
26
23
  "babel-preset-stage-3": "^6.24.1",
24
+ "clean-webpack-plugin": "^4.0.0-alpha.0",
27
25
  "cross-env": "^5.0.5",
28
26
  "css-loader": "^0.28.7",
29
27
  "uglifyjs-webpack-plugin": "^2.2.0",
30
28
  "webpack": "^4.23.1",
31
29
  "webpack-cli": "^4.9.1",
32
- "webpack-dev-server": "^2.9.1",
33
- "clean-webpack-plugin": "^4.0.0-alpha.0"
30
+ "webpack-dev-server": "^2.9.1"
31
+ },
32
+ "dependencies": {
33
+ "mqtt": "^4.3.7"
34
34
  }
35
35
  }