Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/core/src/main/misc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ package streamer:
case class StreamStart(userId: UserId, streamerName: String)
object StreamStart extends bus.GivenChannel[StreamStart]("streamStart")

case class StreamersOnline(streamers: Iterable[(UserId, String)])
case class StreamInfo(name: String, lang: String)
case class StreamersOnline(streamers: Map[UserId, StreamInfo])
object StreamersOnline extends bus.GivenChannel[StreamersOnline]("streamersOnline")

package map:
Expand Down
7 changes: 4 additions & 3 deletions modules/socket/src/main/RemoteSocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import play.api.libs.json.*
import java.util.concurrent.atomic.AtomicReference

import lila.common.{ Bus, Lilakka }
import lila.core.misc.streamer.StreamersOnline
import lila.core.misc.streamer.{ StreamersOnline, StreamInfo }
import lila.core.relation.{ Follow, UnFollow }
import lila.core.round.Mlat
import lila.core.security.CloseAccount
Expand Down Expand Up @@ -255,8 +255,9 @@ object RemoteSocket:
def follow(u1: UserId, u2: UserId) = s"rel/follow $u1 $u2"
def unfollow(u1: UserId, u2: UserId) = s"rel/unfollow $u1 $u2"
def apiUserOnline(u: UserId, v: Boolean) = s"api/online $u ${boolean(v)}"
def streamersOnline(streamers: Iterable[(UserId, String)]) =
s"streamers/online ${commas(streamers.map { (u, s) => s"$u:$s" })}"
private given OWrites[StreamInfo] = Json.writes[StreamInfo]
def streamersOnline(streamers: Map[UserId, StreamInfo]) =
s"streamers/online ${Json.stringify(Json.toJson(streamers.mapKeys(_.value)))}"
def respond(reqId: Int, payload: JsObject) = s"req/response $reqId ${Json.stringify(payload)}"
def stop(reqId: Int) = s"lila/stop $reqId"

Expand Down
6 changes: 4 additions & 2 deletions modules/streamer/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ final class Env(
userApi: lila.core.user.UserApi,
subsRepo: lila.core.relation.SubscriptionRepo,
db: lila.db.Db,
net: lila.core.config.NetConfig
net: lila.core.config.NetConfig,
langList: lila.core.i18n.LangList
)(using scheduler: Scheduler)(using Executor, akka.stream.Materializer):

private given ConfigLoader[TwitchConfig] = AutoConfig.loader[TwitchConfig]
Expand Down Expand Up @@ -73,7 +74,8 @@ final class Env(
keyword = config.keyword,
alwaysFeatured = (() => alwaysFeaturedSetting.get()),
twitchApi = twitchApi,
ytApi = ytApi
ytApi = ytApi,
langList = langList
)

lazy val liveStreamApi = wire[LiveStreamApi]
Expand Down
30 changes: 17 additions & 13 deletions modules/streamer/src/main/Streaming.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ final private class Streaming(
keyword: Stream.Keyword,
alwaysFeatured: () => lila.core.data.UserIds,
twitchApi: TwitchApi,
ytApi: YouTubeApi
ytApi: YouTubeApi,
langList: lila.core.i18n.LangList
)(using Executor, Scheduler):

