All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.jellyfin.sdk.api.sockets.SubscriptionExtensions.kt Maven / Gradle / Ivy

There is a newer version: 1.5.5
Show newest version
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))




© 2015 - 2024 Weber Informatics LLC | Privacy Policy