在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):Tinder/Scarlet开源软件地址(OpenSource Url):https://github.com/Tinder/Scarlet开源编程语言(OpenSource Language):Kotlin 88.1%开源软件介绍(OpenSource Introduction):ScarletA Retrofit inspired WebSocket client for Kotlin, Java, and Android. UpdateWe are working on a new version of Scarlet that supports other persistent connection protocols: ServerSentEvent, Socket IO, STOMP, and MQTT. It can be found on the TutorialUsageIn this example, we read the realtime Bitcoin price from Gdax WebSocket Feed. For more information, please check out the demo app. Declare a WebSocket client using an interface: interface GdaxService {
@Receive
fun observeWebSocketEvent(): Flowable<WebSocket.Event>
@Send
fun sendSubscribe(subscribe: Subscribe)
@Receive
fun observeTicker(): Flowable<Ticker>
} Use Scarlet to create an implementation: val scarletInstance = Scarlet.Builder()
.webSocketFactory(okHttpClient.newWebSocketFactory("wss://ws-feed.gdax.com"))
.addMessageAdapterFactory(MoshiMessageAdapter.Factory())
.addStreamAdapterFactory(RxJava2StreamAdapterFactory())
.build()
val gdaxService = scarletInstance.create<GdaxService>() Send a val BITCOIN_TICKER_SUBSCRIBE_MESSAGE = Subscribe(
productIds = listOf("BTC-USD"),
channels = listOf("ticker")
)
gdaxService.observeWebSocketEvent()
.filter { it is WebSocket.Event.OnConnectionOpened<*> }
.subscribe({
gdaxService.sendSubscribe(BITCOIN_TICKER_SUBSCRIBE_MESSAGE)
})
gdaxService.observeTicker()
.subscribe({ ticker ->
Log.d("Bitcoin price is ${ticker.price} at ${ticker.time}")
}) AndroidScarlet is driven by a StateMachine. TODO DownloadScarlet is available via Maven Central. Snapshots of the development version are available in Sonatype's Maven:<dependency>
<groupId>com.tinder.scarlet</groupId>
<artifactId>scarlet</artifactId>
<version>0.1.12</version>
</dependency> Gradle:implementation 'com.tinder.scarlet:scarlet:0.1.12' Plug-in Roadmap
Copyright
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论