You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

3 years ago
  1. package nova.monadic_sfx.util
  2. import monix.bio.Task
  3. import nova.monadic_sfx.AppTypes
  4. import nova.monadic_sfx.implicits._
  5. import sttp.client._
  6. import sttp.client.httpclient.monix.MonixWebSocketHandler
  7. // class WebSocket()(implicit backend: AppTypes.HttpBackend) {
  8. // // val source = for {
  9. // // } yield ()
  10. // }
  11. object WebSocket {
  12. def apply()(implicit backend: AppTypes.HttpBackend) = {
  13. Task
  14. .deferAction(implicit s =>
  15. IOUtils.toIO(
  16. basicRequest.get(uri"").openWebsocketF(MonixWebSocketHandler())
  17. )
  18. )
  19. .flatMap { r =>
  20. val ws = r.result
  21. // val source = Observable.repeatEvalF(ws.receive)
  22. val source2 = ws.observableSource
  23. // ws.send()
  24. val source3 = source2.map {
  25. case Left(value) => ()
  26. case Right(value) => value
  27. }
  28. // ws.send()
  29. // val sink = new Observer[WebSocketFrame] {
  30. // override def onNext(elem: WebSocketFrame): Future[Ack] = ws.send(elem)
  31. // override def onError(ex: Throwable): Unit = ex.printStackTrace()
  32. // override def onComplete(): Unit = ws.close
  33. // }
  34. Task.unit
  35. }
  36. }
  37. }