123456789101112131415161718192021222324252627282930313233343536373839 |
- import Stomp from "stompjs";
- import store from '../src/store/index'
- var projectconfig = 'ws://192.168.10.151: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);
- }
|