- RevueSDK
- LocalParticipant
- publish(message:to:timeout:)
Instance Method
publish(message:to:timeout:)
發送訊息給指定參與者(Room 層訊息管道)
@discardableResult func publish(message: String, to participant: RemoteParticipant, timeout: TimeInterval = 10) async throws -> UInt32Parameters
- message
訊息文字
- participant
接收方 RemoteParticipant
- timeout
等待 delivery receipt 的最長秒數。範圍 5~30 秒,預設 10 秒; 超出範圍不報錯、自動限制:大於 30 用 30,小於 5(含 0、負數)用 5; NaN 沒有大小可比,用預設的 10 秒 (限制由
FriendManager.sendMessage套用)
Return Value
對方裝置 toxcore 回 ACK 時的 messageId
Discussion
和 FriendManager.sendMessage 的差異:
朋友層
sendMessage— 送純字串給好友,觸發RevueDelegate.didReceiveMessageRoom 層
publish(message:to:)— 送 Room 訊息給 Room 內參與者, 觸發RoomDelegate.room(_:participant:didReceiveMessage:)
兩者底層共用 toxcore transport,但在 wire format 和 delegate 路由上完全隔離。
Throws
RoomMessageError.encodingFailed— JSON envelope 編碼失敗(罕見)
RoomMessageError.messageTooLong— envelope 超過 toxcore 1372 bytes 上限
RoomMessageError.transportFailed(underlying:)— 底層 FriendManager 失敗
CancellationError— Revue.destroy() 觸發