SignalR 即时通信

2019-08-16  本文已影响0人  把我推进深海的你真善良

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

    },

上一篇 下一篇

猜你喜欢

热点阅读