Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add manifestupdated event #5602

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion externs/shaka/manifest_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ shaka.extern.ManifestParser = class {
* isAutoLowLatencyMode: function():boolean,
* enableLowLatencyMode: function(),
* updateDuration: function(),
* newDrmInfo: function(shaka.extern.Stream)
* newDrmInfo: function(shaka.extern.Stream),
* onManifestUpdated: function()
* }}
*
* @description
Expand Down Expand Up @@ -144,6 +145,8 @@ shaka.extern.ManifestParser = class {
* @property {function(shaka.extern.Stream)} newDrmInfo
* Inform the player of new DRM info that needs to be processed for the given
* stream.
* @property {function()} onManifestUpdated
* Should be called when the manifest is updated.
* @exportDoc
*/
shaka.extern.ManifestParser.PlayerInterface;
Expand Down
2 changes: 2 additions & 0 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,8 @@ shaka.dash.DashParser = class {
return;
}

this.playerInterface_.onManifestUpdated();

this.setUpdateTimer_(updateDelay);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3678,6 +3678,13 @@ shaka.hls.HlsParser = class {
// Try again very soon.
this.updatePlaylistTimer_.tickAfter(/* seconds= */ 0.1);
}

// Detect a call to stop()
if (!this.playerInterface_) {
return;
}

this.playerInterface_.onManifestUpdated();
}


Expand Down
1 change: 1 addition & 0 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ shaka.offline.Storage = class {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};

parser.configure(config.manifest);
Expand Down
17 changes: 17 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,18 @@ goog.requireType('shaka.routing.Payload');
*/


/**
* @event shaka.Player.ManifestUpdatedEvent
* @description Fired after the manifest has been updated (live streams).
* @property {string} type
* 'manifestupdated'
* @property {boolean} isLive
* True when the playlist is live. Useful to detect transition from live
* to static playlist..
* @exportDoc
*/


/**
* @event shaka.Player.MetadataEvent
* @description Triggers after metadata associated with the stream is found.
Expand Down Expand Up @@ -1904,6 +1916,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.processDrmInfos_(currentDrmInfo.keySystem, stream);
}
},
onManifestUpdated: () => {
const eventName = shaka.util.FakeEvent.EventName.ManifestUpdated;
const data = (new Map()).set('isLive', this.isLive());
this.dispatchEvent(this.makeEvent_(eventName, data));
},
};

const startTime = Date.now() / 1000;
Expand Down
1 change: 1 addition & 0 deletions lib/util/fake_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ shaka.util.FakeEvent.EventName = {
Loaded: 'loaded',
Loading: 'loading',
ManifestParsed: 'manifestparsed',
ManifestUpdated: 'manifestupdated',
MediaQualityChanged: 'mediaqualitychanged',
Metadata: 'metadata',
OnStateChange: 'onstatechange',
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_content_protection_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('DashParser ContentProtection', () => {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};

const actual = await dashParser.start(
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('DashParser Live', () => {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
});

Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('DashParser Manifest', () => {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
});

Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_segment_base_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('DashParser SegmentBase', () => {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
});

Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_segment_list_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ describe('DashParser SegmentList', () => {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
const manifest = await dashParser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].video;
Expand Down
1 change: 1 addition & 0 deletions test/dash/dash_parser_segment_template_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('DashParser SegmentTemplate', () => {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
});

Expand Down
1 change: 1 addition & 0 deletions test/hls/hls_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('HlsParser live', () => {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};

parser = new shaka.hls.HlsParser();
Expand Down
1 change: 1 addition & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('HlsParser', () => {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: shaka.test.Util.spyFunc(newDrmInfoSpy),
onManifestUpdated: () => {},
};

parser = new shaka.hls.HlsParser();
Expand Down
1 change: 1 addition & 0 deletions test/mss/mss_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('MssParser Manifest', () => {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
});

Expand Down
2 changes: 2 additions & 0 deletions test/test/util/dash_parser_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ shaka.test.Dash = class {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
const manifest = await dashParser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].video;
Expand Down Expand Up @@ -81,6 +82,7 @@ shaka.test.Dash = class {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
const p = dashParser.start('dummy://foo', playerInterface);
await expectAsync(p).toBeRejectedWith(
Expand Down
2 changes: 2 additions & 0 deletions test/test/util/mss_parser_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ shaka.test.Mss = class {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
const manifest = await mssParser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].audio;
Expand Down Expand Up @@ -81,6 +82,7 @@ shaka.test.Mss = class {
enableLowLatencyMode: () => {},
updateDuration: () => {},
newDrmInfo: (stream) => {},
onManifestUpdated: () => {},
};
const p = mssParser.start('dummy://foo', playerInterface);
await expectAsync(p).toBeRejectedWith(
Expand Down