Timeline Events
fl-stream-timeline
library facilitates streaming real-time events for an on-going live stream to enable rich, interactive Live experiences.
Create StreamTimelineManager
StreamTimeline Configuration
Name | Required | Description |
---|---|---|
leagueName | true | The name of the leagues (case sensitive) |
gameId | true | The unique identifier for the game. |
spoiler | false | Indicates if the game events should be emitted ahead of the player watch position. |
val streamTimelineConfig = StreamTimelineConfig("NHL", "2022010075", false)
val streamTimelineManager = StreamTimelineFactory.createStreamTimelineManager(streamTimelineConfig, player, logger)
Refer Firebase setup (Follow only first three steps.) to add the configuration file to the project.
Firebase charges for document reads and writes, so we recommend creating the TimelineManager lazily.
Check If Timeline Events Exist
To check whether timeline events are available for the given gameId
, use:
streamTimelineManager.isPlayerEventsSubscriptionAvailable()
Setup subscription to Timeline Events
To setup the subscription for stream timeline events, use:
val result = streamTimelineManager.subscribeToPlayerEvents()
The subscribeToPlayerEvents
API will return an Error
when setup fails.
:::note
StreamTimelineManager
publishes events only when subscribeToPlayerEvents API is invoked and successful.
:::
Listening to Timeline events
Once the StreamTimelineManager
is created, real-time stream timeline events can be received on the Player
instance.
Game Info
The Game metadata is made available via StreamTimelineEvent.GAME_INFO
event.
override fun onEventReceived(
streamTimelineEvent: StreamTimelineEvent,
suggestedAction: Action,
streamTimelineEventMetadata: StreamTimelineEventMetadata?) {
when(streamTimelineEvent) {
StreamTimelineEvent.GAME_INFO -> {
streamTimelineMetadata as StreamTimelineEventsMetadata
logger.trace { "game info is ${streamTimelineMetadata.events}" }
}
}
}
JSONSchema - Game Info
{
"id": {
"type": "string"
},
"matchNumber": {
"type": "string"
},
"season": {
"type": "string"
},
"series": {
"type": "string"
},
"scheduledStart": {
"type": "string",
"format": "date-time"
},
"timestamp": {
"type": "string",
"format": "date-time"
},
"venue_id": {
"type": "string"
},
"venue_name": {
"type": "string"
},
"game_year": {
"type": "string"
},
"teams": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"code": {
"type": "string"
},
"id": {
"type": "string"
},
"images": {
"type": "array",
"items": [
{
"type": "string"
}
]
},
"region": {
"type": "string"
},
"name": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"home",
"visitor"
]
},
"players": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"currentTeam": {
"type": "string"
},
"name": {
"type": "string"
},
"images": {
"type": "array",
"items": [
{
"type": "string"
}
]
},
"id": {
"type": "string"
},
"number": {
"type": "string"
},
"position": {
"type": "string"
}
}
}
]
}
}
}
]
}
}
}
Game Event
The real-time game events are notified via StreamTimelineEvent.GAME_EVENT
event.streamTimelineMetadata.streamTimelineEventAction
indicates the StreamTimelineEventAction
which allows the application to respond accordingly.
override fun onEventReceived(
streamTimelineEvent: StreamTimelineEvent,
suggestedAction: Action,
streamTimelineEventMetadata: StreamTimelineEventMetadata?) {
when(streamTimelineEvent) {
StreamTimelineEvent.GAME_EVENT -> {
streamTimelineMetadata as StreamTimelineEventsMetadata
when(streamTimelineMetadata.streamTimelineEventAction) {
StreamTimelineEventAction.ADDED -> {
//put your logic here
}
StreamTimelineEventAction.MODIFIED -> {
//put your logic here
}
StreamTimelineEventAction.DELETED -> {
//put your logic here
}
}
}
}
JSONSchema - Game Event
{
"description": {
"type": "string"
},
"id": {
"type": "string",
"format": "date-time"
},
"teamInvolved": {
"type": "string",
"enum": [
"home",
"visitor"
]
},
"timestamp": {
"type": "string",
"format": "date-time"
},
"period": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"period_start",
"period_end",
"overtime_start",
"overtime_end",
"shootout_start",
"shootout_end",
"break_start",
"break_end",
"goal",
"penalty",
"penalty_shot"
]
},
"startTime": {
"type": "string",
"format": "date-time"
},
"players": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"role": {
"type": "string",
"enum": [
"winner",
"loser",
"shooter",
"goalie",
"scorer",
"assist",
"unknown",
"blocker",
"hitter",
"hittee"
]
}
}
}
]
},
"scorecard": {
"type": "object",
"properties": {
"total": {
"type": "object",
"properties": {
"visitor": {
"type": "string"
},
"home": {
"type": "string"
}
}
},
"goals_by_period": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"visitor": {
"type": "string"
},
"home": {
"type": "string"
},
"period": {
"type": "string"
}
}
}
]
}
}
}
}
Stop Listening to Timeline Events
Shutdown the timeline manager when closing the player or when you are no longer interested in listening stream timeline events.
streamTimelineManager.shutdown()