Skip to content

Commit

Permalink
Merge pull request #309 from bitmovin/onDownloadFinishedEvent
Browse files Browse the repository at this point in the history
Implement source event `DownloadFinishedEvent`
  • Loading branch information
123mpozzi authored Nov 2, 2023
2 parents ba557b3 + 9e45535 commit 3361e80
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- `LiveConfig.minTimeshiftBufferDepth` to control the minimum buffer depth of a stream needed to enable time shifting.
- `Player.buffer` to control buffer preferences and to query the current buffer state
- `DownloadFinishedEvent` to signal when the download of specific content has finished

## [0.13.0] (2023-10-20)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private val EVENT_CLASS_TO_REACT_NATIVE_NAME_MAPPING = mapOf(
SourceEvent.AudioTrackAdded::class to "audioAdded",
SourceEvent.AudioTrackChanged::class to "audioChanged",
SourceEvent.AudioTrackRemoved::class to "audioRemoved",
SourceEvent.DownloadFinished::class to "downloadFinished",
PlayerEvent.AdBreakFinished::class to "adBreakFinished",
PlayerEvent.AdBreakStarted::class to "adBreakStarted",
PlayerEvent.AdClicked::class to "adClicked",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class RNPlayerViewManager(private val context: ReactApplicationContext) : Simple
"subtitleAdded" to "onSubtitleAdded",
"subtitleChanged" to "onSubtitleChanged",
"subtitleRemoved" to "onSubtitleRemoved",
"downloadFinished" to "onDownloadFinished",
"pictureInPictureAvailabilityChanged" to "onPictureInPictureAvailabilityChanged",
"pictureInPictureEnter" to "onPictureInPictureEnter",
"pictureInPictureExit" to "onPictureInPictureExit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,18 @@ class JsonConverter {
json.putMap("newSubtitleTrack", fromSubtitleTrack(event.newSubtitleTrack))
}

is SourceEvent.DownloadFinished -> {
json.putDouble("downloadTime", event.downloadTime)
json.putString("requestType", event.downloadType.toString())
json.putInt("httpStatus", event.httpStatus)
json.putBoolean("isSuccess", event.isSuccess)
event.lastRedirectLocation?.let {
json.putString("lastRedirectLocation", it)
}
json.putDouble("size", event.size.toDouble())
json.putString("url", event.url)
}

else -> {
// Event is not supported yet or does not have any additional data
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ fun SourceEvent.getName(): String = when (this) {
is SourceEvent.SubtitleTrackAdded -> "onSubtitleAdded"
is SourceEvent.SubtitleTrackChanged -> "onSubtitleChanged"
is SourceEvent.SubtitleTrackRemoved -> "onSubtitleRemoved"
is SourceEvent.DownloadFinished -> "onDownloadFinished"
else -> "onSource${this.javaClass.simpleName}"
}
19 changes: 19 additions & 0 deletions ios/Event+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,22 @@ extension CastWaitingForDeviceEvent {
}
}
#endif

extension DownloadFinishedEvent {
func toJSON() -> [AnyHashable: Any] {
var json: [AnyHashable: Any] = [
"name": name,
"timestamp": timestamp,
"downloadTime": downloadTime,
"requestType": requestType.rawValue,
"httpStatus": httpStatus,
"isSuccess": successful,
"size": size,
"url": url.absoluteString
]
if let lastRedirectLocation {
json["lastRedirectLocation"] = lastRedirectLocation.absoluteString
}
return json
}
}
4 changes: 4 additions & 0 deletions ios/RNPlayerView+PlayerListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ extension RNPlayerView: PlayerListener {
onSubtitleChanged?(event.toJSON())
}

public func onDownloadFinished(_ event: DownloadFinishedEvent, player: Player) {
onDownloadFinished?(event.toJSON())
}

public func onAdBreakFinished(_ event: AdBreakFinishedEvent, player: Player) {
onAdBreakFinished?(event.toJSON())
}
Expand Down
1 change: 1 addition & 0 deletions ios/RNPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class RNPlayerView: UIView {
@objc var onSubtitleAdded: RCTBubblingEventBlock?
@objc var onSubtitleRemoved: RCTBubblingEventBlock?
@objc var onSubtitleChanged: RCTBubblingEventBlock?
@objc var onDownloadFinished: RCTBubblingEventBlock?
@objc var onPictureInPictureEnter: RCTBubblingEventBlock?
@objc var onPictureInPictureEntered: RCTBubblingEventBlock?
@objc var onPictureInPictureExit: RCTBubblingEventBlock?
Expand Down
1 change: 1 addition & 0 deletions ios/RNPlayerViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ @interface RCT_EXTERN_REMAP_MODULE(NativePlayerView, RNPlayerViewManager, RCTVie
RCT_EXPORT_VIEW_PROPERTY(onSubtitleAdded, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onSubtitleRemoved, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onSubtitleChanged, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onDownloadFinished, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPictureInPictureEnter, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPictureInPictureEntered, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPictureInPictureExit, RCTBubblingEventBlock)
Expand Down
5 changes: 5 additions & 0 deletions src/components/PlayerView/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
TimeChangedEvent,
UnmutedEvent,
VideoPlaybackQualityChangedEvent,
DownloadFinishedEvent,
} from '../../events';

/**
Expand Down Expand Up @@ -170,6 +171,10 @@ interface EventProps {
* Event emitted when the player is destroyed.
*/
onDestroy: DestroyEvent;
/**
* Emitted when a download was finished.
*/
onDownloadFinished: DownloadFinishedEvent;
/**
* All events emitted by the player.
*/
Expand Down
1 change: 1 addition & 0 deletions src/components/PlayerView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export function PlayerView({
onTimeChanged={proxy(props.onTimeChanged)}
onUnmuted={proxy(props.onUnmuted)}
onVideoPlaybackQualityChanged={proxy(props.onVideoPlaybackQualityChanged)}
onDownloadFinished={proxy(props.onDownloadFinished)}
/>
);
}
55 changes: 55 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,58 @@ export interface CastWaitingForDeviceEvent extends Event {
*/
castPayload: CastPayload;
}

/**
* Available HTTP request types.
*/
export enum HttpRequestType {
ManifestDash = 'manifest/dash',
ManifestHlsMaster = 'manifest/hls/master',
ManifestHlsVariant = 'manifest/hls/variant',
ManifestSmooth = 'manifest/smooth',
MediaProgressive = 'media/progressive',
MediaAudio = 'media/audio',
MediaVideo = 'media/video',
MediaSubtitles = 'media/subtitles',
MediaThumbnails = 'media/thumbnails',
DrmLicenseFairplay = 'drm/license/fairplay',
DrmCertificateFairplay = 'drm/certificate/fairplay',
DrmLicenseWidevine = 'drm/license/widevine',
KeyHlsAes = 'key/hls/aes',
Unknown = 'unknown',
}

/**
* Emitted when a download was finished.
*/
export interface DownloadFinishedEvent extends Event {
/**
* The time needed to finish the request, in seconds.
*/
downloadTime: number;
/**
* Which type of request this was.
*/
requestType: HttpRequestType;
/**
* The HTTP status code of the request.
* If opening the connection failed, a value of `0` is returned.
*/
httpStatus: number;
/**
* If the download was successful.
*/
isSuccess: boolean;
/**
* The last redirect location, or `null` if no redirect happened.
*/
lastRedirectLocation?: String;
/**
* The size of the downloaded data, in bytes.
*/
size: number;
/**
* The URL of the request.
*/
url: String;
}

0 comments on commit 3361e80

Please sign in to comment.