import { MsgCall } from "tsrpc";
import { server } from "..";
import { MsgReqSend } from "../shared/protocols/MsgReqSend";

/**
 * 发送消息处理器
 */
export default async function (call: MsgCall<MsgReqSend>) {
    // 验证消息内容
    if (call.msg.content.length === 0) {
        call.conn.sendMsg('ResSend', {
            time: new Date()
        });
        return;
    }

    // 返回成功响应
    let time = new Date();
    call.conn.sendMsg('ResSend', {
        time: time
    });

    // 广播消息
    server.broadcastMsg('Chat', {
        content: call.msg.content,
        time: time
    });
}