Commit 5a690f5e authored by 毛线's avatar 毛线

对接im

parent 217bc14b
......@@ -154,7 +154,6 @@ export default {
params,
}).then(({ data }) => {
console.log('退出游戏页面')
this.$router.replace('/device')
})
},
},
......
......@@ -15,6 +15,10 @@ export default {
meta: [
{ charset: 'utf-8' },
// { name: 'viewport', content: 'width=device-width, initial-scale=1' },
{
'http-equiv': 'Content-Security-Policy',
content: 'upgrade-insecure-requests',
},
{ hid: 'description', name: 'description', content: process.env.project_description || '' }
],
link: [
......@@ -100,10 +104,10 @@ export default {
}
},
server: {
https: {
key: fs.readFileSync(path.resolve(__dirname, 'configs/certificate/localhost.key')),
cert: fs.readFileSync(path.resolve(__dirname, 'configs/certificate/localhost.crt'))
}
// https: {
// key: fs.readFileSync(path.resolve(__dirname, 'configs/certificate/localhost.key')),
// cert: fs.readFileSync(path.resolve(__dirname, 'configs/certificate/localhost.crt'))
// }
},
// axios: {
// // baseURL,
......
......@@ -22,13 +22,15 @@ export default {
Footer,
},
data() {
return {}
return {
imLoginStatus: false,
}
},
computed: {
...mapState([
'relist',
'userInfo',
'token',
'imToken',
]),
},
watch: {
......@@ -36,7 +38,9 @@ export default {
this.$router.replace(`/login`)
},
userInfo() {
this.init().im()
if (!this.imLoginStatus) {
this.init().im()
}
},
},
mounted() {
......@@ -52,55 +56,62 @@ export default {
init() {
return {
im: () => {
const { userInfo, token, } = this
const { userInfo, imToken, } = this
const { id } = userInfo
this.network().getOpenimInfo().then(({ data }) => {
console.log('data', data)
const config = {
userID: id, // 用户ID
token: token, // 用户token
token: imToken, // 用户token
url: data.imWsServer, // jssdk server ws地址
platformID: 5, // 平台号
}
console.log('config', config)
openIM.login(config).then(res => {
this.loginStatus = true
this.imLoginStatus = true
console.log('login suc...', res)
// me.startListenIM()
this.init().startListenIM()
// if(me.initUserId) {
// me.handleNewConversation(me.initUserId)
// }
}).catch(err => {
this.loginStatus = false
this.imLoginStatus = false
this.$message.error('login to openIM failed')
console.log('login failed...', err)
})
})
// const config = {
// userID: openIMConfig.openImId, // 用户ID
// token: openIMConfig.openImToken, // 用户token
// url: openIMConfig.wsUrl, // jssdk server ws地址
// platformID: openIMConfig.platformID, // 平台号
// }
// openIM.login(config).then(res => {
// this.loginStatus = true
// console.log('login suc...', res)
// // me.startListenIM()
// // if(me.initUserId) {
// // me.handleNewConversation(me.initUserId)
// // }
// }).catch(err => {
// this.loginStatus = false
// this.$message.error('login to openIM failed')
// console.log('login failed...', err)
// })
},
startListenIM: () => {
openIM.on(CbEvents.ONRECVNEWMESSAGE, (data) => {
const msg = JSON.parse(data.data)
const content = JSON.parse(msg.content)
// console.log('receive message', msg, content)
if (msg.sendID !== 'openIMAdmin') { // 非系统消息
return
}
this.handler().newMessageCome(msg)
})
openIM.on(CbEvents.ONCONNECTFAILED, (data) => {
console.log('connection failed', data)
// 连接失败...
})
openIM.on(CbEvents.ONCONNECTSUCCESS, (data) => {
console.log('connection success', data)
// 连接成功...
})
openIM.on(CbEvents.ONCONNECTING, (data) => {
console.log('connection establishing', data)
// 连接中...
})
openIM.on(CbEvents.ONKICKEDOFFLINE, (data) => {
console.log('connection kick offline', data)
// 被踢下线...
})
openIM.on(CbEvents.ONUSERTOKENEXPIRED, (data) => {
console.log('connection expired', data)
// token过期...
})
},
}
},
......@@ -113,6 +124,7 @@ export default {
method: 'get',
}).then(({ data }) => {
if (!data) {
this.$router.replace('/device')
return
}
const { id } = data
......@@ -131,6 +143,65 @@ export default {
method: 'get',
})
},
quitGame: () => {
const { id } = this.$route.params
const params = {
deviceId: id,
}
this.$request({
url: '/api/app/device/quitDevice',
method: 'get',
params,
}).then(({ data }) => {
})
},
}
},
handler() {
return {
newMessageCome: (msg) => {
const content = JSON.parse(msg.content)
const { eventCode, data: message, } = content
console.log('newMessageCome', content)
switch (eventCode) {
case 10008: // Credit-in success
case 10006: // Credit-out success
console.log('message', message)
Message({
type: 'success',
message,
})
break
case 10005: // 退出设备失败
Message({
type: 'error',
message,
})
break
case 10003: // 需要更细设备列表
this.GetDeviceList()
break
case 10000:
this.GetBaseInfo()
break
case 10022: // 返回设备列表
console.log('返回设备列表')
break
case 10004: // 退出设备成功
case 10015: // 后台提出游戏
this.$router.replace('/device')
break
case 10002: // 即将超出最大未操作时长,60秒后将踢出游戏
Message({
type: 'error',
message,
})
break
case 10001: // 超出最大未操作时长,踢出游戏
this.network().quitGame()
break
}
},
}
},
},
......
......@@ -174,16 +174,13 @@ export default {
}
},
methods: {
...mapActions([
'GetBaseInfo',
]),
...mapMutations([
'SetDevice',
]),
init() {
return {
play: () => {
const url = this.device.videoMainNumber
const url = this.device?.videoMainNumber
const webrtc = `webrtc://eslotstreaming.com${url}`
console.log('device', { ...this.device })
this.$refs.webrtc.initVideo(webrtc)
......@@ -282,10 +279,6 @@ export default {
method: 'get',
params,
}).then(({ data }) => {
this.GetBaseInfo()
setTimeout(() => {
this.GetBaseInfo()
}, 3000)
})
this.creditInShow = false
},
......@@ -299,10 +292,6 @@ export default {
method: 'get',
params,
}).then(({ data }) => {
this.GetBaseInfo()
setTimeout(() => {
this.GetBaseInfo()
}, 3000)
})
},
jackpotList: () => {
......
......@@ -20,7 +20,7 @@ import {
SET_CONFIG,
} from '@/store/mutation-types'
import { treeData } from '@/utils/tool'
import { getToken, removeToken, setUserData } from '@/utils/auth' // 验权
import { getToken, getImToken, removeToken, setUserData } from '@/utils/auth' // 验权
export const state = () => ({
relist: false, // 重新登录
......@@ -33,6 +33,7 @@ export const state = () => ({
deviceList: [], // 设备列表
device: {}, // 当前设备
token: getToken(),
imToken: getImToken(),
zoom: 1, // 当前屏幕缩放比例
innerWidth: window.innerWidth,
innerHeight: window.innerHeight,
......
......@@ -8,6 +8,10 @@ export function getToken() {
return Cookies.get(TokenKey)
}
export function getImToken() {
return Cookies.get(OpenImToken)
}
export function setToken(token) {
return Cookies.set(TokenKey, token)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment