sockjs+stomp的websocket插件
/** * 依赖文件sockjs.js、stomp.js * */ ;!(function (window) { let WS = function () { this.isConnect = false; //保存所有的订阅事件 {Aevent:[pubfun(status,data),pubfun(status,data),...]} this.subEvents = {}; this.stompClient = null; }; WS.prototype = { constructor: WS //设置连接状态 , setConnect(status) { this.isConnect = status; } //建立连接 , connect(url) { let ws = new SockJS(url) , stompClient = Stomp.over(ws); stompClient.connect({}, (data) => { this.setConnect(true); this.connectSuc.apply(this, [stompClient, data]); }, (error) => { this.setConnect(false); this.connectErr.apply(this,[stompClient,error]); }); this