|
@@ -1,4 +1,11 @@
|
|
|
var server = require("http").createServer();
|
|
|
+const TLSSigAPIv2 = require('tls-sig-api-v2')
|
|
|
+const appids = require('./../config/appid')
|
|
|
+const api = new TLSSigAPIv2.Api(appids.shop.appid, appids.shop.key)
|
|
|
+
|
|
|
+function getSig (userId) {
|
|
|
+ return api.genSig(userId, 86400)
|
|
|
+}
|
|
|
|
|
|
const EVENT = {
|
|
|
someOneInRoom: 'someOneInRoom',
|
|
@@ -39,19 +46,18 @@ module.exports = class WebSocketServer {
|
|
|
const webRoomId = `${roomId}_web`
|
|
|
const clientRoom = userId ? `${userId}` : `${userId}${roomId}`
|
|
|
// 加入客户端与H5单独的通讯房间
|
|
|
+ console.log(user, '新连接')
|
|
|
socket.join(clientRoom, () => {
|
|
|
console.log('join success', clientRoom, user)
|
|
|
})
|
|
|
|
|
|
socket.on(EVENT.clientSyncAction, (data) => {
|
|
|
- console.log('client', clientRoom, data)
|
|
|
socket.broadcast.to(clientRoom).emit(EVENT.clientSyncAction, data)
|
|
|
})
|
|
|
|
|
|
socket.on(EVENT.changeVoiceStatus, data => {
|
|
|
let _roomPerson = this._roomPerson.get(roomId) || []
|
|
|
user.voiceStatus = data.status
|
|
|
- console.log(_roomPerson, '_roomPerson')
|
|
|
_roomPerson.forEach(item => {
|
|
|
if (item.userId === user.userId) {
|
|
|
item.voiceStatus = user.voiceStatus
|
|
@@ -87,6 +93,9 @@ module.exports = class WebSocketServer {
|
|
|
// 只有h5才能加入H5端的房间
|
|
|
if (!isClient) {
|
|
|
let roomsPerson = this._roomPerson.get(roomId) || []
|
|
|
+ if (userId) {
|
|
|
+ user.sig = getSig(userId)
|
|
|
+ }
|
|
|
roomsPerson.push(user)
|
|
|
this._roomPerson.set(roomId, roomsPerson)
|
|
|
}
|
|
@@ -106,7 +115,6 @@ module.exports = class WebSocketServer {
|
|
|
|
|
|
|
|
|
socket.on(EVENT.startCall, () => {
|
|
|
- console.log('startcall', user)
|
|
|
if (!isClient) {
|
|
|
socket.join(webRoomId, () => {
|
|
|
console.log('join webRoom', user)
|
|
@@ -118,7 +126,6 @@ module.exports = class WebSocketServer {
|
|
|
})
|
|
|
|
|
|
socket.on(EVENT.stopCall, () => {
|
|
|
- console.log('stopCall', user)
|
|
|
socket.leave(roomId)
|
|
|
if (role === 'leader') {
|
|
|
socket.broadcast.to(roomId).emit(EVENT.roomClose)
|
|
@@ -141,7 +148,6 @@ module.exports = class WebSocketServer {
|
|
|
})
|
|
|
|
|
|
socket.on("disconnect", (reason) => {
|
|
|
- console.log(reason, 'reason')
|
|
|
socket.leave(roomId)
|
|
|
if (!isClient) {
|
|
|
// if (role === 'leader' && reason !== 'ping timeout') {
|
|
@@ -157,7 +163,6 @@ module.exports = class WebSocketServer {
|
|
|
})
|
|
|
|
|
|
socket.on('reconnect', () => {
|
|
|
- console.log('重连', user)
|
|
|
socket.join(roomId)
|
|
|
if (!isClient) {
|
|
|
let roomsPerson = this._roomPerson.get(roomId) || []
|