push new streams to the homepage, log streaming api errors
This commit is contained in:
parent
000086d9b3
commit
dba35ecedf
|
@ -35,5 +35,7 @@ private[app] final class Renderer extends Actor {
|
|||
|
||||
case lila.puzzle.RenderDaily(puzzle, fen, lastMove) =>
|
||||
sender ! V.puzzle.daily(puzzle, fen, lastMove)
|
||||
|
||||
case lila.tv.StreamsOnAir(streams) => sender ! V.tv.streamsOnAir(streams)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,7 @@
|
|||
}
|
||||
</div>
|
||||
}
|
||||
@streams.map { s =>
|
||||
<a class="stream" href="@s.url"><span data-icon="1"> LIVE!</span> @s.name</a>
|
||||
}
|
||||
<div id="streams_on_air">@tv.streamsOnAir(streams)</div>
|
||||
<div id="timeline" data-href="@routes.Lobby.timeline">
|
||||
@timeline.entries(userTimeline)
|
||||
<div class="links clearfix">
|
||||
|
|
4
app/views/tv/streamsOnAir.scala.html
Normal file
4
app/views/tv/streamsOnAir.scala.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
@(ss: List[lila.tv.StreamOnAir])
|
||||
@ss.map { s =>
|
||||
<a class="stream" href="@s.url"><span data-icon="1"> LIVE!</span> @s.name</a>
|
||||
}
|
|
@ -25,6 +25,7 @@ sealed abstract class RemindDeploy(val key: String)
|
|||
case object RemindDeployPre extends RemindDeploy("deployPre")
|
||||
case object RemindDeployPost extends RemindDeploy("deployPost")
|
||||
case class Deploy(event: RemindDeploy, html: String)
|
||||
case class StreamsOnAir(html: String)
|
||||
|
||||
package map {
|
||||
case class Get(id: String)
|
||||
|
|
|
@ -24,7 +24,7 @@ private[lobby] final class Socket(
|
|||
router: akka.actor.ActorSelection,
|
||||
uidTtl: Duration) extends SocketActor[Member](uidTtl) with Historical[Member] {
|
||||
|
||||
context.system.lilaBus.subscribe(self, 'changeFeaturedGame)
|
||||
context.system.lilaBus.subscribe(self, 'changeFeaturedGame, 'streams)
|
||||
|
||||
def receiveSpecific = {
|
||||
|
||||
|
@ -67,6 +67,8 @@ private[lobby] final class Socket(
|
|||
}
|
||||
|
||||
case HookIds(ids) => notifyVersion("hook_list", ids)
|
||||
|
||||
case lila.hub.actorApi.StreamsOnAir(html) => notifyAll(makeMessage("streams", html))
|
||||
}
|
||||
|
||||
private def playerUrl(fullId: String) =
|
||||
|
|
|
@ -24,6 +24,7 @@ final class Env(
|
|||
private lazy val streaming = new Streaming(
|
||||
system = system,
|
||||
isOnline = isOnline,
|
||||
renderer = hub.actor.renderer,
|
||||
ustreamApiKey = UstreamApiKey)
|
||||
|
||||
def streamsOnAir = streaming.onAir
|
||||
|
|
|
@ -7,6 +7,7 @@ import play.api.libs.ws.WS
|
|||
private final class Streaming(
|
||||
system: ActorSystem,
|
||||
ustreamApiKey: String,
|
||||
renderer: ActorSelection,
|
||||
isOnline: String => Boolean) {
|
||||
|
||||
import Streaming._
|
||||
|
@ -31,17 +32,39 @@ private final class Streaming(
|
|||
val twitch = WS.url("https://api.twitch.tv/kraken/search/streams")
|
||||
.withQueryString("q" -> "lichess.org")
|
||||
.withHeaders("Accept" -> "application/vnd.twitchtv.v2+json")
|
||||
.get().map { _.json.asOpt[Twitch.Result] ?? (_.streamsOnAir take max) }
|
||||
.get().map {
|
||||
_.json.asOpt[Twitch.Result] match {
|
||||
case Some(data) => data.streamsOnAir take max
|
||||
case None =>
|
||||
logger.warn(s"twitch {res.status} {~res.body.lines.toList.headOption}")
|
||||
Nil
|
||||
}
|
||||
}
|
||||
val chesswhiz = isOnline("chesswhiz") ??
|
||||
WS.url(s"http://api.ustream.tv/json/stream/recent/search/title:like:chesswhiz")
|
||||
.withQueryString("key" -> ustreamApiKey)
|
||||
.get().map { _.json.asOpt[Ustream.Result] ?? (_.streamsOnAir take max) }
|
||||
.get().map {
|
||||
_.json.asOpt[Ustream.Result] match {
|
||||
case Some(data) => data.streamsOnAir take max
|
||||
case None =>
|
||||
logger.warn(s"chesswhiz {res.status} {~res.body.lines.toList.headOption}")
|
||||
Nil
|
||||
}
|
||||
}
|
||||
twitch |+| chesswhiz map StreamsOnAir.apply pipeTo self
|
||||
|
||||
case StreamsOnAir(streams) => onAir = streams
|
||||
case event@StreamsOnAir(streams) if onAir != streams =>
|
||||
onAir = streams
|
||||
import makeTimeout.short
|
||||
renderer ? event foreach {
|
||||
case html: play.api.templates.Html =>
|
||||
context.system.lilaBus.publish(lila.hub.actorApi.StreamsOnAir(html.body), 'stream)
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
private def logger = play.api.Logger("tv.streaming")
|
||||
|
||||
actor ! Search
|
||||
}
|
||||
|
||||
|
|
|
@ -2310,6 +2310,9 @@ var storage = {
|
|||
}
|
||||
});
|
||||
},
|
||||
streams: function(html) {
|
||||
$('#streams_on_air').html(html);
|
||||
},
|
||||
hook_add: function(hook) {
|
||||
addHook(hook);
|
||||
drawHooks();
|
||||
|
|
Loading…
Reference in a new issue