RevueSDK · Swift reference Guides

Instance Method

requestMute(_:)

發送靜音請求給此參與者

@discardableResult func requestMute(_ muted: Bool) async throws -> Bool

Parameters

muted

true = 請求靜音, false = 請求取消靜音

Return Value

送達時(對方裝置 toxcore 回 ACK)為 true;送不到時 throw,不回 false

Discussion

這是「通知」而非「強制」:只送給這一位(不是廣播),對方收到 didReceiveMuteRequest callback 後,由對方的 App 決定是否配合(能力層 vs 授權層分離)。

與本地調整收聽音量的差異:

常見組合使用:

// 情境 1:我不想聽 A 說話(只影響自己)
(remoteA?.firstAudioTrack as? RemoteAudioTrack)?.volume = 0

// 情境 2:主持人要求 A 靜音(通知 + 立即本地不播放)
func hostMuteParticipant(_ participant: RemoteParticipant) async throws {
    (participant.firstAudioTrack as? RemoteAudioTrack)?.volume = 0  // 立即:我這邊不播放
    try await participant.requestMute(true)                         // 通知:請對方靜音
}

// 情境 3:只是通知對方(不強制)
try await remoteA?.requestMute(true)

Throws

  • RoomMessageError.encodingFailed — JSON envelope 編碼失敗(罕見)

  • RoomMessageError.messageTooLong — envelope 超過 toxcore 1372 bytes 上限

  • RoomMessageError.transportFailed(underlying:) — 底層 FriendManager 失敗

  • CancellationError — Revue.destroy() 觸發