Some checks failed
CI Pipeline / Code Quality & Typecheck (push) Waiting to run
CI Pipeline / Test Suite (macos-latest) (push) Blocked by required conditions
CI Pipeline / Test Suite (ubuntu-latest) (push) Blocked by required conditions
CI Pipeline / Test Suite (windows-latest) (push) Blocked by required conditions
CI Pipeline / Build Validation (admin) (push) Blocked by required conditions
CI Pipeline / Build Validation (desktop) (push) Blocked by required conditions
Deploy Landing Page / deploy (push) Blocked by required conditions
Deploy Landing Page / build (push) Waiting to run
Release & Packaging Pipeline / Build & Publish Admin Docker Image (push) Failing after 8s
Release & Code Signing CA Pipeline / build-and-sign-windows (push) Failing after 1m51s
Build macOS / Build & Package (macOS) (push) Failing after 4s
Build macOS / Build & Package (macOS)-1 (push) Failing after 5s
Release & Code Signing CA Pipeline / build-and-sign-macos (push) Failing after 3s
Release & Packaging Pipeline / Package macOS Desktop App (push) Failing after 4s
Release & Packaging Pipeline / Package Windows Desktop App (push) Failing after 2m28s
Release & Packaging Pipeline / Publish Official GitHub Release (push) Has been skipped
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
// apps/desktop/src/main/ipc/ads-handlers.ts
|
|
// IPC handlers for Multi-Ad Mediation, Header Bidding, and Revenue Settlement
|
|
|
|
import { ipcMain } from 'electron'
|
|
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
|
|
import { ok, err } from '@d3ro/core/errors'
|
|
import type {
|
|
AdMediationConfig,
|
|
AdMediationAuctionRequest,
|
|
AdImpressionEvent,
|
|
PublisherAccountConfig,
|
|
} from '@d3ro/core/types'
|
|
import { getAdMediationEngine } from '../services/ads/AdMediationEngine'
|
|
import { getAdSettlementService } from '../services/ads/AdSettlementService'
|
|
|
|
export function registerAdsHandlers(): void {
|
|
const engine = getAdMediationEngine()
|
|
const settlement = getAdSettlementService()
|
|
|
|
// 1. Get Mediation Config
|
|
ipcMain.handle(IPC_CHANNELS.ADS.GET_CONFIG, async () => {
|
|
return ok(engine.getConfig())
|
|
})
|
|
|
|
// 2. Set Mediation Config
|
|
ipcMain.handle(IPC_CHANNELS.ADS.SET_CONFIG, async (_event, config: Partial<AdMediationConfig>) => {
|
|
return ok(engine.setConfig(config))
|
|
})
|
|
|
|
// 3. Request Header Bidding Auction
|
|
ipcMain.handle(IPC_CHANNELS.ADS.REQUEST_AUCTION, async (_event, request: AdMediationAuctionRequest) => {
|
|
try {
|
|
const result = await engine.runAuction(request)
|
|
return ok(result)
|
|
} catch (e) {
|
|
return err('AD_AUCTION_FAILED', e instanceof Error ? e.message : String(e))
|
|
}
|
|
})
|
|
|
|
// 4. Record Impression
|
|
ipcMain.handle(IPC_CHANNELS.ADS.RECORD_IMPRESSION, async (_event, eventPayload: Omit<AdImpressionEvent, 'timestamp'>) => {
|
|
engine.recordImpression(eventPayload)
|
|
return ok(true)
|
|
})
|
|
|
|
// 5. Record Click
|
|
ipcMain.handle(IPC_CHANNELS.ADS.RECORD_CLICK, async (_event, { adId, networkId }: { adId: string; networkId: string }) => {
|
|
engine.recordClick(adId, networkId)
|
|
return ok(true)
|
|
})
|
|
|
|
// 6. Claim Rewarded Video Quota
|
|
ipcMain.handle(IPC_CHANNELS.ADS.CLAIM_REWARD, async (_event, { adId, networkId }: { adId: string; networkId: string }) => {
|
|
const result = await engine.claimReward(adId, networkId)
|
|
return ok(result)
|
|
})
|
|
|
|
// 7. Get Revenue & Settlement Stats
|
|
ipcMain.handle(IPC_CHANNELS.ADS.GET_REVENUE_STATS, async (_event, { period }: { period?: string } = {}) => {
|
|
return ok(engine.getRevenueStats(period))
|
|
})
|
|
|
|
// 8. Get Settlement Records
|
|
ipcMain.handle(IPC_CHANNELS.ADS.GET_SETTLEMENTS, async () => {
|
|
const stats = engine.getRevenueStats()
|
|
return ok(stats.settlements)
|
|
})
|
|
|
|
// 9. Request Payout
|
|
ipcMain.handle(IPC_CHANNELS.ADS.REQUEST_PAYOUT, async (_event, { settlementId }: { settlementId: string }) => {
|
|
const result = settlement.requestPayout(settlementId)
|
|
return ok(result)
|
|
})
|
|
|
|
// 10. Get/Set Publisher Account
|
|
ipcMain.handle(IPC_CHANNELS.ADS.GET_PUBLISHER_ACCOUNT, async () => {
|
|
return ok(settlement.getPublisherAccount())
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.ADS.SET_PUBLISHER_ACCOUNT, async (_event, account: Partial<PublisherAccountConfig>) => {
|
|
return ok(settlement.setPublisherAccount(account))
|
|
})
|
|
}
|