|
|
@@ -19,6 +19,7 @@ import {
|
|
|
WebSocketClass,
|
|
|
WsConnectStatusEnum,
|
|
|
WsMsgTypeEnum,
|
|
|
+ prettierReceiveWebsocket,
|
|
|
} from '@/network/webSocket';
|
|
|
import { useNetworkStore } from '@/store/network';
|
|
|
import { useUserStore } from '@/store/user';
|
|
|
@@ -392,7 +393,7 @@ export function usePull({
|
|
|
if (!instance?.socketIo) return;
|
|
|
// websocket连接成功
|
|
|
instance.socketIo.on(WsConnectStatusEnum.connect, () => {
|
|
|
- console.log('【websocket】websocket连接成功');
|
|
|
+ prettierReceiveWebsocket(WsConnectStatusEnum.connect);
|
|
|
handleHeartbeat();
|
|
|
if (!instance) return;
|
|
|
instance.status = WsConnectStatusEnum.connect;
|
|
|
@@ -402,7 +403,7 @@ export function usePull({
|
|
|
|
|
|
// websocket连接断开
|
|
|
instance.socketIo.on(WsConnectStatusEnum.disconnect, () => {
|
|
|
- console.log('【websocket】websocket连接断开');
|
|
|
+ prettierReceiveWebsocket(WsConnectStatusEnum.disconnect);
|
|
|
if (!instance) return;
|
|
|
instance.status = WsConnectStatusEnum.disconnect;
|
|
|
instance.update();
|
|
|
@@ -410,8 +411,8 @@ export function usePull({
|
|
|
|
|
|
// 收到offer
|
|
|
instance.socketIo.on(WsMsgTypeEnum.offer, async (data: IOffer) => {
|
|
|
- console.warn(
|
|
|
- '【websocket】收到offer',
|
|
|
+ prettierReceiveWebsocket(
|
|
|
+ WsMsgTypeEnum.offer,
|
|
|
`发送者:${data.data.sender},接收者:${data.data.receiver}`,
|
|
|
data
|
|
|
);
|
|
|
@@ -451,7 +452,11 @@ export function usePull({
|
|
|
|
|
|
// 收到answer
|
|
|
instance.socketIo.on(WsMsgTypeEnum.answer, async (data: IOffer) => {
|
|
|
- console.warn('【websocket】收到answer', data);
|
|
|
+ prettierReceiveWebsocket(
|
|
|
+ WsMsgTypeEnum.answer,
|
|
|
+ `发送者:${data.data.sender},接收者:${data.data.receiver}`,
|
|
|
+ data
|
|
|
+ );
|
|
|
if (isSRS) return;
|
|
|
if (!instance) return;
|
|
|
const rtc = networkStore.getRtcMap(`${roomId.value}___${data.socketId}`);
|
|
|
@@ -468,7 +473,11 @@ export function usePull({
|
|
|
|
|
|
// 收到candidate
|
|
|
instance.socketIo.on(WsMsgTypeEnum.candidate, (data: ICandidate) => {
|
|
|
- console.warn('【websocket】收到candidate', data);
|
|
|
+ prettierReceiveWebsocket(
|
|
|
+ WsMsgTypeEnum.candidate,
|
|
|
+ `发送者:${data.data.sender},接收者:${data.data.receiver}`,
|
|
|
+ data
|
|
|
+ );
|
|
|
if (isSRS) return;
|
|
|
if (!instance) return;
|
|
|
const rtc = networkStore.getRtcMap(`${roomId.value}___${data.socketId}`);
|
|
|
@@ -493,24 +502,24 @@ export function usePull({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 当前所有在线用户
|
|
|
+ // 管理员正在直播
|
|
|
instance.socketIo.on(WsMsgTypeEnum.roomLiveing, (data: IAdminIn) => {
|
|
|
- console.log('【websocket】收到管理员正在直播', data);
|
|
|
+ prettierReceiveWebsocket(WsMsgTypeEnum.roomLiveing, data);
|
|
|
if (isSRS && !isFlv) {
|
|
|
startNewWebRtc({});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 当前所有在线用户
|
|
|
+ // 管理员不在直播
|
|
|
instance.socketIo.on(WsMsgTypeEnum.roomNoLive, (data: IAdminIn) => {
|
|
|
- console.log('【websocket】收到管理员不在直播', data);
|
|
|
+ prettierReceiveWebsocket(WsMsgTypeEnum.roomNoLive, data);
|
|
|
roomNoLive.value = true;
|
|
|
closeRtc();
|
|
|
});
|
|
|
|
|
|
// 当前所有在线用户
|
|
|
instance.socketIo.on(WsMsgTypeEnum.liveUser, (data) => {
|
|
|
- console.log('【websocket】当前所有在线用户', data);
|
|
|
+ prettierReceiveWebsocket(WsMsgTypeEnum.liveUser, data);
|
|
|
if (!instance) return;
|
|
|
liveUserList.value = data.map((item) => ({
|
|
|
avatar: 'red',
|
|
|
@@ -521,7 +530,7 @@ export function usePull({
|
|
|
|
|
|
// 收到用户发送消息
|
|
|
instance.socketIo.on(WsMsgTypeEnum.message, (data) => {
|
|
|
- console.log('【websocket】收到用户发送消息', data);
|
|
|
+ prettierReceiveWebsocket(WsMsgTypeEnum.message, data);
|
|
|
if (!instance) return;
|
|
|
const danmu: IDanmu = {
|
|
|
msgType: DanmuMsgTypeEnum.danmu,
|
|
|
@@ -534,7 +543,7 @@ export function usePull({
|
|
|
|
|
|
// 用户加入房间
|
|
|
instance.socketIo.on(WsMsgTypeEnum.joined, (data) => {
|
|
|
- console.log('【websocket】用户加入房间完成', data);
|
|
|
+ prettierReceiveWebsocket(WsMsgTypeEnum.joined, data);
|
|
|
roomName.value = data.data.roomName;
|
|
|
track.audio = data.data.track_audio;
|
|
|
track.video = data.data.track_video;
|
|
|
@@ -548,7 +557,7 @@ export function usePull({
|
|
|
|
|
|
// 其他用户加入房间
|
|
|
instance.socketIo.on(WsMsgTypeEnum.otherJoin, (data) => {
|
|
|
- console.log('【websocket】其他用户加入房间', data);
|
|
|
+ prettierReceiveWebsocket(WsMsgTypeEnum.otherJoin, data);
|
|
|
const danmu: IDanmu = {
|
|
|
msgType: DanmuMsgTypeEnum.otherJoin,
|
|
|
socketId: data.data.socketId,
|
|
|
@@ -561,16 +570,17 @@ export function usePull({
|
|
|
|
|
|
// 用户离开房间
|
|
|
instance.socketIo.on(WsMsgTypeEnum.leave, (data) => {
|
|
|
- console.log('【websocket】用户离开房间', data);
|
|
|
+ prettierReceiveWebsocket(WsMsgTypeEnum.leave, data);
|
|
|
if (!instance) return;
|
|
|
- instance.socketIo?.emit(WsMsgTypeEnum.leave, {
|
|
|
- roomId: instance.roomId,
|
|
|
+ instance.send({
|
|
|
+ msgType: WsMsgTypeEnum.leave,
|
|
|
+ data: { roomId: instance.roomId },
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// 用户离开房间完成
|
|
|
instance.socketIo.on(WsMsgTypeEnum.leaved, (data) => {
|
|
|
- console.log('【websocket】用户离开房间完成', data);
|
|
|
+ prettierReceiveWebsocket(WsMsgTypeEnum.leaved, data);
|
|
|
if (!instance) return;
|
|
|
const res = liveUserList.value.filter(
|
|
|
(item) => item.socketId !== data.socketId
|