Jelajahi Sumber

连接testtool

HuangKai 3 bulan lalu
induk
melakukan
59736c269a
2 mengubah file dengan 21 tambahan dan 0 penghapusan
  1. 2 0
      src/index.js
  2. 19 0
      src/view/utils/connectTestTool.js

+ 2 - 0
src/index.js

@@ -14,6 +14,7 @@
 // import LocationCard from './view/common/LocationCard';
 import App from './view/App'
 import updateMarkerPos from './view/utils/moveMarker'
+import connectTestTool from './view/utils/connectTestTool'
 
 
 /*
@@ -71,5 +72,6 @@ window.EDITOR_NAME = window.CONFIG.editor_name;
 const ThreeXMAP = {
 	MAP: App,
 	moveMarker: updateMarkerPos,
+	connectTestTool: connectTestTool,
 }
 export { ThreeXMAP }

+ 19 - 0
src/view/utils/connectTestTool.js

@@ -0,0 +1,19 @@
+// import PubSub from 'pubsub-js';
+
+/** * 连接数据 * * 
+ * @param {String} url - 数据地址 * 
+*/
+export default function connectTestTool(url) {
+    return new TestToolSocket(url);
+}
+
+class TestToolSocket {
+	constructor(url){
+		this._socket = new WebSocket(url);
+		this._socket.onmessage = (e) => this.onRecieveMessage(e);
+		this._socket.onclose = (e) => this.onClose(e);
+		this._socket.onerror = (e) => this.onError(e);
+		// this._socket.onopen = (e) => this.onOpen(e);
+		this.close = () => this._socket.close;
+	}
+}