123456789101112131415161718192021222324252627282930313233343536373839 |
- import Stomp from "stompjs";
- import store from '../src/store/index'
- var projectconfig = 'ws://192.168.10.22:8082/gyee-websocket'
- // ============================一般使用的变量============================
- let number = 0;
- export const datainit = initialize;
- // ============================ 大函数体 ============================
- function initialize() {
- let adpClient = null;
- var url = projectconfig;
- adpClient = Stomp.client(url);
- adpClient.debug = null;
- adpClient.connect({}, adpClient => connectCallBackSubscribe(adpClient), error => reconnect(error, adpClient));
- }
- // 断线重连
- function reconnect(error, adpClient) {
- //连接失败时再次调用函数
- number++;
- adpClient.connected = false;
- clearTimeout(setTimeout(initialize(), 1000 * 5));
- debugX("DataAdapter reconnect:" + number + " 次");
- return;
- }
- // ============================ 订阅函数体 ============================
- function connectCallBackSubscribe(adpClient) {
- number = 0;
- adpClient.connected = true;
- adpClient.subscribe('topic/popup', stompMessage => reflexWindturbineBasicInformation(stompMessage));
- }
- // ============================ 解析函数体 ============================
- function reflexWindturbineBasicInformation(stompMessage) {
- var newdata = JSON.parse(stompMessage.body);
- store.dispatch('getupdate', newdata);
- console.log(newdata)
- }
- // ============================ 其他 ============================
- function debugX(text) {
- console.log(text);
- }
|