Campaign Lifecycle
Everything is configured in the Vio Dashboard — the SDK discovers campaigns automatically at runtime. No campaign IDs in your app code.
How It Works
Dashboard SDK
───────── ───
Broadcast setBroadcastContext(broadcastId)
└── externalId → discoverCampaigns(broadcastId)
└── Campaign ├── currentCampaign set
├── Polls ├── WebSocket /ws/:campaignId connected
├── Contests ├── Polls received via WS
└── Sponsor └── Sponsor assets appliedSetup: autoDiscover: true
Use this in your vio-config.json — no hardcoded campaign IDs:
{
"apiKey": "YOUR_API_KEY",
"campaigns": {
"webSocketBaseURL": "wss://api.vio.live",
"restAPIBaseURL": "https://api.vio.live",
"campaignApiKey": "YOUR_CAMPAIGN_API_KEY",
"autoDiscover": true
}
}Connect to a Broadcast
Call setBroadcastContext with the broadcast’s externalId as configured in the Dashboard:
import VioCore
// When user opens a stream
let context = BroadcastContext(
broadcastId: "real-madrid-vs-barcelona-2025-01-24", // = externalId in Dashboard
broadcastName: "Real Madrid vs Barcelona"
)
await CampaignManager.shared.setBroadcastContext(context)This triggers:
- API call to
GET /v1/sdk/broadcast?contentId=<broadcastId>— finds the campaign - WebSocket connects to
/ws/:campaignId - Backend sends the current state (active polls, contests) immediately
- Real-time events flow in as you scheduled them in the Dashboard
Disconnect
// When user closes the stream
CampaignManager.shared.disconnect()Campaign States
| State | When | Behavior |
|---|---|---|
| Active | Between campaign start/end dates, broadcast is live | Components shown, WS connected |
| Upcoming | Before campaign start date | campaignState = .upcoming |
| Ended | After campaign end date | Components hidden, WS disconnected |
| Paused | Dashboard manually paused | isPaused = true, components hidden |
// Check state in your UI
switch CampaignManager.shared.campaignState {
case .active:
// Show overlay
case .upcoming:
Text("Starting soon")
case .ended:
// Hide overlay
}
let isActive = CampaignManager.shared.isCampaignActiveMultiple Broadcasts
If you have multiple streams running, each call to setBroadcastContext resets to a fresh state for the new broadcast — previous polls and contests are cleared automatically.
WebSocket Events
The SDK handles these automatically:
| Event | Effect |
|---|---|
poll | Poll added/updated in EngagementManager |
contest | Contest added/updated |
shoppable_ad | Product overlay triggered |
campaign_started | Campaign activated |
campaign_ended | Components hidden, WS closed |
tweet | Tweet card added to timeline |
chat_message | Chat message received |
Next Steps
- Market Availability — Disable SDK per market
- Configuration — Full vio-config.json reference
Last updated on