SignalR 即时通信
proxy.on 需要写在 hub.start()前边
initconnect() {
var self = this
const hub = jQuery.hubConnection(self.apiurl)
const proxy = hub.createHubProxy('SignalRServerHub')
proxy.on('getorderinfo', function(message) {
console.log('message', message)
self.playVoice('./static/audio/newmes.mp3')
})
hub.start().done((connection) => {
proxy.invoke('sendloginmsg', { source: this.source, companyID: this.comid, employeeid: this.eid })
}).fail(() => {
console.log('Could not connect')
})
hub.error(function(error) {
console.log('SignalR error: ' + error)
})
hub.connectionSlow(function() {
console.log('We are currently experiencing difficulties with the connection.')
})
hub.disconnected(function() {
console.log('disconnected')
})
return proxy
},