mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-06-24 21:25:23 +00:00
Added version code sending.
This commit is contained in:
parent
18b61d549c
commit
33a8d684bf
9 changed files with 68 additions and 10 deletions
|
@ -28,7 +28,8 @@ enum class Opcode(val value: Byte) {
|
|||
VolumeUpdate(7),
|
||||
SetVolume(8),
|
||||
PlaybackError(9),
|
||||
SetSpeed(10)
|
||||
SetSpeed(10),
|
||||
Version(11)
|
||||
}
|
||||
|
||||
const val LENGTH_BYTES = 4
|
||||
|
@ -42,6 +43,10 @@ class FCastSession(outputStream: OutputStream, private val _remoteSocketAddress:
|
|||
private var _outputStream: DataOutputStream? = DataOutputStream(outputStream)
|
||||
val id = UUID.randomUUID()
|
||||
|
||||
fun sendVersion(value: VersionMessage) {
|
||||
send(Opcode.Version, value)
|
||||
}
|
||||
|
||||
fun sendPlaybackError(value: PlaybackErrorMessage) {
|
||||
send(Opcode.PlaybackError, value)
|
||||
}
|
||||
|
@ -190,13 +195,13 @@ class FCastSession(outputStream: OutputStream, private val _remoteSocketAddress:
|
|||
|
||||
try {
|
||||
when (opcode) {
|
||||
Opcode.Play -> _service.onCastPlay(Json.decodeFromString(body!!))
|
||||
Opcode.Play -> _service.onCastPlay(json.decodeFromString(body!!))
|
||||
Opcode.Pause -> _service.onCastPause()
|
||||
Opcode.Resume -> _service.onCastResume()
|
||||
Opcode.Stop -> _service.onCastStop()
|
||||
Opcode.Seek -> _service.onCastSeek(Json.decodeFromString(body!!))
|
||||
Opcode.SetVolume -> _service.onSetVolume(Json.decodeFromString(body!!))
|
||||
Opcode.SetSpeed -> _service.onSetSpeed(Json.decodeFromString(body!!))
|
||||
Opcode.Seek -> _service.onCastSeek(json.decodeFromString(body!!))
|
||||
Opcode.SetVolume -> _service.onSetVolume(json.decodeFromString(body!!))
|
||||
Opcode.SetSpeed -> _service.onSetSpeed(json.decodeFromString(body!!))
|
||||
else -> { }
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
|
@ -206,5 +211,6 @@ class FCastSession(outputStream: OutputStream, private val _remoteSocketAddress:
|
|||
|
||||
companion object {
|
||||
const val TAG = "FCastSession"
|
||||
private val json = Json { ignoreUnknownKeys = true }
|
||||
}
|
||||
}
|
|
@ -60,6 +60,15 @@ class NetworkService : Service() {
|
|||
_scope?.launch(Dispatchers.Main) {
|
||||
Log.i(TAG, "On new session ${session.id}")
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
Log.i(TAG, "Sending version ${session.id}")
|
||||
session.sendVersion(VersionMessage(2))
|
||||
} catch (e: Throwable) {
|
||||
Log.e(TAG, "Failed to send version ${session.id}")
|
||||
}
|
||||
}
|
||||
|
||||
var encounteredError = false
|
||||
while (!_stopped && !encounteredError) {
|
||||
try {
|
||||
|
|
|
@ -44,4 +44,9 @@ data class SetSpeedMessage(
|
|||
@Serializable
|
||||
data class SetVolumeMessage(
|
||||
val volume: Double
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class VersionMessage(
|
||||
val version: Long
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue