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
4 changes: 4 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
{
"source": "/api/subscribe",
"function": "subscribe"
},
{
"source": "/embed",
"function": "embedRedirect"
}
]
}
Expand Down
27 changes: 27 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,33 @@ export const getProfilePicture = functions.https.onRequest(async (req, res) => {
}
});

export const embedRedirect = functions.https.onRequest(async (req, res) => {
const provider = req.query?.provider as string | null;
const channelId = req.query?.channelId as string | null;
if (!provider || !channelId) {
throw new functions.https.HttpsError(
"invalid-argument",
"missing provider, channelId"
);
}
switch (provider) {
case "twitch":
const login = await getTwitchLogin(channelId);
if (!login) {
throw new functions.https.HttpsError("not-found", "channel not found");
}
res.redirect(
`https://player.twitch.tv/?channel=${login}&controls=false&parent=chat.rtirl.com&muted=true`
);
break;
default:
throw new functions.https.HttpsError(
"invalid-argument",
"invalid provider"
);
}
});

export {
subscribe,
unsubscribe,
Expand Down
12 changes: 5 additions & 7 deletions lib/components/stream_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:rtchat/models/channels.dart';
import 'package:rtchat/models/stream_preview.dart';
import 'package:webview_flutter/webview_flutter.dart';

class StreamPreview extends StatefulWidget {
const StreamPreview({
Key? key,
required this.channelDisplayName,
}) : super(key: key);
const StreamPreview({Key? key, required this.channel}) : super(key: key);

final String channelDisplayName;
final Channel channel;

@override
State<StreamPreview> createState() => _StreamPreviewState();
Expand Down Expand Up @@ -63,7 +61,7 @@ class _StreamPreviewState extends State<StreamPreview> {
void didUpdateWidget(StreamPreview oldWidget) {
super.didUpdateWidget(oldWidget);
final newUrl =
'https://player.twitch.tv/?channel=${widget.channelDisplayName}&controls=false&parent=chat.rtirl.com&muted=true';
'https://chat.rtirl.com/embed?provider=${widget.channel.provider}&channelId=${widget.channel.channelId}';
if (url != newUrl && _controller != null) {
_controller!.loadUrl(newUrl);
url = newUrl;
Expand All @@ -75,7 +73,7 @@ class _StreamPreviewState extends State<StreamPreview> {
return Stack(children: [
WebView(
initialUrl:
'https://player.twitch.tv/?channel=${widget.channelDisplayName}&controls=false&parent=chat.rtirl.com&muted=true',
'https://chat.rtirl.com/embed?provider=${widget.channel.provider}&channelId=${widget.channel.channelId}',
onWebViewCreated: (controller) {
if (!mounted) {
return;
Expand Down
8 changes: 2 additions & 6 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
} else if (layoutModel.isShowPreview) {
return SizedBox(
height: MediaQuery.of(context).size.width * 9 / 16,
child: StreamPreview(
channelDisplayName:
widget.channel.displayName));
child: StreamPreview(channel: widget.channel));
} else {
return Container();
}
Expand Down Expand Up @@ -326,9 +324,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
if (layoutModel.isShowNotifications) {
return const ActivityFeedPanelWidget();
} else if (layoutModel.isShowPreview) {
return StreamPreview(
channelDisplayName:
widget.channel.displayName);
return StreamPreview(channel: widget.channel);
} else {
return Container();
}
Expand Down