|
@@ -15,6 +15,7 @@ import {
|
|
|
WsAnswerType,
|
|
WsAnswerType,
|
|
|
WsCandidateType,
|
|
WsCandidateType,
|
|
|
WsConnectStatusEnum,
|
|
WsConnectStatusEnum,
|
|
|
|
|
+ WsDisableSpeakingType,
|
|
|
WsGetLiveUserType,
|
|
WsGetLiveUserType,
|
|
|
WsHeartbeatType,
|
|
WsHeartbeatType,
|
|
|
WsJoinType,
|
|
WsJoinType,
|
|
@@ -72,6 +73,7 @@ export const useSrsWs = () => {
|
|
|
const ws = networkStore.wsMap.get(roomId.value);
|
|
const ws = networkStore.wsMap.get(roomId.value);
|
|
|
if (!ws) return;
|
|
if (!ws) return;
|
|
|
ws.send<WsHeartbeatType['data']>({
|
|
ws.send<WsHeartbeatType['data']>({
|
|
|
|
|
+ requestId: getRandomString(8),
|
|
|
msgType: WsMsgTypeEnum.heartbeat,
|
|
msgType: WsMsgTypeEnum.heartbeat,
|
|
|
data: {
|
|
data: {
|
|
|
socket_id: socketId,
|
|
socket_id: socketId,
|
|
@@ -107,6 +109,7 @@ export const useSrsWs = () => {
|
|
|
tid: getRandomString(10),
|
|
tid: getRandomString(10),
|
|
|
});
|
|
});
|
|
|
networkStore.wsMap.get(roomId.value)?.send<WsUpdateJoinInfoType['data']>({
|
|
networkStore.wsMap.get(roomId.value)?.send<WsUpdateJoinInfoType['data']>({
|
|
|
|
|
+ requestId: getRandomString(8),
|
|
|
msgType: WsMsgTypeEnum.updateJoinInfo,
|
|
msgType: WsMsgTypeEnum.updateJoinInfo,
|
|
|
data: {
|
|
data: {
|
|
|
live_room_id: Number(roomId.value),
|
|
live_room_id: Number(roomId.value),
|
|
@@ -142,6 +145,7 @@ export const useSrsWs = () => {
|
|
|
}) {
|
|
}) {
|
|
|
console.log('handleStartLivehandleStartLive', receiver);
|
|
console.log('handleStartLivehandleStartLive', receiver);
|
|
|
networkStore.wsMap.get(roomId.value)?.send<WsStartLiveType['data']>({
|
|
networkStore.wsMap.get(roomId.value)?.send<WsStartLiveType['data']>({
|
|
|
|
|
+ requestId: getRandomString(8),
|
|
|
msgType: WsMsgTypeEnum.startLive,
|
|
msgType: WsMsgTypeEnum.startLive,
|
|
|
data: {
|
|
data: {
|
|
|
cover_img: coverImg!,
|
|
cover_img: coverImg!,
|
|
@@ -165,6 +169,7 @@ export const useSrsWs = () => {
|
|
|
const instance = networkStore.wsMap.get(roomId.value);
|
|
const instance = networkStore.wsMap.get(roomId.value);
|
|
|
if (!instance) return;
|
|
if (!instance) return;
|
|
|
instance.send<WsJoinType['data']>({
|
|
instance.send<WsJoinType['data']>({
|
|
|
|
|
+ requestId: getRandomString(8),
|
|
|
msgType: WsMsgTypeEnum.join,
|
|
msgType: WsMsgTypeEnum.join,
|
|
|
data: {
|
|
data: {
|
|
|
socket_id: mySocketId.value,
|
|
socket_id: mySocketId.value,
|
|
@@ -254,6 +259,7 @@ export const useSrsWs = () => {
|
|
|
if (answer) {
|
|
if (answer) {
|
|
|
await rtc.setLocalDescription(answer);
|
|
await rtc.setLocalDescription(answer);
|
|
|
ws.send<WsAnswerType['data']>({
|
|
ws.send<WsAnswerType['data']>({
|
|
|
|
|
+ requestId: getRandomString(8),
|
|
|
msgType: WsMsgTypeEnum.answer,
|
|
msgType: WsMsgTypeEnum.answer,
|
|
|
data: {
|
|
data: {
|
|
|
live_room_id: Number(roomId.value),
|
|
live_room_id: Number(roomId.value),
|
|
@@ -331,6 +337,7 @@ export const useSrsWs = () => {
|
|
|
ws.socketIo.on(WsMsgTypeEnum.message, (data: WsMessageType) => {
|
|
ws.socketIo.on(WsMsgTypeEnum.message, (data: WsMessageType) => {
|
|
|
prettierReceiveWsMsg(WsMsgTypeEnum.message, data);
|
|
prettierReceiveWsMsg(WsMsgTypeEnum.message, data);
|
|
|
damuList.value.push({
|
|
damuList.value.push({
|
|
|
|
|
+ request_id: data.request_id,
|
|
|
socket_id: data.socket_id,
|
|
socket_id: data.socket_id,
|
|
|
msgType: DanmuMsgTypeEnum.danmu,
|
|
msgType: DanmuMsgTypeEnum.danmu,
|
|
|
msg: data.data.msg,
|
|
msg: data.data.msg,
|
|
@@ -339,6 +346,20 @@ export const useSrsWs = () => {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ // 收到disableSpeaking
|
|
|
|
|
+ ws.socketIo.on(
|
|
|
|
|
+ WsMsgTypeEnum.disableSpeaking,
|
|
|
|
|
+ (data: WsDisableSpeakingType['data']) => {
|
|
|
|
|
+ prettierReceiveWsMsg(WsMsgTypeEnum.disableSpeaking, data);
|
|
|
|
|
+ if (data.disable_expired_at) {
|
|
|
|
|
+ window.$message.error('你已被禁言!');
|
|
|
|
|
+ damuList.value = damuList.value.filter(
|
|
|
|
|
+ (v) => v.request_id !== data.request_id
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
// 用户加入房间完成
|
|
// 用户加入房间完成
|
|
|
ws.socketIo.on(WsMsgTypeEnum.joined, (data: WsJoinType['data']) => {
|
|
ws.socketIo.on(WsMsgTypeEnum.joined, (data: WsJoinType['data']) => {
|
|
|
prettierReceiveWsMsg(WsMsgTypeEnum.joined, data);
|
|
prettierReceiveWsMsg(WsMsgTypeEnum.joined, data);
|
|
@@ -349,6 +370,7 @@ export const useSrsWs = () => {
|
|
|
appStore.setLiveRoomInfo(data.live_room);
|
|
appStore.setLiveRoomInfo(data.live_room);
|
|
|
anchorInfo.value = data.anchor_info;
|
|
anchorInfo.value = data.anchor_info;
|
|
|
ws.send<WsGetLiveUserType['data']>({
|
|
ws.send<WsGetLiveUserType['data']>({
|
|
|
|
|
+ requestId: getRandomString(8),
|
|
|
msgType: WsMsgTypeEnum.getLiveUser,
|
|
msgType: WsMsgTypeEnum.getLiveUser,
|
|
|
data: {
|
|
data: {
|
|
|
live_room_id: data.live_room.id!,
|
|
live_room_id: data.live_room.id!,
|
|
@@ -363,7 +385,9 @@ export const useSrsWs = () => {
|
|
|
id: data.join_socket_id,
|
|
id: data.join_socket_id,
|
|
|
userInfo: data.join_user_info,
|
|
userInfo: data.join_user_info,
|
|
|
});
|
|
});
|
|
|
|
|
+ const requestId = getRandomString(8);
|
|
|
const danmu: IDanmu = {
|
|
const danmu: IDanmu = {
|
|
|
|
|
+ request_id: requestId,
|
|
|
msgType: DanmuMsgTypeEnum.otherJoin,
|
|
msgType: DanmuMsgTypeEnum.otherJoin,
|
|
|
socket_id: data.join_socket_id,
|
|
socket_id: data.join_socket_id,
|
|
|
userInfo: data.join_user_info,
|
|
userInfo: data.join_user_info,
|
|
@@ -372,6 +396,7 @@ export const useSrsWs = () => {
|
|
|
};
|
|
};
|
|
|
damuList.value.push(danmu);
|
|
damuList.value.push(danmu);
|
|
|
ws.send<WsGetLiveUserType['data']>({
|
|
ws.send<WsGetLiveUserType['data']>({
|
|
|
|
|
+ requestId,
|
|
|
msgType: WsMsgTypeEnum.getLiveUser,
|
|
msgType: WsMsgTypeEnum.getLiveUser,
|
|
|
data: {
|
|
data: {
|
|
|
live_room_id: data.live_room.id!,
|
|
live_room_id: data.live_room.id!,
|
|
@@ -444,6 +469,7 @@ export const useSrsWs = () => {
|
|
|
damuList.value.push({
|
|
damuList.value.push({
|
|
|
socket_id: data.socket_id,
|
|
socket_id: data.socket_id,
|
|
|
msgType: DanmuMsgTypeEnum.userLeaved,
|
|
msgType: DanmuMsgTypeEnum.userLeaved,
|
|
|
|
|
+ msgIsFile: false,
|
|
|
userInfo: data.user_info,
|
|
userInfo: data.user_info,
|
|
|
msg: '',
|
|
msg: '',
|
|
|
});
|
|
});
|