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();
...