|
@@ -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;
|
|
|
+ }
|
|
|
+}
|