RemoteMediaClient created demo receiver

This commit is contained in:
gianlucaparadise 2021-11-17 08:28:18 +01:00
parent cc5e5f9696
commit 2125ebf893
5 changed files with 66 additions and 3 deletions

View file

@ -6,3 +6,6 @@ pigeon: # Generates the typesafe bridge between host and flutter
--objc_source_out ios/Classes/PlatformBridgeApis.m \ --objc_source_out ios/Classes/PlatformBridgeApis.m \
--java_out ./android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java \ --java_out ./android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java \
--java_package "com.gianlucaparadise.flutter_cast_framework" --java_package "com.gianlucaparadise.flutter_cast_framework"
deploy-receiver:
surge receiver

View file

@ -9,7 +9,7 @@ import com.google.android.gms.cast.framework.SessionProvider
class CastOptionsProvider : OptionsProvider { class CastOptionsProvider : OptionsProvider {
override fun getCastOptions(context: Context): CastOptions { override fun getCastOptions(context: Context): CastOptions {
return CastOptions.Builder() return CastOptions.Builder()
.setReceiverApplicationId("4F8B3483") .setReceiverApplicationId("D6760CCD")
.build() .build()
} }

View file

@ -4,7 +4,7 @@ import GoogleCast
@UIApplicationMain @UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, GCKLoggerDelegate { @objc class AppDelegate: FlutterAppDelegate, GCKLoggerDelegate {
let kReceiverAppID = "4F8B3483" let kReceiverAppID = "D6760CCD"
let kDebugLoggingEnabled = true let kDebugLoggingEnabled = true
override func application( override func application(

1
receiver/CNAME Normal file
View file

@ -0,0 +1 @@
flutter-cast-framework-demo.surge.sh

59
receiver/index.html Normal file
View file

@ -0,0 +1,59 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js">
</script>
</head>
<body>
<cast-media-player></cast-media-player>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
<script>
const namespace = "urn:x-cast:flutter-cast-framework-demo";
const context = cast.framework.CastReceiverContext.getInstance();
const showMessage = (text) => {
if (!text) return;
Toastify({
text: text,
duration: 3000,
gravity: "bottom",
position: "right", // `left`, `center` or `right`
stopOnFocus: true, // Prevents dismissing of toast on hover
style: {
background: "#4496EC",
},
}).showToast();
}
const sendMessage = (senderId) => {
senderId = !senderId ? undefined : senderId; // When senderId is undefined, this broadcasts to all connected devices
const message = `Received text from ${senderId} at ${new Date().toISOString()}`
console.log('Sending CustomMessage: ');
console.log(message);
context.sendCustomMessage(namespace, senderId, message);
}
const onCustomMessage = (event) => {
console.log('Received CustomMessage: ');
console.log(event);
const text = event?.data?.text;
showMessage(text);
const senderId = event?.senderId;
sendMessage(senderId);
}
context.addCustomMessageListener(namespace, onCustomMessage)
context.start();
</script>
</body>
</html>