监听高级 IMA 事件
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
CAF DAI SDK 与原生 CAF 广告插播时间点功能紧密集成。因此,在大多数情况下,您应使用 CAF 广告插播事件来触发日志记录或自定义功能。不过,CAF DAI SDK 提供了无法直接通过 CAF 广告插播时间点提供的其他几个事件,例如四分位跟踪事件。
想要与使用 IMA DAI SDK 的平台完全对等的发布商可能需要向 StreamManager 附加事件监听器来处理这些额外的事件。如果需要将这些事件传递给附加的发件人应用,只需通过 castContext.sendCustomMessage() 将事件转发给发件人即可。
示例:
...
streamManager.addEventListener(ima.cast.dai.api.StreamEvent.Type.MIDPOINT, (event) => {
// add custom receiver handler code here, if necessary
console.log(event);
// broadcast event to all attached senders, so they can
// run custom handler code, if necessary
const CUSTOM_CHANNEL = 'urn:x-cast:com.example.cast.mynamespace';
castContext.sendCustomMessage(CUSTOM_CHANNEL, null, event);
});
castContext.start();
...
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[[["\u003cp\u003eThe CAF DAI SDK leverages CAF Ad Break events for logging and custom functionality, recommending their use over separate implementations.\u003c/p\u003e\n"],["\u003cp\u003eFor advanced use cases like quartile tracking, the CAF DAI SDK provides additional StreamEvents beyond standard CAF Ad Break events.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure sender application compatibility, publishers can utilize \u003ccode\u003ecastContext.sendCustomMessage()\u003c/code\u003e to relay custom CAF DAI events to sender applications.\u003c/p\u003e\n"]]],["The CAF DAI SDK utilizes CAF Ad Break events for most functions, but it also provides additional events like quartile tracking. Publishers needing full parity with the IMA DAI SDK should attach event listeners to the StreamManager to handle these extra events. To pass these events to sender apps, use `castContext.sendCustomMessage()`. An example shows how to add a listener for the `MIDPOINT` event, log it, and then broadcast it to all connected senders via a custom message channel.\n"],null,["# Listen for advanced IMA events\n\nThe CAF DAI SDK integrates closely with the native [CAF Ad Breaks](/cast/docs/web_sender/advanced#ad_breaks) functionality. As such, in most cases, you should use [CAF Ad Break events](/cast/docs/web_receiver/ad_breaks#events) to trigger logging or custom functionality. However, the CAF DAI SDK offers [several additional events](/ad-manager/dynamic-ad-insertion/sdk/cast/reference/js/StreamEvent#enumeration) that are not available directly through CAF Ad Breaks, such as quartile tracking events.\n\nPublishers who want full parity with platforms using the IMA DAI SDK may need to attach event listeners to the StreamManager to handle these additional events. If it is necessary to pass these events on to the attached sender apps, simply forward the event to the sender via [castContext.sendCustomMessage()](/cast/docs/reference/web_receiver/cast.framework.CastReceiverContext#sendCustomMessage).\n\n**Example:** \n\n ...\n\n streamManager.addEventListener(ima.cast.dai.api.StreamEvent.Type.MIDPOINT, (event) =\\\u003e {\n // add custom receiver handler code here, if necessary\n console.log(event);\n // broadcast event to all attached senders, so they can\n // run custom handler code, if necessary\n const CUSTOM_CHANNEL = 'urn:x-cast:com.example.cast.mynamespace';\n castContext.sendCustomMessage(CUSTOM_CHANNEL, null, event);\n });\n\n castContext.start();\n\n ..."]]