134 lines
5.2 KiB
Go
134 lines
5.2 KiB
Go
package models
|
||
|
||
// 统一消息结构(发送方使用)
|
||
type SendMessagePayload struct {
|
||
RequestType string `json:"request_type"` // 消息类型
|
||
TargetClientID string `json:"target_client_id"` // 目标客户端ID
|
||
SenderUserID string `json:"sender_user_id"` // 发送者用户ID
|
||
ReceiverUserID string `json:"receiver_user_id"` // 接收者用户ID
|
||
MessageType int `json:"message_type"` // 消息类型(0-8)
|
||
MessageContent string `json:"message_content"` // 消息内容
|
||
// 通话专用字段
|
||
CallID string `json:"call_id,omitempty"` // 通话唯一ID
|
||
CallStatus string `json:"call_status,omitempty"` // 通话状态:invite/accepted/rejected/ended/candidate
|
||
}
|
||
|
||
// 通过用户ID发送消息的结构
|
||
type SendToUserPayload struct {
|
||
SenderUserID string `json:"sender_user_id"` // 发送者用户ID
|
||
ReceiverUserID string `json:"receiver_user_id"` // 接收者用户ID
|
||
MessageType int `json:"message_type"` // 消息类型(0-8)
|
||
MessageContent string `json:"message_content"` // 消息内容
|
||
// 通话专用字段
|
||
CallID string `json:"call_id,omitempty"` // 通话唯一ID
|
||
CallStatus string `json:"call_status,omitempty"` // 通话状态:invite/accepted/rejected/ended/candidate/offer/answer
|
||
}
|
||
|
||
// 客户端接收消息结构(最终格式)
|
||
type ClientReceivedMessage struct {
|
||
SenderID string `json:"sender_id"` // 发送者连接ID
|
||
ReceiverID string `json:"receiver_id"` // 接收者连接ID
|
||
SenderUserID string `json:"sender_user_id"` // 发送者用户ID
|
||
ReceiverUserID string `json:"receiver_user_id"` // 接收者用户ID
|
||
MessageType int `json:"message_type"` // 消息类型(0-8)
|
||
Content string `json:"content"` // 消息内容
|
||
SendTime string `json:"send_time"` // 发送时间
|
||
|
||
// 通话专用字段
|
||
CallID string `json:"call_id,omitempty"` // 通话唯一ID
|
||
CallStatus string `json:"call_status,omitempty"` // 通话状态:invite/accepted/rejected/ended/candidate/offer/answer
|
||
}
|
||
|
||
// Redis 消息结构
|
||
type RedisMessage struct {
|
||
SenderNodeID string `json:"sender_node_id"` // 发送节点ID
|
||
ClientID string `json:"client_id"` // 目标客户端ID
|
||
Message string `json:"message"` // 消息内容
|
||
}
|
||
|
||
// 用户绑定请求结构
|
||
type BindRequest struct {
|
||
UserID string `json:"user_id"` // 用户ID
|
||
ClientID string `json:"client_id"` // 客户端ID
|
||
}
|
||
|
||
// 通话信令结构
|
||
type CallSignal struct {
|
||
CallStatus string `json:"call_status"` // 动作: invite/accept/reject/end/candidate/offer/answer
|
||
CallType int `json:"call_type"` // 通话类型:6=视频,7=语音
|
||
CallID string `json:"call_id"` // 通话唯一ID
|
||
CallerID string `json:"caller_id"` // 主叫用户ID
|
||
CalleeID string `json:"callee_id"` // 被叫用户ID
|
||
Data string `json:"data"` // 数据(SDP/ICE候选)
|
||
}
|
||
|
||
// WebRTC信令数据结构
|
||
type WebRTCSignalData struct {
|
||
Type string `json:"type"` // offer/answer/candidate
|
||
SDP string `json:"sdp,omitempty"` // SDP数据
|
||
Candidate interface{} `json:"candidate,omitempty"` // ICE候选数据
|
||
SDPMid string `json:"sdpMid,omitempty"` // SDP媒体标识
|
||
SDPMLineIndex int `json:"sdpMLineIndex,omitempty"` // SDP行索引
|
||
}
|
||
|
||
// 通话状态常量
|
||
const (
|
||
CallStatusInvite = "invite" // 发起邀请
|
||
CallStatusAccepted = "accepted" // 接受通话
|
||
CallStatusRejected = "rejected" // 拒绝通话
|
||
CallStatusEnded = "ended" // 结束通话
|
||
CallStatusOffer = "offer" // WebRTC Offer
|
||
CallStatusAnswer = "answer" // WebRTC Answer
|
||
CallStatusCandidate = "candidate" // ICE候选
|
||
CallStatusHangup = "hangup" // 挂断
|
||
CallStatusDisconnected = "disconnected" // 断开连接
|
||
CallStatusTerminated = "terminated" // 终止
|
||
CallStatusNoAnswer = "no-answer" // 无人接听
|
||
CallStatusBusy = "busy" // 忙线
|
||
CallStatusFailed = "failed" // 失败
|
||
CallStatusConnecting = "connecting" // 连接中
|
||
)
|
||
|
||
// 消息类型常量
|
||
const (
|
||
MessageTypeText = 0 // 文本消息
|
||
MessageTypeImage = 1 // 图片消息
|
||
MessageTypeAudio = 2 // 音频消息
|
||
MessageTypeVideo = 3 // 视频消息
|
||
MessageTypePrescription = 4 // 处方消息
|
||
MessageTypeMedicalRecord = 5 // 病例消息
|
||
MessageTypeVideoCall = 6 // 视频通话
|
||
MessageTypeAudioCall = 7 // 语音通话
|
||
MessageTypeFile = 8 // 文件消息
|
||
)
|
||
|
||
// Redis键常量
|
||
const (
|
||
ClientUserKey = "client_user_mapping" // clientid -> userid映射
|
||
UserClientKey = "user_client_mapping" // userid -> clientid列表
|
||
)
|
||
|
||
// 响应结构
|
||
type APIResponse struct {
|
||
Status string `json:"status"`
|
||
Message string `json:"message"`
|
||
Data interface{} `json:"data,omitempty"`
|
||
Error string `json:"error,omitempty"`
|
||
}
|
||
|
||
// 健康检查响应
|
||
type HealthResponse struct {
|
||
Status string `json:"status"`
|
||
Node string `json:"node"`
|
||
Port string `json:"port"`
|
||
Time string `json:"time"`
|
||
}
|
||
|
||
// 绑定响应
|
||
type BindResponse struct {
|
||
Status string `json:"status"`
|
||
Message string `json:"message"`
|
||
UserID string `json:"user_id"`
|
||
ClientID string `json:"client_id"`
|
||
}
|