Skip to content

Commit

Permalink
feat: implement media sink wants
Browse files Browse the repository at this point in the history
  • Loading branch information
viztea committed Dec 12, 2023
1 parent 1595b95 commit da525d5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions voice/src/main/kotlin/gateway/Command.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public sealed class Command {
composite.encodeSerializableElement(descriptor, 0, OpCode.Serializer, OpCode.Heartbeat)
composite.encodeLongElement(descriptor, 1, value.nonce)
}
is MediaSinkWants -> {
composite.encodeSerializableElement(descriptor, 0, OpCode.Serializer, OpCode.MediaSinkWants)
composite.encodeSerializableElement(descriptor, 1, MediaSinkWants.serializer(), value)
}
is SendSpeaking -> {
composite.encodeSerializableElement(descriptor, 0, OpCode.Serializer, OpCode.Speaking)
composite.encodeSerializableElement(descriptor, 1, SendSpeaking.serializer(), value)
Expand Down Expand Up @@ -72,6 +76,12 @@ public data class SendSpeaking(
val ssrc: UInt
) : Command()

@KordVoice
@Serializable
public data class MediaSinkWants(
val any: Int
) : Command()

@KordVoice
@Serializable
public data class SelectProtocol(
Expand Down
3 changes: 2 additions & 1 deletion voice/src/main/kotlin/gateway/DefaultVoiceGateway.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public data class DefaultVoiceGatewayData(
val sessionId: String,
val client: HttpClient,
val reconnectRetry: Retry,
val isDeaf: Boolean,
val eventFlow: MutableSharedFlow<VoiceEvent>
)

Expand Down Expand Up @@ -196,7 +197,7 @@ public class DefaultVoiceGateway(
val copy = command.copy(data = command.data.copy(address = "ip"))
"Voice Gateway >>> ${Json.encodeToString(Command.SerializationStrategy, copy)}"
}
is Heartbeat, is Resume, is SendSpeaking -> "Voice Gateway >>> $json"
else -> "Voice Gateway >>> $json"
}
}
socket.send(Frame.Text(json))
Expand Down
2 changes: 2 additions & 0 deletions voice/src/main/kotlin/gateway/DefaultVoiceGatewayBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class DefaultVoiceGatewayBuilder(
public var client: HttpClient? = null
public var reconnectRetry: Retry? = null
public var eventFlow: MutableSharedFlow<VoiceEvent> = MutableSharedFlow(extraBufferCapacity = Int.MAX_VALUE)
public var isDeaf: Boolean = false

public fun build(): DefaultVoiceGateway {
val client = client ?: HttpClient(CIO) {
Expand All @@ -37,6 +38,7 @@ public class DefaultVoiceGatewayBuilder(
sessionId,
client,
retry,
isDeaf,
eventFlow
)

Expand Down
3 changes: 2 additions & 1 deletion voice/src/main/kotlin/gateway/OpCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public enum class OpCode(public val code: Int) {
Resume(7),
Hello(8),
Resumed(9),
ClientDisconnect(13);
ClientDisconnect(13),
MediaSinkWants(15);

internal object Serializer : KSerializer<OpCode> {
override val descriptor: SerialDescriptor
Expand Down
1 change: 1 addition & 0 deletions voice/src/main/kotlin/gateway/handler/HandshakeHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class HandshakeHandler(
on<Hello> {
data.reconnectRetry.reset()
send(identify)
send(MediaSinkWants(if (data.isDeaf) 0 else 100))
}
}
}

0 comments on commit da525d5

Please sign in to comment.