commonMain.org.jellyfin.sdk.api.sockets.SubscriptionExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jellyfin-api-jvm Show documentation
Show all versions of jellyfin-api-jvm Show documentation
Official Kotlin/Java SDK for Jellyfin. org.jellyfin.sdk:jellyfin-api-jvm
package org.jellyfin.sdk.api.sockets
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import org.jellyfin.sdk.model.api.GeneralCommandMessage
import org.jellyfin.sdk.model.api.GeneralCommandType
import org.jellyfin.sdk.model.api.OutboundWebSocketMessage
import org.jellyfin.sdk.model.api.PlaystateCommand
import org.jellyfin.sdk.model.api.PlaystateMessage
import org.jellyfin.sdk.model.api.SendCommandType
import org.jellyfin.sdk.model.api.SyncPlayCommandMessage
/**
* Subscribe to a specific WebSocket message type.
*/
public inline fun SocketApi.subscribe(): Flow = subscribe(T::class)
/**
* Subscribe to specific [GeneralCommandType] messages.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun SocketApi.subscribeGeneralCommands(
commands: Set = GeneralCommandType.values().toSet(),
): Flow = subscribe()
.filter { message -> message.data?.name in commands }
/**
* Subscribe to a specific [GeneralCommandType] message.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun SocketApi.subscribeGeneralCommand(
command: GeneralCommandType,
): Flow = subscribeGeneralCommands(setOf(command))
/**
* Subscribe to specific [PlaystateCommand] messages.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun SocketApi.subscribePlayStateCommands(
commands: Set = PlaystateCommand.values().toSet(),
): Flow = subscribe()
.filter { message -> message.data?.command in commands }
/**
* Subscribe to a specific [PlaystateCommand] message.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun SocketApi.subscribePlayStateCommand(
command: PlaystateCommand,
): Flow = subscribePlayStateCommands(setOf(command))
/**
* Subscribe to specific [SendCommandType] messages.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun SocketApi.subscribeSyncPlayCommands(
commands: Set = SendCommandType.values().toSet(),
): Flow = subscribe()
.filter { message -> message.data?.command in commands }
/**
* Subscribe to a specific [SendCommandType] message.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun SocketApi.subscribeSyncPlayCommand(
command: SendCommandType,
): Flow = subscribeSyncPlayCommands(setOf(command))