App: scelta canale YouTube MLTV/società, privacy e condivisione link.
Premium Full può forzare il canale piattaforma; visibilità non in elenco o privato; share_url unificato per Match Live TV e YouTube. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -118,7 +118,7 @@ module Api
|
|||||||
end
|
end
|
||||||
|
|
||||||
def session_params
|
def session_params
|
||||||
params.permit(:platform, :privacy_status, :quality_preset, :target_bitrate, :target_fps)
|
params.permit(:platform, :privacy_status, :quality_preset, :target_bitrate, :target_fps, :youtube_channel)
|
||||||
end
|
end
|
||||||
|
|
||||||
def session_json(session, detail: false)
|
def session_json(session, detail: false)
|
||||||
@@ -130,6 +130,8 @@ module Api
|
|||||||
rtmp_ingest_url: session.rtmp_ingest_url,
|
rtmp_ingest_url: session.rtmp_ingest_url,
|
||||||
hls_playback_url: session.hls_playback_url,
|
hls_playback_url: session.hls_playback_url,
|
||||||
watch_page_url: session.watch_page_url,
|
watch_page_url: session.watch_page_url,
|
||||||
|
share_url: session.share_url,
|
||||||
|
youtube_watch_url: session.youtube_watch_url,
|
||||||
youtube_broadcast_id: session.youtube_broadcast_id,
|
youtube_broadcast_id: session.youtube_broadcast_id,
|
||||||
privacy_status: session.privacy_status,
|
privacy_status: session.privacy_status,
|
||||||
quality_preset: session.quality_preset,
|
quality_preset: session.quality_preset,
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ module Api
|
|||||||
def team_json(team, detail: false)
|
def team_json(team, detail: false)
|
||||||
ent = team.entitlements
|
ent = team.entitlements
|
||||||
yt = Youtube::TeamStatus.new(team)
|
yt = Youtube::TeamStatus.new(team)
|
||||||
|
resolver = Youtube::CredentialResolver.new(team)
|
||||||
data = {
|
data = {
|
||||||
id: team.id,
|
id: team.id,
|
||||||
name: team.name,
|
name: team.name,
|
||||||
@@ -84,6 +85,9 @@ module Api
|
|||||||
youtube_selectable: yt.selectable?,
|
youtube_selectable: yt.selectable?,
|
||||||
youtube_channel_title: yt.channel_title,
|
youtube_channel_title: yt.channel_title,
|
||||||
youtube_uses_platform_channel: yt.uses_platform_channel?,
|
youtube_uses_platform_channel: yt.uses_platform_channel?,
|
||||||
|
youtube_platform_available: resolver.platform_available?,
|
||||||
|
youtube_team_channel_available: resolver.team_channel_available?,
|
||||||
|
youtube_team_channel_title: team.youtube_credential&.channel_title,
|
||||||
plan_slug: ent.plan.slug,
|
plan_slug: ent.plan.slug,
|
||||||
plan_name: ent.plan.name,
|
plan_name: ent.plan.name,
|
||||||
premium_active: ent.premium_active?,
|
premium_active: ent.premium_active?,
|
||||||
|
|||||||
@@ -90,6 +90,21 @@ class StreamSession < ApplicationRecord
|
|||||||
"#{MatchLiveTv.app_public_url.chomp('/')}/live/#{id}"
|
"#{MatchLiveTv.app_public_url.chomp('/')}/live/#{id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def youtube_watch_url
|
||||||
|
return nil if youtube_broadcast_id.blank?
|
||||||
|
return nil if youtube_broadcast_id.to_s.start_with?("mock_")
|
||||||
|
|
||||||
|
"https://www.youtube.com/watch?v=#{youtube_broadcast_id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def share_url
|
||||||
|
if platform == "youtube"
|
||||||
|
youtube_watch_url.presence || watch_page_url
|
||||||
|
else
|
||||||
|
watch_page_url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def terminal?
|
def terminal?
|
||||||
status.in?(%w[ended error])
|
status.in?(%w[ended error])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ module Sessions
|
|||||||
)
|
)
|
||||||
|
|
||||||
if session.platform == "youtube"
|
if session.platform == "youtube"
|
||||||
attach_youtube_broadcast!(session)
|
youtube_channel = @params[:youtube_channel].presence
|
||||||
|
assert_youtube_channel!(youtube_channel)
|
||||||
|
attach_youtube_broadcast!(session, youtube_channel: youtube_channel)
|
||||||
end
|
end
|
||||||
|
|
||||||
StreamSession.transaction do
|
StreamSession.transaction do
|
||||||
@@ -39,8 +41,18 @@ module Sessions
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def attach_youtube_broadcast!(session)
|
def assert_youtube_channel!(youtube_channel)
|
||||||
yt = Youtube::BroadcastService.new(session.match.team)
|
resolver = Youtube::CredentialResolver.new(@match.team, channel: youtube_channel)
|
||||||
|
if resolver.resolve.blank?
|
||||||
|
raise Teams::EntitlementError.new(
|
||||||
|
"Canale YouTube selezionato non disponibile",
|
||||||
|
code: "youtube_channel_unavailable"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def attach_youtube_broadcast!(session, youtube_channel: nil)
|
||||||
|
yt = Youtube::BroadcastService.new(session.match.team, youtube_channel: youtube_channel)
|
||||||
title = "#{session.match.team.name} vs #{session.match.opponent_name}"
|
title = "#{session.match.team.name} vs #{session.match.opponent_name}"
|
||||||
broadcast = yt.create_broadcast!(
|
broadcast = yt.create_broadcast!(
|
||||||
title: title,
|
title: title,
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ module Youtube
|
|||||||
class BroadcastService
|
class BroadcastService
|
||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
|
|
||||||
def initialize(team)
|
def initialize(team, youtube_channel: nil)
|
||||||
@team = team
|
@team = team
|
||||||
@resolver = CredentialResolver.new(team)
|
@resolver = CredentialResolver.new(team, channel: youtube_channel)
|
||||||
@credential = @resolver.resolve
|
@credential = @resolver.resolve
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,61 @@
|
|||||||
module Youtube
|
module Youtube
|
||||||
class CredentialResolver
|
class CredentialResolver
|
||||||
def self.for_team(team)
|
VALID_CHANNELS = %w[platform team].freeze
|
||||||
new(team).resolve
|
|
||||||
|
def self.for_team(team, channel: nil)
|
||||||
|
new(team, channel: channel).resolve
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(team)
|
def initialize(team, channel: nil)
|
||||||
@team = team
|
@team = team
|
||||||
@status = TeamStatus.new(team)
|
@channel = channel.to_s.presence
|
||||||
@mode = team.entitlements.plan.youtube_mode
|
@channel = nil unless VALID_CHANNELS.include?(@channel)
|
||||||
|
@ent = team.entitlements
|
||||||
|
@mode = @ent.plan.youtube_mode
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve
|
def resolve
|
||||||
if @status.uses_platform_channel?
|
case effective_channel
|
||||||
PlatformCredential.new
|
when :platform
|
||||||
elsif @mode == "team"
|
PlatformCredential.configured? ? PlatformCredential.new : nil
|
||||||
|
when :team
|
||||||
@team.youtube_credential
|
@team.youtube_credential
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def uses_platform_channel?
|
def uses_platform_channel?
|
||||||
@status.uses_platform_channel?
|
effective_channel == :platform
|
||||||
|
end
|
||||||
|
|
||||||
|
def platform_available?
|
||||||
|
@ent.youtube_enabled? && PlatformCredential.configured?
|
||||||
|
end
|
||||||
|
|
||||||
|
def team_channel_available?
|
||||||
|
@ent.youtube_enabled? && @ent.premium_full? && @mode == "team" && @team.youtube_credential.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def effective_channel
|
||||||
|
if @channel == "platform"
|
||||||
|
return :platform if platform_available?
|
||||||
|
elsif @channel == "team"
|
||||||
|
return :team if team_channel_available?
|
||||||
|
end
|
||||||
|
|
||||||
|
auto_channel
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def auto_channel
|
||||||
|
if @mode == "matchlivetv_light"
|
||||||
|
return :platform if platform_available?
|
||||||
|
elsif @mode == "team"
|
||||||
|
return :team if team_channel_available?
|
||||||
|
return :platform if platform_available?
|
||||||
|
end
|
||||||
|
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import '../../providers/match_rules_provider.dart';
|
|||||||
import '../../providers/score_provider.dart';
|
import '../../providers/score_provider.dart';
|
||||||
import '../../shared/api_client.dart';
|
import '../../shared/api_client.dart';
|
||||||
import '../../shared/regia_share.dart';
|
import '../../shared/regia_share.dart';
|
||||||
|
import '../../shared/watch_share.dart';
|
||||||
import '../../shared/models/score_state.dart';
|
import '../../shared/models/score_state.dart';
|
||||||
import '../../providers/session_provider.dart';
|
import '../../providers/session_provider.dart';
|
||||||
import '../../shared/websocket_service.dart';
|
import '../../shared/websocket_service.dart';
|
||||||
@@ -232,6 +233,50 @@ class _CameraScreenState extends ConsumerState<CameraScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _shareWatch() async {
|
||||||
|
final session = ref.read(sessionProvider).session;
|
||||||
|
final match = ref.read(sessionProvider).match;
|
||||||
|
if (session == null) return;
|
||||||
|
await shareWatchLink(
|
||||||
|
context,
|
||||||
|
session: session,
|
||||||
|
title:
|
||||||
|
'Diretta — ${match?.teamName ?? 'Casa'} vs ${match?.opponentName ?? 'Ospiti'}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showShareMenu() {
|
||||||
|
final session = ref.read(sessionProvider).session;
|
||||||
|
if (session == null) return;
|
||||||
|
final isYoutube = session.platform == 'youtube';
|
||||||
|
showModalBottomSheet<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => SafeArea(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.live_tv),
|
||||||
|
title: Text(isYoutube ? 'Condividi link YouTube' : 'Condividi link diretta'),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
_shareWatch();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.scoreboard),
|
||||||
|
title: const Text('Condividi link regia (punteggio)'),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
_shareRegia();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _leaveSession() async {
|
Future<void> _leaveSession() async {
|
||||||
try {
|
try {
|
||||||
await StreamingChannel.stopStream();
|
await StreamingChannel.stopStream();
|
||||||
@@ -342,7 +387,7 @@ class _CameraScreenState extends ConsumerState<CameraScreen> {
|
|||||||
bitrateMbps: _bitrateMbps,
|
bitrateMbps: _bitrateMbps,
|
||||||
fps: _fps,
|
fps: _fps,
|
||||||
viewerCount: _viewerCount,
|
viewerCount: _viewerCount,
|
||||||
onShareRegia: _shareRegia,
|
onShare: _showShareMenu,
|
||||||
onInterrupt: _interruptStream,
|
onInterrupt: _interruptStream,
|
||||||
onCloseStream: _closeStreamPermanently,
|
onCloseStream: _closeStreamPermanently,
|
||||||
pointsTarget: pointsTarget,
|
pointsTarget: pointsTarget,
|
||||||
@@ -358,7 +403,7 @@ class _CameraScreenState extends ConsumerState<CameraScreen> {
|
|||||||
bitrateMbps: _bitrateMbps,
|
bitrateMbps: _bitrateMbps,
|
||||||
fps: _fps,
|
fps: _fps,
|
||||||
viewerCount: _viewerCount,
|
viewerCount: _viewerCount,
|
||||||
onShareRegia: _shareRegia,
|
onShare: _showShareMenu,
|
||||||
onInterrupt: _interruptStream,
|
onInterrupt: _interruptStream,
|
||||||
onCloseStream: _closeStreamPermanently,
|
onCloseStream: _closeStreamPermanently,
|
||||||
pointsTarget: pointsTarget,
|
pointsTarget: pointsTarget,
|
||||||
@@ -380,7 +425,7 @@ class _PortraitOverlay extends StatelessWidget {
|
|||||||
required this.bitrateMbps,
|
required this.bitrateMbps,
|
||||||
required this.fps,
|
required this.fps,
|
||||||
required this.viewerCount,
|
required this.viewerCount,
|
||||||
required this.onShareRegia,
|
required this.onShare,
|
||||||
required this.onInterrupt,
|
required this.onInterrupt,
|
||||||
required this.onCloseStream,
|
required this.onCloseStream,
|
||||||
required this.pointsTarget,
|
required this.pointsTarget,
|
||||||
@@ -395,7 +440,7 @@ class _PortraitOverlay extends StatelessWidget {
|
|||||||
final double bitrateMbps;
|
final double bitrateMbps;
|
||||||
final int fps;
|
final int fps;
|
||||||
final int viewerCount;
|
final int viewerCount;
|
||||||
final VoidCallback onShareRegia;
|
final VoidCallback onShare;
|
||||||
final VoidCallback onInterrupt;
|
final VoidCallback onInterrupt;
|
||||||
final Future<void> Function() onCloseStream;
|
final Future<void> Function() onCloseStream;
|
||||||
final int pointsTarget;
|
final int pointsTarget;
|
||||||
@@ -413,9 +458,9 @@ class _PortraitOverlay extends StatelessWidget {
|
|||||||
LiveBadge(elapsed: elapsed),
|
LiveBadge(elapsed: elapsed),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: onShareRegia,
|
onPressed: onShare,
|
||||||
icon: const Icon(Icons.share),
|
icon: const Icon(Icons.share),
|
||||||
tooltip: 'Condividi link regia',
|
tooltip: 'Condividi link',
|
||||||
),
|
),
|
||||||
CameraCompactMetrics(
|
CameraCompactMetrics(
|
||||||
networkType: networkType,
|
networkType: networkType,
|
||||||
@@ -451,9 +496,9 @@ class _PortraitOverlay extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
OutlinedButton.icon(
|
OutlinedButton.icon(
|
||||||
onPressed: onShareRegia,
|
onPressed: onShare,
|
||||||
icon: const Icon(Icons.share, size: 18),
|
icon: const Icon(Icons.share, size: 18),
|
||||||
label: const Text('Condividi link regia'),
|
label: const Text('Condividi link'),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
@@ -485,7 +530,7 @@ class _LandscapeOverlay extends StatelessWidget {
|
|||||||
required this.bitrateMbps,
|
required this.bitrateMbps,
|
||||||
required this.fps,
|
required this.fps,
|
||||||
required this.viewerCount,
|
required this.viewerCount,
|
||||||
required this.onShareRegia,
|
required this.onShare,
|
||||||
required this.onInterrupt,
|
required this.onInterrupt,
|
||||||
required this.onCloseStream,
|
required this.onCloseStream,
|
||||||
required this.pointsTarget,
|
required this.pointsTarget,
|
||||||
@@ -501,7 +546,7 @@ class _LandscapeOverlay extends StatelessWidget {
|
|||||||
final double bitrateMbps;
|
final double bitrateMbps;
|
||||||
final int fps;
|
final int fps;
|
||||||
final int viewerCount;
|
final int viewerCount;
|
||||||
final VoidCallback onShareRegia;
|
final VoidCallback onShare;
|
||||||
final VoidCallback onInterrupt;
|
final VoidCallback onInterrupt;
|
||||||
final Future<void> Function() onCloseStream;
|
final Future<void> Function() onCloseStream;
|
||||||
final int pointsTarget;
|
final int pointsTarget;
|
||||||
@@ -557,9 +602,9 @@ class _LandscapeOverlay extends StatelessWidget {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: onShareRegia,
|
onPressed: onShare,
|
||||||
icon: const Icon(Icons.share, color: Colors.white),
|
icon: const Icon(Icons.share, color: Colors.white),
|
||||||
tooltip: 'Condividi link regia',
|
tooltip: 'Condividi link',
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: OutlinedButton(
|
child: OutlinedButton(
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
@@ -16,6 +15,7 @@ import '../../shared/models/score_state.dart';
|
|||||||
import '../../shared/models/stream_session.dart';
|
import '../../shared/models/stream_session.dart';
|
||||||
import '../../shared/websocket_service.dart';
|
import '../../shared/websocket_service.dart';
|
||||||
import '../../shared/regia_share.dart';
|
import '../../shared/regia_share.dart';
|
||||||
|
import '../../shared/watch_share.dart';
|
||||||
import '../../shared/widgets/metric_card.dart';
|
import '../../shared/widgets/metric_card.dart';
|
||||||
import '../../shared/widgets/primary_cta.dart';
|
import '../../shared/widgets/primary_cta.dart';
|
||||||
import '../../shared/widgets/screen_insets.dart';
|
import '../../shared/widgets/screen_insets.dart';
|
||||||
@@ -201,7 +201,7 @@ class _StepNetworkTestState extends ConsumerState<StepNetworkTest> {
|
|||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (ref.read(sessionProvider).session?.watchPageUrl != null) ...[
|
if (watchShareUrl(ref.read(sessionProvider).session!) != null) ...[
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(14),
|
padding: const EdgeInsets.all(14),
|
||||||
@@ -213,25 +213,43 @@ class _StepNetworkTestState extends ConsumerState<StepNetworkTest> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'Link per gli spettatori',
|
ref.read(sessionProvider).session!.platform == 'youtube'
|
||||||
|
? 'Link video YouTube'
|
||||||
|
: 'Link diretta Match Live TV',
|
||||||
style: theme.textTheme.titleSmall,
|
style: theme.textTheme.titleSmall,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
SelectableText(
|
SelectableText(
|
||||||
ref.read(sessionProvider).session!.watchPageUrl!,
|
watchShareUrl(ref.read(sessionProvider).session!)!,
|
||||||
style: theme.textTheme.bodySmall,
|
style: theme.textTheme.bodySmall,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
OutlinedButton.icon(
|
Row(
|
||||||
onPressed: () {
|
children: [
|
||||||
final url = ref.read(sessionProvider).session!.watchPageUrl!;
|
Expanded(
|
||||||
Clipboard.setData(ClipboardData(text: url));
|
child: OutlinedButton.icon(
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
onPressed: () => copyWatchLink(
|
||||||
const SnackBar(content: Text('Link copiato')),
|
context,
|
||||||
);
|
ref.read(sessionProvider).session!,
|
||||||
},
|
),
|
||||||
icon: const Icon(Icons.link, size: 18),
|
icon: const Icon(Icons.link, size: 18),
|
||||||
label: const Text('COPIA LINK DIRETTA'),
|
label: const Text('COPIA'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: OutlinedButton.icon(
|
||||||
|
onPressed: () => shareWatchLink(
|
||||||
|
context,
|
||||||
|
session: ref.read(sessionProvider).session!,
|
||||||
|
title:
|
||||||
|
'Diretta — ${widget.match.teamName} vs ${widget.match.opponentName}',
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.share, size: 18),
|
||||||
|
label: const Text('CONDIVIDI'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -251,19 +269,33 @@ class _StepNetworkTestState extends ConsumerState<StepNetworkTest> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
OutlinedButton.icon(
|
if (ref.read(sessionProvider).session != null) ...[
|
||||||
onPressed: ref.read(sessionProvider).session == null
|
OutlinedButton.icon(
|
||||||
? null
|
onPressed: () => shareWatchLink(
|
||||||
: () => shareRegiaLink(
|
context,
|
||||||
context,
|
session: ref.read(sessionProvider).session!,
|
||||||
ref,
|
title: 'Diretta — ${widget.match.teamName} vs ${widget.match.opponentName}',
|
||||||
sessionId: ref.read(sessionProvider).session!.id,
|
),
|
||||||
shareSubject:
|
icon: const Icon(Icons.live_tv),
|
||||||
'Regia — ${widget.match.teamName} vs ${widget.match.opponentName}',
|
label: Text(
|
||||||
),
|
ref.read(sessionProvider).session!.platform == 'youtube'
|
||||||
icon: const Icon(Icons.share),
|
? 'Condividi link YouTube'
|
||||||
label: const Text('Condividi link regia (punteggio)'),
|
: 'Condividi link diretta',
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
OutlinedButton.icon(
|
||||||
|
onPressed: () => shareRegiaLink(
|
||||||
|
context,
|
||||||
|
ref,
|
||||||
|
sessionId: ref.read(sessionProvider).session!.id,
|
||||||
|
shareSubject:
|
||||||
|
'Regia — ${widget.match.teamName} vs ${widget.match.opponentName}',
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.scoreboard),
|
||||||
|
label: const Text('Condividi link regia (punteggio)'),
|
||||||
|
),
|
||||||
|
],
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onPressed: _testing ? null : _runTest,
|
onPressed: _testing ? null : _runTest,
|
||||||
|
|||||||
@@ -31,8 +31,27 @@ class StepTransmission extends ConsumerStatefulWidget {
|
|||||||
class _StepTransmissionState extends ConsumerState<StepTransmission> {
|
class _StepTransmissionState extends ConsumerState<StepTransmission> {
|
||||||
String _platform = 'matchlivetv';
|
String _platform = 'matchlivetv';
|
||||||
String _privacy = 'unlisted';
|
String _privacy = 'unlisted';
|
||||||
|
String? _youtubeChannel;
|
||||||
bool _creating = false;
|
bool _creating = false;
|
||||||
|
|
||||||
|
void _syncYoutubeChannel(Team? team) {
|
||||||
|
if (team == null) {
|
||||||
|
_youtubeChannel = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!team.canChooseYoutubeChannel) {
|
||||||
|
if (team.youtubeTeamChannelAvailable) {
|
||||||
|
_youtubeChannel = 'team';
|
||||||
|
} else if (team.youtubePlatformAvailable) {
|
||||||
|
_youtubeChannel = 'platform';
|
||||||
|
} else {
|
||||||
|
_youtubeChannel = null;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_youtubeChannel ??= 'platform';
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _createSession() async {
|
Future<void> _createSession() async {
|
||||||
setState(() => _creating = true);
|
setState(() => _creating = true);
|
||||||
try {
|
try {
|
||||||
@@ -40,6 +59,7 @@ class _StepTransmissionState extends ConsumerState<StepTransmission> {
|
|||||||
final session = await client.createSession(
|
final session = await client.createSession(
|
||||||
widget.match.id,
|
widget.match.id,
|
||||||
platform: _platform,
|
platform: _platform,
|
||||||
|
youtubeChannel: _platform == 'youtube' ? _youtubeChannel : null,
|
||||||
privacyStatus: _privacy,
|
privacyStatus: _privacy,
|
||||||
qualityPreset: '720p_30_2.5mbps',
|
qualityPreset: '720p_30_2.5mbps',
|
||||||
targetBitrate: 2500000,
|
targetBitrate: 2500000,
|
||||||
@@ -76,7 +96,10 @@ class _StepTransmissionState extends ConsumerState<StepTransmission> {
|
|||||||
void _onYoutubeTap(Team? team) {
|
void _onYoutubeTap(Team? team) {
|
||||||
if (team == null) return;
|
if (team == null) return;
|
||||||
if (team.isYoutubeReady) {
|
if (team.isYoutubeReady) {
|
||||||
setState(() => _platform = 'youtube');
|
setState(() {
|
||||||
|
_platform = 'youtube';
|
||||||
|
_syncYoutubeChannel(team);
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (team.canUseYoutube) {
|
if (team.canUseYoutube) {
|
||||||
@@ -100,17 +123,20 @@ class _StepTransmissionState extends ConsumerState<StepTransmission> {
|
|||||||
if (team == null || !team.canUseYoutube) {
|
if (team == null || !team.canUseYoutube) {
|
||||||
return 'Premium Light o Full';
|
return 'Premium Light o Full';
|
||||||
}
|
}
|
||||||
if (team.isYoutubeReady) {
|
if (!team.isYoutubeReady) {
|
||||||
final label = team.youtubeChannelTitle;
|
|
||||||
if (team.youtubeUsesPlatformChannel) {
|
|
||||||
return label != null ? 'Canale $label' : 'Canale Match Live TV';
|
|
||||||
}
|
|
||||||
return label != null ? 'Canale $label' : 'Canale società collegato';
|
|
||||||
}
|
|
||||||
if (team.youtubeMode == 'matchlivetv_light' || team.youtubeMode == 'team') {
|
|
||||||
return 'Canale Match Live TV (in attivazione)';
|
return 'Canale Match Live TV (in attivazione)';
|
||||||
}
|
}
|
||||||
return 'In attivazione';
|
if (_platform == 'youtube' && team.canChooseYoutubeChannel) {
|
||||||
|
return _youtubeChannel == 'team'
|
||||||
|
? 'Canale ${team.youtubeTeamChannelTitle ?? "società"}'
|
||||||
|
: 'Canale Match Live TV';
|
||||||
|
}
|
||||||
|
if (team.youtubeUsesPlatformChannel || team.youtubePlatformAvailable) {
|
||||||
|
final label = team.youtubeChannelTitle;
|
||||||
|
return label != null ? 'Canale $label' : 'Canale Match Live TV';
|
||||||
|
}
|
||||||
|
final label = team.youtubeTeamChannelTitle ?? team.youtubeChannelTitle;
|
||||||
|
return label != null ? 'Canale $label' : 'Canale società collegato';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -122,7 +148,10 @@ class _StepTransmissionState extends ConsumerState<StepTransmission> {
|
|||||||
loading: () => const Center(child: CircularProgressIndicator(color: AppTheme.primaryRed)),
|
loading: () => const Center(child: CircularProgressIndicator(color: AppTheme.primaryRed)),
|
||||||
error: (_, __) => const Center(child: Text('Errore caricamento squadra')),
|
error: (_, __) => const Center(child: Text('Errore caricamento squadra')),
|
||||||
data: (team) {
|
data: (team) {
|
||||||
|
_syncYoutubeChannel(team);
|
||||||
final youtubeSelectable = team != null && team.isYoutubeReady;
|
final youtubeSelectable = team != null && team.isYoutubeReady;
|
||||||
|
final showYoutubeChannels =
|
||||||
|
_platform == 'youtube' && team != null && team.canChooseYoutubeChannel;
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
padding: ScreenInsets.contentPadding(context, horizontal: 20, vertical: 12),
|
padding: ScreenInsets.contentPadding(context, horizontal: 20, vertical: 12),
|
||||||
@@ -163,17 +192,60 @@ class _StepTransmissionState extends ConsumerState<StepTransmission> {
|
|||||||
badge: team?.canUseYoutube == true ? null : 'Premium',
|
badge: team?.canUseYoutube == true ? null : 'Premium',
|
||||||
onTap: () => _onYoutubeTap(team),
|
onTap: () => _onYoutubeTap(team),
|
||||||
),
|
),
|
||||||
|
if (showYoutubeChannels) ...[
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Text('Canale YouTube', style: theme.textTheme.titleMedium),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_PlatformCard(
|
||||||
|
title: 'Match Live TV',
|
||||||
|
subtitle: 'Canale ufficiale della piattaforma',
|
||||||
|
selected: _youtubeChannel == 'platform',
|
||||||
|
enabled: true,
|
||||||
|
onTap: () => setState(() => _youtubeChannel = 'platform'),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_PlatformCard(
|
||||||
|
title: team!.youtubeTeamChannelTitle ?? 'Canale società',
|
||||||
|
subtitle: 'Il tuo canale collegato',
|
||||||
|
selected: _youtubeChannel == 'team',
|
||||||
|
enabled: true,
|
||||||
|
onTap: () => setState(() => _youtubeChannel = 'team'),
|
||||||
|
),
|
||||||
|
],
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
Text('Privacy', style: theme.textTheme.titleLarge),
|
Text('Visibilità video', style: theme.textTheme.titleLarge),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Solo per YouTube. Su Match Live TV la pagina diretta segue le impostazioni del sito.',
|
||||||
|
style: theme.textTheme.bodySmall,
|
||||||
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
SegmentedButton<String>(
|
SegmentedButton<String>(
|
||||||
segments: const [
|
segments: const [
|
||||||
ButtonSegment(value: 'public', label: Text('Pubblico')),
|
ButtonSegment(
|
||||||
ButtonSegment(value: 'unlisted', label: Text('Non in elenco')),
|
value: 'unlisted',
|
||||||
|
label: Text('Non in elenco'),
|
||||||
|
icon: Icon(Icons.link),
|
||||||
|
),
|
||||||
|
ButtonSegment(
|
||||||
|
value: 'private',
|
||||||
|
label: Text('Privato'),
|
||||||
|
icon: Icon(Icons.lock_outline),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
selected: {_privacy},
|
selected: {_privacy},
|
||||||
onSelectionChanged: (s) => setState(() => _privacy = s.first),
|
onSelectionChanged: _platform == 'youtube'
|
||||||
|
? (s) => setState(() => _privacy = s.first)
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
|
if (_platform != 'youtube')
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 8),
|
||||||
|
child: Text(
|
||||||
|
'Seleziona YouTube Live per impostare la visibilità del video.',
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(color: AppTheme.textSecondary),
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
Text('Qualità', style: theme.textTheme.titleLarge),
|
Text('Qualità', style: theme.textTheme.titleLarge),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ class SessionNotifier extends StateNotifier<SessionState> {
|
|||||||
rtmpIngestUrl: s.rtmpIngestUrl,
|
rtmpIngestUrl: s.rtmpIngestUrl,
|
||||||
hlsPlaybackUrl: s.hlsPlaybackUrl,
|
hlsPlaybackUrl: s.hlsPlaybackUrl,
|
||||||
watchPageUrl: s.watchPageUrl,
|
watchPageUrl: s.watchPageUrl,
|
||||||
|
shareUrl: s.shareUrl,
|
||||||
|
youtubeWatchUrl: s.youtubeWatchUrl,
|
||||||
youtubeBroadcastId: s.youtubeBroadcastId,
|
youtubeBroadcastId: s.youtubeBroadcastId,
|
||||||
privacyStatus: s.privacyStatus,
|
privacyStatus: s.privacyStatus,
|
||||||
qualityPreset: s.qualityPreset,
|
qualityPreset: s.qualityPreset,
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ class ApiClient {
|
|||||||
Future<StreamSession> createSession(
|
Future<StreamSession> createSession(
|
||||||
String matchId, {
|
String matchId, {
|
||||||
String platform = 'matchlivetv',
|
String platform = 'matchlivetv',
|
||||||
|
String? youtubeChannel,
|
||||||
String privacyStatus = 'unlisted',
|
String privacyStatus = 'unlisted',
|
||||||
String qualityPreset = '720p_30_2.5mbps',
|
String qualityPreset = '720p_30_2.5mbps',
|
||||||
int? targetBitrate,
|
int? targetBitrate,
|
||||||
@@ -164,6 +165,7 @@ class ApiClient {
|
|||||||
'platform': platform,
|
'platform': platform,
|
||||||
'privacy_status': privacyStatus,
|
'privacy_status': privacyStatus,
|
||||||
'quality_preset': qualityPreset,
|
'quality_preset': qualityPreset,
|
||||||
|
if (youtubeChannel != null) 'youtube_channel': youtubeChannel,
|
||||||
if (targetBitrate != null) 'target_bitrate': targetBitrate,
|
if (targetBitrate != null) 'target_bitrate': targetBitrate,
|
||||||
if (targetFps != null) 'target_fps': targetFps,
|
if (targetFps != null) 'target_fps': targetFps,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ class StreamSession {
|
|||||||
this.rtmpIngestUrl,
|
this.rtmpIngestUrl,
|
||||||
this.hlsPlaybackUrl,
|
this.hlsPlaybackUrl,
|
||||||
this.watchPageUrl,
|
this.watchPageUrl,
|
||||||
|
this.shareUrl,
|
||||||
|
this.youtubeWatchUrl,
|
||||||
this.youtubeBroadcastId,
|
this.youtubeBroadcastId,
|
||||||
this.privacyStatus = 'unlisted',
|
this.privacyStatus = 'unlisted',
|
||||||
this.qualityPreset = '720p_30_2.5mbps',
|
this.qualityPreset = '720p_30_2.5mbps',
|
||||||
@@ -27,6 +29,8 @@ class StreamSession {
|
|||||||
final String? rtmpIngestUrl;
|
final String? rtmpIngestUrl;
|
||||||
final String? hlsPlaybackUrl;
|
final String? hlsPlaybackUrl;
|
||||||
final String? watchPageUrl;
|
final String? watchPageUrl;
|
||||||
|
final String? shareUrl;
|
||||||
|
final String? youtubeWatchUrl;
|
||||||
final String? youtubeBroadcastId;
|
final String? youtubeBroadcastId;
|
||||||
final String privacyStatus;
|
final String privacyStatus;
|
||||||
final String qualityPreset;
|
final String qualityPreset;
|
||||||
@@ -55,6 +59,8 @@ class StreamSession {
|
|||||||
rtmpIngestUrl: json['rtmp_ingest_url'] as String?,
|
rtmpIngestUrl: json['rtmp_ingest_url'] as String?,
|
||||||
hlsPlaybackUrl: json['hls_playback_url'] as String?,
|
hlsPlaybackUrl: json['hls_playback_url'] as String?,
|
||||||
watchPageUrl: json['watch_page_url'] as String?,
|
watchPageUrl: json['watch_page_url'] as String?,
|
||||||
|
shareUrl: json['share_url'] as String?,
|
||||||
|
youtubeWatchUrl: json['youtube_watch_url'] as String?,
|
||||||
youtubeBroadcastId: json['youtube_broadcast_id'] as String?,
|
youtubeBroadcastId: json['youtube_broadcast_id'] as String?,
|
||||||
privacyStatus: json['privacy_status'] as String? ?? 'unlisted',
|
privacyStatus: json['privacy_status'] as String? ?? 'unlisted',
|
||||||
qualityPreset: json['quality_preset'] as String? ?? '720p_30_2.5mbps',
|
qualityPreset: json['quality_preset'] as String? ?? '720p_30_2.5mbps',
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ class Team {
|
|||||||
this.youtubeSelectable = false,
|
this.youtubeSelectable = false,
|
||||||
this.youtubeChannelTitle,
|
this.youtubeChannelTitle,
|
||||||
this.youtubeUsesPlatformChannel = false,
|
this.youtubeUsesPlatformChannel = false,
|
||||||
|
this.youtubePlatformAvailable = false,
|
||||||
|
this.youtubeTeamChannelAvailable = false,
|
||||||
|
this.youtubeTeamChannelTitle,
|
||||||
this.planSlug = 'free',
|
this.planSlug = 'free',
|
||||||
this.planName = 'Free',
|
this.planName = 'Free',
|
||||||
this.premiumActive = false,
|
this.premiumActive = false,
|
||||||
@@ -43,6 +46,9 @@ class Team {
|
|||||||
final bool youtubeSelectable;
|
final bool youtubeSelectable;
|
||||||
final String? youtubeChannelTitle;
|
final String? youtubeChannelTitle;
|
||||||
final bool youtubeUsesPlatformChannel;
|
final bool youtubeUsesPlatformChannel;
|
||||||
|
final bool youtubePlatformAvailable;
|
||||||
|
final bool youtubeTeamChannelAvailable;
|
||||||
|
final String? youtubeTeamChannelTitle;
|
||||||
final String planSlug;
|
final String planSlug;
|
||||||
final String planName;
|
final String planName;
|
||||||
final bool premiumActive;
|
final bool premiumActive;
|
||||||
@@ -66,6 +72,9 @@ class Team {
|
|||||||
bool get canUseYoutube => youtubeEnabled && (premiumFull || youtubeMode == 'matchlivetv_light');
|
bool get canUseYoutube => youtubeEnabled && (premiumFull || youtubeMode == 'matchlivetv_light');
|
||||||
|
|
||||||
bool get isYoutubeReady => youtubeSelectable;
|
bool get isYoutubeReady => youtubeSelectable;
|
||||||
|
|
||||||
|
bool get canChooseYoutubeChannel =>
|
||||||
|
youtubePlatformAvailable && youtubeTeamChannelAvailable;
|
||||||
bool get canUseRecordings => recordingsEnabled;
|
bool get canUseRecordings => recordingsEnabled;
|
||||||
bool get canDownloadOnPhone => phoneDownloadEnabled;
|
bool get canDownloadOnPhone => phoneDownloadEnabled;
|
||||||
|
|
||||||
@@ -89,6 +98,9 @@ class Team {
|
|||||||
youtubeSelectable: json['youtube_selectable'] as bool? ?? false,
|
youtubeSelectable: json['youtube_selectable'] as bool? ?? false,
|
||||||
youtubeChannelTitle: json['youtube_channel_title'] as String?,
|
youtubeChannelTitle: json['youtube_channel_title'] as String?,
|
||||||
youtubeUsesPlatformChannel: json['youtube_uses_platform_channel'] as bool? ?? false,
|
youtubeUsesPlatformChannel: json['youtube_uses_platform_channel'] as bool? ?? false,
|
||||||
|
youtubePlatformAvailable: json['youtube_platform_available'] as bool? ?? false,
|
||||||
|
youtubeTeamChannelAvailable: json['youtube_team_channel_available'] as bool? ?? false,
|
||||||
|
youtubeTeamChannelTitle: json['youtube_team_channel_title'] as String?,
|
||||||
planSlug: json['plan_slug'] as String? ?? 'free',
|
planSlug: json['plan_slug'] as String? ?? 'free',
|
||||||
planName: json['plan_name'] as String? ?? 'Free',
|
planName: json['plan_name'] as String? ?? 'Free',
|
||||||
premiumActive: json['premium_active'] as bool? ?? false,
|
premiumActive: json['premium_active'] as bool? ?? false,
|
||||||
|
|||||||
54
mobile/lib/shared/watch_share.dart
Normal file
54
mobile/lib/shared/watch_share.dart
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
||||||
|
import 'models/stream_session.dart';
|
||||||
|
|
||||||
|
String? watchShareUrl(StreamSession session) {
|
||||||
|
return session.shareUrl ?? session.youtubeWatchUrl ?? session.watchPageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
String watchShareLabel(StreamSession session) {
|
||||||
|
if (session.platform == 'youtube') {
|
||||||
|
return 'Guarda la diretta su YouTube';
|
||||||
|
}
|
||||||
|
return 'Guarda la diretta su Match Live TV';
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> shareWatchLink(
|
||||||
|
BuildContext context, {
|
||||||
|
required StreamSession session,
|
||||||
|
required String title,
|
||||||
|
}) async {
|
||||||
|
final url = watchShareUrl(session);
|
||||||
|
if (url == null || url.isEmpty) {
|
||||||
|
if (context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Link diretta non ancora disponibile')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await Share.share(
|
||||||
|
'${watchShareLabel(session)}:\n$url',
|
||||||
|
subject: title,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> copyWatchLink(BuildContext context, StreamSession session) async {
|
||||||
|
final url = watchShareUrl(session);
|
||||||
|
if (url == null || url.isEmpty) {
|
||||||
|
if (context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Link diretta non ancora disponibile')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await Clipboard.setData(ClipboardData(text: url));
|
||||||
|
if (context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Link copiato')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user