sud.createRewardedVideoAd
Creates a rewarded video ad object. Each call returns a new instance.
createRewardedVideoAd(params: {
adUnitId: string;
/** Whether to enable multiton mode, defaults to true (reserved parameter, not yet in effect) */
multiton?: boolean;
/** Whether to disable the fallback share page, defaults to false (reserved parameter, not yet in effect) */
disableFallbackSharePage?: boolean;
}): RewardedVideoAd;Parameters
Object object
| Property | Type | Required | Description |
|---|---|---|---|
| adUnitId | string | Yes | Ad unit ID configured in the SUD OpenPaaS console |
| multiton | boolean | No | Whether to enable multiton mode, defaults to true (reserved parameter, not yet in effect) |
| disableFallbackSharePage | boolean | No | Whether to disable the fallback share page, defaults to false (reserved parameter, not yet in effect) |
Return Value
RewardedVideoAd ad object.
Methods
| Method | Return value | Description |
|---|---|---|
load() | Promise<void> | Starts loading the ad |
show() | Promise<void> | Requests that the ad be shown |
destroy() | void | Destroys the ad; the object cannot be reused |
The Promises returned by load() and show() report only the method-call result. Use onLoad for successful loading, onError for loading or display failures, and onClose for closing.
load() is subject to request frequency limits. When a limit is reached, onError reports the error code (errCode) and message (errMsg).
Events
| Method | Description |
|---|---|
onLoad(listener) | Listens for a successful ad load |
offLoad(listener) | Removes the specified load listener |
onError(listener) | Listens for ad loading or display failures |
offError(listener) | Removes the specified error listener |
onClose(listener) | Listens for the ad to close |
offClose(listener) | Removes the specified close listener |
onLoad Callback Parameters
The onLoad listener receives the following object:
| Property | Type | Description |
|---|---|---|
| useFallbackSharePage | boolean | Whether the rewarded ad share page is used for this display (reserved parameter, not yet in effect) |
onError Callback Parameters
The onError listener receives the following object:
| Property | Type | Description |
|---|---|---|
| errCode | number | See ad error codes |
| errMsg | string | Error message |
onClose Callback Parameters
The onClose listener receives the following object:
| Property | Type | Description |
|---|---|---|
| isEnded | boolean | Whether this ad met the reward condition |
true can enter the game's reward flow, while false must not grant a reward. Closing alone is not a reward signal. Handle the reward result at most once per display.
Example
Create and load the ad on reward-scene entry. Call onRewardButtonClick() only after the user clicks the watch-ad button; grant the reward only when onClose returns isEnded === true.
const rewardedVideoAd = sud.createRewardedVideoAd({
adUnitId: 'adunit-xxxxxxxx',
// Reserved parameters, not yet in effect
multiton: true,
disableFallbackSharePage: false,
});
let ready = false;
let disposed = false;
let showRequested = false;
function onLoad(res) {
if (disposed) return;
// res.useFallbackSharePage is a reserved parameter, not yet in effect
ready = true;
}
function onError(err) {
if (disposed) return;
console.error('Rewarded video ad failed', err);
onRewardSceneExit();
}
function onClose(result) {
if (disposed) return;
onRewardSceneExit();
if (result?.isEnded === true) {
console.log('Reward condition met');
// Apply the game's reward once here.
}
}
function onRewardButtonClick() {
if (disposed || !ready || showRequested) return;
showRequested = true;
ready = false;
rewardedVideoAd.show().catch(onError);
}
function onRewardSceneExit() {
if (disposed) return;
disposed = true;
ready = false;
rewardedVideoAd.offLoad(onLoad);
rewardedVideoAd.offError(onError);
rewardedVideoAd.offClose(onClose);
rewardedVideoAd.destroy();
}
rewardedVideoAd.onLoad(onLoad);
rewardedVideoAd.onError(onError);
rewardedVideoAd.onClose(onClose);
rewardedVideoAd.load().catch(onError);Bind onRewardSceneExit() to scene exit. For the complete flow, see game developer examples.
