Line data Source code
1 : import 'dart:convert';
2 :
3 : import 'package:flutter_chrome_cast/common/hls_segment_format.dart';
4 : import 'package:flutter_chrome_cast/common/vast_ads_request.dart';
5 :
6 : ///Represents a break clip (e.g. a clip of an ad during an ad break)
7 :
8 : class CastBreakClips {
9 : ///URL of the page that the sender will display,
10 : ///when the end user clicks the link on the sender
11 : ///UI, while the receiver is playing this clip.
12 :
13 : final String? clickThroughUrl;
14 :
15 : /// The URL or content ID of the break media playing on the receiver.
16 :
17 : final String? contentId;
18 :
19 : ///The content MIME type.
20 : final String? contentType;
21 :
22 : ///Optional break media URL, to allow using contentId
23 : ///for the real ID. If contentUrl is provided, it will
24 : /// be used as the media URL, otherwise
25 : /// the contentId will be used as the media URL.
26 :
27 : final String? contentUrl;
28 :
29 : ///Application-specific break clip data.
30 : final Map<String, dynamic>? customData;
31 :
32 : ///Duration of a break clip in seconds.
33 : final Duration? duration;
34 :
35 : ///The format of the HLS media segment.
36 : final CastHlsSegmentFormat? hlsSegmentFormat;
37 :
38 : ///Unique ID of break clip.
39 : final String id;
40 :
41 : /// URL of content that the sender will
42 : /// display while the receiver is playing this clip.
43 :
44 : final String? posterUrl;
45 :
46 : ///Title of a break clip. Sender might display this on its screen, if provided.
47 : final String? title;
48 :
49 : ///VAST ad request configuration. Used if contentId or contentUrl is not provided.
50 : final VastAdsRequest vastAdsRequest;
51 :
52 : ///The time in seconds when this break clip becomes skippable.
53 : /// 5 means that end user can skip this break clip after 5 seconds.
54 : /// If this field is not defined or is a negative value, it means that
55 : /// current break clip is not shippable.
56 :
57 : final Duration? whenSkippable;
58 :
59 : /// Creates a new [CastBreakClips] instance.
60 : ///
61 : /// [clickThroughUrl] - URL of the page that the sender will display when clicked.
62 : /// [contentId] - The content ID of the break media.
63 : /// [contentType] - The content MIME type.
64 : /// [contentUrl] - Optional break media URL.
65 : /// [customData] - Application-specific break clip data.
66 : /// [duration] - Duration of a break clip in seconds.
67 : /// [hlsSegmentFormat] - The format of the HLS media segment.
68 : /// [id] - Unique ID of break clip, required.
69 : /// [posterUrl] - URL of content that the sender will display.
70 : /// [title] - Title of a break clip.
71 : /// [vastAdsRequest] - VAST ad request configuration, required.
72 : /// [whenSkippable] - The time in seconds when this break clip becomes skippable.
73 0 : CastBreakClips({
74 : this.clickThroughUrl,
75 : this.contentId,
76 : this.contentType,
77 : this.contentUrl,
78 : this.customData,
79 : this.duration,
80 : this.hlsSegmentFormat,
81 : required this.id,
82 : this.posterUrl,
83 : this.title,
84 : required this.vastAdsRequest,
85 : this.whenSkippable,
86 : });
87 :
88 : /// Converts the break clip object to a map for serialization.
89 0 : Map<String, dynamic> toMap() {
90 0 : return {
91 0 : 'clickThroughUrl': clickThroughUrl,
92 0 : 'contentId': contentId,
93 0 : 'contentType': contentType,
94 0 : 'contentUrl': contentUrl,
95 0 : 'customData': customData,
96 0 : 'duration': duration?.inSeconds,
97 0 : 'hlsSegmentFormat': hlsSegmentFormat?.name,
98 0 : 'id': id,
99 0 : 'posterUrl': posterUrl,
100 0 : 'title': title,
101 0 : 'vastAdsRequest': vastAdsRequest.toMap(),
102 0 : 'whenSkippable': whenSkippable?.inSeconds,
103 : };
104 : }
105 :
106 : /// Creates a [CastBreakClips] instance from a map.
107 : ///
108 : /// [map] - The map to create the instance from.
109 0 : factory CastBreakClips.fromMap(Map<String, dynamic> map) {
110 0 : return CastBreakClips(
111 0 : clickThroughUrl: map['clickThroughUrl'],
112 0 : contentId: map['contentId'],
113 0 : contentType: map['contentType'],
114 0 : contentUrl: map['contentUrl'],
115 0 : customData: Map<String, dynamic>.from(map['customData']),
116 0 : duration: map['duration'] != null
117 0 : ? Duration(seconds: map['duration'].round())
118 : : null,
119 0 : hlsSegmentFormat: map['hlsSegmentFormat'] != null
120 0 : ? CastHlsSegmentFormat.fromMap(map['hlsSegmentFormat'])
121 : : null,
122 0 : id: map['id'] ?? '',
123 0 : posterUrl: map['posterUrl'],
124 0 : title: map['title'],
125 0 : vastAdsRequest: VastAdsRequest.fromMap(map['vastAdsRequest']),
126 0 : whenSkippable: map['whenSkippable'] != null
127 0 : ? Duration(seconds: map['whenSkippable'].round())
128 : : null,
129 : );
130 : }
131 :
132 : /// Converts the [CastBreakClips] to a JSON string.
133 : ///
134 : /// Returns a JSON string representation of this object.
135 0 : String toJson() => json.encode(toMap());
136 :
137 : /// Creates a [CastBreakClips] from a JSON string.
138 : ///
139 : /// [source] - The JSON string to create the instance from.
140 0 : factory CastBreakClips.fromJson(String source) =>
141 0 : CastBreakClips.fromMap(json.decode(source));
142 : }
|