Skip to content

Commit

Permalink
Improve watch tab, remove tv feed
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Sep 25, 2023
1 parent 11cf157 commit 695a3a6
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 270 deletions.
4 changes: 2 additions & 2 deletions lib/src/model/tv/live_tv_channels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import 'featured_player.dart';

part 'live_tv_channels.g.dart';

typedef TvChannels = IMap<TvChannel, TvGameSnapshot>;
typedef LiveTvChannelsState = IMap<TvChannel, TvGameSnapshot>;

@riverpod
class LiveTvChannels extends _$LiveTvChannels {
StreamSubscription<SocketEvent>? _socketSubscription;

@override
Future<TvChannels> build() async {
Future<LiveTvChannelsState> build() async {
ref.onDispose(() {
_socketSubscription?.cancel();
_socket.close();
Expand Down
81 changes: 0 additions & 81 deletions lib/src/model/tv/tv_event.dart

This file was deleted.

32 changes: 0 additions & 32 deletions lib/src/model/tv/tv_repository.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'dart:convert';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:logging/logging.dart';
import 'package:result_extensions/result_extensions.dart';
import 'package:lichess_mobile/src/utils/json.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:deep_pick/deep_pick.dart';
import 'package:dartchess/dartchess.dart';

import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/model/common/chess.dart';
Expand All @@ -14,7 +12,6 @@ import 'package:lichess_mobile/src/constants.dart';
import 'package:lichess_mobile/src/model/auth/auth_client.dart';

import './tv_channel.dart';
import './tv_event.dart';
import './tv_game.dart';

part 'tv_repository.g.dart';
Expand All @@ -36,35 +33,6 @@ class TvRepository {
final AuthClient apiClient;
final Logger _log;

Stream<TvEvent> tvFeed() async* {
final resp = await apiClient.stream(Uri.parse('$kLichessHost/api/tv/feed'));
_log.fine('Start streaming TV.');
yield* resp.stream
.toStringStream()
.where((event) => event.isNotEmpty && event != '\n')
.map((event) => jsonDecode(event) as Map<String, dynamic>)
.where((json) => json['t'] == 'featured' || json['t'] == 'fen')
.map((json) => TvEvent.fromJson(json))
.handleError((Object error) => _log.warning(error));
}

Future<TvGameSnapshot> currentBestSnapshot() {
return tvFeed()
.firstWhere((event) => event is TvFeaturedEvent)
.then((event) async {
final featured = event as TvFeaturedEvent;
return TvGameSnapshot(
channel: TvChannel.best,
id: featured.id,
orientation: featured.orientation,
fen: featured.fen,
player: featured.orientation == Side.white
? featured.white
: featured.black,
);
});
}

FutureResult<TvChannels> channels() {
return apiClient
.get(Uri.parse('$kLichessHost/api/tv/channels'))
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/watch/live_tv_channels_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class _Body extends ConsumerWidget {
final currentBottomTab = ref.watch(currentBottomTabProvider);
final gamesAsync = currentBottomTab == BottomTab.watch
? ref.watch(liveTvChannelsProvider)
: const AsyncLoading<TvChannels>();
: const AsyncLoading<LiveTvChannelsState>();
return gamesAsync.when(
data: (games) {
final list = [
Expand Down
2 changes: 2 additions & 0 deletions lib/src/view/watch/tv_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class _Body extends ConsumerWidget {
orientation: cg.Side.white,
fen: kEmptyFen,
),
showMoveListPlaceholder: true,
),
error: (err, stackTrace) {
debugPrint(
Expand All @@ -211,6 +212,7 @@ class _Body extends ConsumerWidget {
orientation: cg.Side.white,
),
errorMessage: 'Could not load TV stream.',
showMoveListPlaceholder: true,
);
},
),
Expand Down
Loading

0 comments on commit 695a3a6

Please sign in to comment.