python websocket django vue_关于在vue中如何正确的使用websocket

import { getGrouplist, getSessions, getConferencerooms } from '@/api/service/getData'

// import { docall, hangup, answer, callbacks } from '@/api/call'

import verto, {Verto} from '@/api/verto/verto'

export default {

name: 'Home',

data () {

return {

extn: this.$store.state.data.extn,

password: this.$store.state.data.password,

domain: this.$store.state.data.domain,

local: this.$store.state.data.local,

login: this.$store.state.data.login,

grouplist: [],

curCall: null,

ringing: false,

destination_number: ''

}

},

mounted () {

console.log(this.extn)

getSessions(this.extn, this.password).then(res => {

console.log(res.data.token)

this.token = res.data.token

if (res.data.code === 200) {

console.log('登录成功')

this.loginVerto()

getGrouplist(this.extn).then((res) => {

console.log(res)

this.grouplist = res.data

this.destination_number = res.data[3].extn

}).catch(err => {

console.log(err.message)

})

}

}).catch(err => {

console.log(err.message)

})

getConferencerooms().then(res => {

console.log(res)

})

},

computed: {

},

methods: {

loginVerto () {

if (verto != null) {

if (verto.rpcClient.socketReady() === true) {

verto.logout()

verto.rpcClient.closeSocket()

}

}

verto.connect(this.init())

verto.login()

},

init () {

return {

login: this.extn + '@' + this.domain,

passwd: this.password,

socketUrl: 'ws://192.168.101.20:8081',

tag: 'webcam',

ringFile: './sounds/bell_ring2.wav',

audioParams: {

googAutoGainControl: false,

googNoiseSuppression: false,

googHighpassFilter: false

},

deviceParams: {

useCamera: 'any',

useMic: 'any',

useSpeak: 'any',

onResCheck: null

},

iceServers: false

}

},

onMessage (verto, dialog, msg, data) {

console.log('data', data)

console.log('msg', msg)

console.log('verto', verto)

switch (msg) {

case Verto.enum.message.pvtEvent:

break

case Verto.enum.message.clientReady:

break

case Verto.enum.message.info:

break

case Verto.enum.message.display:

break

default:

break

}

},

onDialogState (d) {

this.curCall = d

if (d.state === Verto.enum.state.ringing) {

this.ringing = true

} else {

this.ringing = false

}

switch (d.state) {

case Verto.enum.state.ringing:

this.display('Call From: ' + d.cidString())

this.hangupClick()

this.answerClick()

break

case Verto.enum.state.trying:

this.display('Calling: ' + d.cidString())

this.docallClick()

break

case Verto.enum.state.early:

case Verto.enum.state.active:

this.display('Talking to: ' + d.cidString())

break

case Verto.enum.state.hangup:

this.display('Call ended with cause: ' + d.cause)

break

case Verto.enum.state.destroy:

this.curCall = null

break

case Verto.enum.state.held:

break

default:

break

}

},

onWSLogin (v, success) {

this.curCall = null

this.ringing = false

if (success) {

this.display('login success')

}

},

onWSClose (v, success) {

var today = new Date()

this.display('Connection Error.
Last Attempt: ' + today)

},

onEvent (v, e) {

console.debug('GOT EVENT', e)

},

display (s) {

console.log(s)

},

hangupClick () {

this.curCall = verto.hangup()

},

answerClick () {

this.curCall.answer()

},

docallClick () {

if (this.curCall) {

return

}

this.curCall = verto.newCall({

destination_number: this.destination_number,

useVideo: false, // 待定

useStereo: false

})

}

}

}

我在.vue文件中使用websocket登录verto模块

但是callbacks返回的onMessage,onDialogState等可能没有完全生效有些bug,是不是我的写法有问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值