import { v1 as uuidV1 } from 'uuid'; export type MsgType = 'text' | 'audio' | 'video' | 'image' |'cmd' | 'attachment'; export type ChatType = 'chat' | 'room' | 'group' | 'push'; export class MsgBase { // 消息编号 id: string = uuidV1(); // 消息发送方,如果是从多个人发出,则用 , 逗号分隔 from: string; // 消息接收方/目标方,如果是发送给多个人,则用 , 逗号分隔 to: string; // 聊天室类型 type: ChatType; // 扩展消息 ext: Record; /** 校验当前消息是否有效 */ isValid() { if (!this.from || !this.to) { return false; } return true; } static createMsg(baseMsg: Partial): MsgBase { const msg = new MsgBase(); Object.assign(msg, baseMsg); return msg; } } export type GroupOption = { }