|
| 1 | +// Copyright 2013 The Flutter Authors |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'platform_interface/platform_interface.dart'; |
| 6 | + |
| 7 | +/// Data object representing a single ad. |
| 8 | +class Ad { |
| 9 | + /// Constructs an [Ad] from a specific platform implementation. |
| 10 | + Ad.fromPlatform(this.platform); |
| 11 | + |
| 12 | + /// Implementation of [PlatformAd] for the current platform. |
| 13 | + final PlatformAd platform; |
| 14 | + |
| 15 | + /// The ad ID as specified in the VAST response. |
| 16 | + String get adId => platform.adId; |
| 17 | + |
| 18 | + /// The pod metadata object. |
| 19 | + AdPodInfo get adPodInfo => AdPodInfo.fromPlatform(platform.adPodInfo); |
| 20 | + |
| 21 | + /// The ad system as specified in the VAST response. |
| 22 | + String get adSystem => platform.adSystem; |
| 23 | + |
| 24 | + /// The IDs of the ads' creatives, starting with the first wrapper ad. |
| 25 | + List<String> get wrapperCreativeIds => platform.wrapperCreativeIds; |
| 26 | + |
| 27 | + /// The wrapper ad IDs as specified in the VAST response. |
| 28 | + List<String> get wrapperIds => platform.wrapperIds; |
| 29 | + |
| 30 | + /// The wrapper ad systems as specified in the VAST response. |
| 31 | + List<String> get wrapperSystems => platform.wrapperSystems; |
| 32 | + |
| 33 | + /// The advertiser name as defined by the serving party. |
| 34 | + String get advertiserName => platform.advertiserName; |
| 35 | + |
| 36 | + /// The companions for the current ad while using DAI. |
| 37 | + /// |
| 38 | + /// Returns an empty list in any other scenario. |
| 39 | + List<CompanionAd> get companionAds => List<CompanionAd>.unmodifiable( |
| 40 | + platform.companionAds.map(CompanionAd.fromPlatform), |
| 41 | + ); |
| 42 | + |
| 43 | + /// The content type of the currently selected creative, or null if no |
| 44 | + /// creative is selected or the content type is unavailable. |
| 45 | + String? get contentType => platform.contentType; |
| 46 | + |
| 47 | + /// The ISCI (Industry Standard Commercial Identifier) code for an ad. |
| 48 | + String get creativeAdId => platform.creativeAdId; |
| 49 | + |
| 50 | + /// The ID of the selected creative for the ad, |
| 51 | + String get creativeId => platform.creativeId; |
| 52 | + |
| 53 | + /// The first deal ID present in the wrapper chain for the current ad, |
| 54 | + /// starting from the top. |
| 55 | + String get dealId => platform.dealId; |
| 56 | + |
| 57 | + /// The description of this ad from the VAST response. |
| 58 | + String? get description => platform.description; |
| 59 | + |
| 60 | + /// The duration of the ad. |
| 61 | + Duration? get duration => platform.duration; |
| 62 | + |
| 63 | + /// The width of the selected creative if non-linear, else returns 0. |
| 64 | + int get width => platform.width; |
| 65 | + |
| 66 | + /// The height of the selected creative if non-linear, else returns 0. |
| 67 | + int get height => platform.height; |
| 68 | + |
| 69 | + /// The playback time before the ad becomes skippable. |
| 70 | + /// |
| 71 | + /// The value is null for non-skippable ads, or if the value is unavailable. |
| 72 | + Duration? get skipTimeOffset => platform.skipTimeOffset; |
| 73 | + |
| 74 | + /// The URL associated with the survey for the given ad. |
| 75 | + String? get surveyUrl => platform.surveyUrl; |
| 76 | + |
| 77 | + /// The title of this ad from the VAST response. |
| 78 | + String? get title => platform.title; |
| 79 | + |
| 80 | + /// The custom parameters associated with the ad at the time of ad |
| 81 | + /// trafficking. |
| 82 | + String get traffickingParameters => platform.traffickingParameters; |
| 83 | + |
| 84 | + /// The set of ad UI elements rendered by the IMA SDK for this ad. |
| 85 | + Set<AdUIElement> get uiElements => platform.uiElements; |
| 86 | + |
| 87 | + /// The list of all universal ad IDs for this ad. |
| 88 | + List<UniversalAdId> get universalAdIds => List<UniversalAdId>.unmodifiable( |
| 89 | + platform.universalAdIds.map(UniversalAdId.fromPlatform), |
| 90 | + ); |
| 91 | + |
| 92 | + /// The VAST bitrate in Kbps of the selected creative. |
| 93 | + int get vastMediaBitrate => platform.vastMediaBitrate; |
| 94 | + |
| 95 | + /// The VAST media height in pixels of the selected creative. |
| 96 | + int get vastMediaHeight => platform.vastMediaHeight; |
| 97 | + |
| 98 | + /// The VAST media width in pixels of the selected creative. |
| 99 | + int get vastMediaWidth => platform.vastMediaWidth; |
| 100 | + |
| 101 | + /// Indicates whether the ad’s current mode of operation is linear or |
| 102 | + /// non-linear. |
| 103 | + bool get isLinear => platform.isLinear; |
| 104 | + |
| 105 | + /// Indicates whether the ad can be skipped by the user. |
| 106 | + bool get isSkippable => platform.isSkippable; |
| 107 | +} |
| 108 | + |
| 109 | +/// Simple data object containing podding metadata. |
| 110 | +class AdPodInfo { |
| 111 | + /// Constructs an [AdPodInfo] from a specific platform implementation. |
| 112 | + AdPodInfo.fromPlatform(this.platform); |
| 113 | + |
| 114 | + /// Implementation of [PlatformAdPodInfo] for the current platform. |
| 115 | + final PlatformAdPodInfo platform; |
| 116 | + |
| 117 | + /// The position of the ad within the pod. |
| 118 | + /// |
| 119 | + /// The value returned is one-based, for example, 1 of 2, 2 of 2, etc. If the |
| 120 | + /// ad is not part of a pod, this will return 1. |
| 121 | + int get adPosition => platform.adPosition; |
| 122 | + |
| 123 | + /// The maximum duration of the pod. |
| 124 | + /// |
| 125 | + /// For unknown duration, null. |
| 126 | + Duration? get maxDuration => platform.maxDuration; |
| 127 | + |
| 128 | + /// Returns the index of the ad pod. |
| 129 | + /// |
| 130 | + /// Client side: For a preroll pod, returns 0. For midrolls, returns 1, 2,…, |
| 131 | + /// N. For a postroll pod, returns -1. Defaults to 0 if this ad is not part of |
| 132 | + /// a pod, or this pod is not part of a playlist. |
| 133 | + /// |
| 134 | + /// DAI VOD: Returns the index of the ad pod. For a preroll pod, returns 0. |
| 135 | + /// For midrolls, returns 1, 2,…,N. For a postroll pod, returns N+1…N+X. |
| 136 | + /// Defaults to 0 if this ad is not part of a pod, or this pod is not part of |
| 137 | + /// a playlist. |
| 138 | + /// |
| 139 | + /// DAI live stream: For a preroll pod, returns 0. For midrolls, returns the |
| 140 | + /// break ID. Returns -2 if pod index cannot be determined (internal error). |
| 141 | + int get podIndex => platform.podIndex; |
| 142 | + |
| 143 | + /// The content time offset at which the current ad pod was scheduled. |
| 144 | + /// |
| 145 | + /// For preroll pod, 0 is returned. For midrolls, the scheduled time is |
| 146 | + /// returned. For postroll, -1 is returned. Defaults to 0 if this ad is not |
| 147 | + /// part of a pod, or the pod is not part of an ad playlist. |
| 148 | + Duration get timeOffset => platform.timeOffset; |
| 149 | + |
| 150 | + /// Total number of ads in the pod this ad belongs to, including bumpers. |
| 151 | + /// |
| 152 | + /// Will be 1 for standalone ads. |
| 153 | + int get totalAds => platform.totalAds; |
| 154 | + |
| 155 | + /// Specifies whether the ad is a bumper. |
| 156 | + /// |
| 157 | + /// Bumpers are short videos used to open and close ad breaks. |
| 158 | + bool get isBumper => platform.isBumper; |
| 159 | +} |
| 160 | + |
| 161 | +/// An object that holds data corresponding to the companion Ad. |
| 162 | +class CompanionAd { |
| 163 | + /// Constructs a [CompanionAd] from a specific platform implementation. |
| 164 | + CompanionAd.fromPlatform(this.platform); |
| 165 | + |
| 166 | + /// Implementation of [PlatformCompanionAd] for the current platform. |
| 167 | + final PlatformCompanionAd platform; |
| 168 | + |
| 169 | + /// The width of the companion in pixels. |
| 170 | + /// |
| 171 | + /// `null` if unavailable. |
| 172 | + int? get width => platform.width; |
| 173 | + |
| 174 | + /// The height of the companion in pixels. |
| 175 | + /// |
| 176 | + /// `null` if unavailable. |
| 177 | + int? get height => platform.height; |
| 178 | + |
| 179 | + /// The API needed to execute this ad, or null if unavailable. |
| 180 | + String? get apiFramework => platform.apiFramework; |
| 181 | + |
| 182 | + /// The URL for the static resource of this companion. |
| 183 | + String? get resourceValue => platform.resourceValue; |
| 184 | +} |
| 185 | + |
| 186 | +/// Simple data object containing universal ad ID information. |
| 187 | +class UniversalAdId { |
| 188 | + /// Constructs an [UniversalAdId] from a specific platform implementation. |
| 189 | + UniversalAdId.fromPlatform(this.platform); |
| 190 | + |
| 191 | + /// Implementation of [PlatformUniversalAdId] for the current platform. |
| 192 | + final PlatformUniversalAdId platform; |
| 193 | + |
| 194 | + /// The universal ad ID value. |
| 195 | + /// |
| 196 | + /// This will be null if it isn’t defined by the ad. |
| 197 | + String? get adIdValue => platform.adIdValue; |
| 198 | + |
| 199 | + /// The universal ad ID registry with which the value is registered. |
| 200 | + /// |
| 201 | + /// This will be null if it isn’t defined by the ad. |
| 202 | + String? get adIdRegistry => platform.adIdRegistry; |
| 203 | +} |
0 commit comments