123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import Stomp from "stompjs";
- import store from '../src/store/index'
- var projectconfig = 'ws://192.168.10.14:8082/gyee-websocket'
- let number = 0;
- export const datainit = initialize;
- function initialize(topic) {
- let adpClient = null;
- var url = projectconfig;
-
-
- adpClient = Stomp.client(url);
- adpClient.debug = null;
- adpClient.connect({topic:topic}, adpClient2 => connectCallBackSubscribe(adpClient), error => reconnect(error, adpClient));
- }
- function reconnect(error, adpClient) {
-
- number++;
- adpClient.connected = false;
- clearTimeout(setTimeout(initialize('/topic/popup'), 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);
- }
|