import { useRtcStore } from '/@/store/modules/rtc';

// 所有socket业务事件集中点

export function initSocketEvent(socket: SocketIOClient.Socket): void {
  if (socket) {
    socket.on('connect', () => {
      const rtcStore = useRtcStore();
      const params = {
        userId: rtcStore.userId,
        roomId: rtcStore.roomId,
        role: rtcStore.role || 'leader',
        avatar: rtcStore.avatar,
        nickname: rtcStore.nickname,
        isClient: false,
      };
      socket.emit('join', params);
    });
  } else {
    throw new Error('socket没有初始化！');
  }
}