import Stream.*
Expand Down Expand Up @@ -51,30 +52,33 @@ final private class Streaming(
private val streamStartOnceEvery = scalalib.cache.OnceEvery[UserId](2.hour)

private def publishStreams(streamers: List[Streamer], newStreams: LiveStreams) =
import lila.core.misc.streamer.*
Bus.pub:
lila.core.misc.streamer
.StreamersOnline(newStreams.streams.map(s => (s.streamer.userId, s.streamer.name.value)))
StreamersOnline:
newStreams.streams
.map: s =>
s.streamer.userId ->
StreamInfo(
name = s.streamer.name.value,
lang = ~s.streamer.lastStreamLang.map(langList.nameByLanguage)
)
.toMap
if newStreams != liveStreams then
newStreams.streams
.filterNot { s =>
.filterNot: s =>
liveStreams.has(s.streamer)
}
.foreach { s =>
.foreach: s =>
import s.streamer.userId
if streamStartOnceEvery(userId) then
Bus.pub(lila.core.misc.streamer.StreamStart(userId, s.streamer.name.value))
}
liveStreams = newStreams
streamers.foreach { streamer =>
streamer.twitch.foreach { t =>
streamers.foreach: streamer =>
streamer.twitch.foreach: t =>
if liveStreams.streams.exists(s => s.serviceName == "twitch" && s.is(streamer)) then
lila.mon.tv.streamer.present(s"${t.userId}@twitch").increment()
}
streamer.youTube.foreach { t =>
streamer.youTube.foreach: t =>
if liveStreams.streams.exists(s => s.serviceName == "youTube" && s.is(streamer)) then
lila.mon.tv.streamer.present(s"${t.channelId}@youtube").increment()
}
}

private def dedupStreamers(streams: List[Stream]): List[Stream] =
streams
Expand Down
1 change: 1 addition & 0 deletions ui/@types/lichess/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ type Speed = 'ultraBullet' | 'bullet' | 'blitz' | 'rapid' | 'classical' | 'corre

type Perf = Exclude<VariantKey, 'standard'> | Speed;

type UserId = string;
type Uci = string;
type San = string;
type Ply = number;
Expand Down
5 changes: 4 additions & 1 deletion ui/analyse/css/study/relay/_tour.scss
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,10 @@ $hover-bg: $m-primary_bg--mix-30;
padding: 0.7em 1em;
font-size: 1.1em;
color: $c-font;

gap: 1ch;
i {
color: $c-font-dimmer;
}
&::before {
font-size: 1.3em;
}
Expand Down
9 changes: 5 additions & 4 deletions ui/analyse/src/study/relay/relayCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { MultiRedraw } from '../../interfaces';

export const relayTabs = ['overview', 'boards', 'teams', 'players', 'stats'] as const;
export type RelayTab = (typeof relayTabs)[number];
type StreamInfo = [UserId, { name: string; lang: string }];

export default class RelayCtrl {
log: LogEvent[] = [];
Expand All @@ -26,7 +27,7 @@ export default class RelayCtrl {
teams?: RelayTeams;
players: RelayPlayers;
stats: RelayStats;
streams: [string, string][] = [];
streams: StreamInfo[] = [];
showStreamerMenu = toggle(false);
videoPlayer?: VideoPlayer;

Expand Down Expand Up @@ -74,13 +75,13 @@ export default class RelayCtrl {
this.redraw,
);
const pinnedName = this.isPinnedStreamOngoing() && data.pinned?.name;
if (pinnedName) this.streams.push(['ps', pinnedName]);
if (pinnedName) this.streams.push(['ps', { name: pinnedName, lang: '' }]);
this.chatCtrl.isDisabled = () => this.tourShow();
this.chatCtrl.setChapterId(chapterSelect.get());
this.baseRedraw.add(() => this.chatCtrl.redraw?.());
pubsub.on('socket.in.crowd', d => {
const s = (d.streams as [string, string][]) ?? [];
if (pinnedName) s.unshift(['ps', pinnedName]);
const s = d.streams?.slice() ?? [];
if (pinnedName) s.unshift(['ps', { name: pinnedName, lang: '' }]);
if (this.streams.length === s.length && this.streams.every(([id], i) => id === s[i][0])) return;
this.streams = s;
this.redraw();
Expand Down
7 changes: 5 additions & 2 deletions ui/analyse/src/study/relay/relayView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ export function renderStreamerMenu(relay: RelayCtrl): VNode {
}),
),
},
relay.streams.map(([id, name]) =>
h('a.streamer.text', { attrs: { 'data-icon': licon.Mic, href: makeUrl(id) } }, name),
relay.streams.map(([id, info]) =>
h('a.streamer.text', { attrs: { 'data-icon': licon.Mic, href: makeUrl(id) } }, [
info.name,
info.lang && h('i', ` (${info.lang})`),
]),
),
),
);
Expand Down