Skip to content

Commit

Permalink
fix(CMCD): allow session id to be configured (#6192)
Browse files Browse the repository at this point in the history
  • Loading branch information
littlespex authored and avelad committed Feb 1, 2024
1 parent a22967a commit 2166cfa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
16 changes: 3 additions & 13 deletions lib/util/cmcd_manager.js
Expand Up @@ -27,13 +27,6 @@ shaka.util.CmcdManager = class {
/** @private {?shaka.extern.CmcdConfiguration} */
this.config_ = config;

/**
* Session ID
*
* @private {string}
*/
this.sid_ = '';

/**
* Streaming format
*
Expand Down Expand Up @@ -65,9 +58,6 @@ shaka.util.CmcdManager = class {
*/
configure(config) {
this.config_ = config;
if (this.config_.sessionId && this.config_.sessionId != this.sid_) {
this.sid_ = '';
}
}

/**
Expand Down Expand Up @@ -295,13 +285,13 @@ shaka.util.CmcdManager = class {
* @private
*/
createData_() {
if (!this.sid_) {
this.sid_ = this.config_.sessionId || window.crypto.randomUUID();
if (!this.config_.sessionId) {
this.config_.sessionId = window.crypto.randomUUID();
}
return {
v: shaka.util.CmcdManager.Version,
sf: this.sf_,
sid: this.sid_,
sid: this.config_.sessionId,
cid: this.config_.contentId,
mtp: this.playerInterface_.getBandwidthEstimate() / 1000,
};
Expand Down
30 changes: 27 additions & 3 deletions test/util/cmcd_manager_unit.js
Expand Up @@ -8,8 +8,10 @@ describe('CmcdManager', () => {
const CmcdManager = shaka.util.CmcdManager;
const uuidRegex =
'[A-F\\d]{8}-[A-F\\d]{4}-4[A-F\\d]{3}-[89AB][A-F\\d]{3}-[A-F\\d]{12}';
const sidRegex = new RegExp(`sid%3D%22${uuidRegex}%22`, 'i');
const sessionId = 'c936730c-031e-4a73-976f-92bc34039c60';
const data = {
'sid': 'c936730c-031e-4a73-976f-92bc34039c60',
'sid': sessionId,
'cid': 'xyz',
'su': false,
'nor': '../testing/3.m4v',
Expand Down Expand Up @@ -186,8 +188,30 @@ describe('CmcdManager', () => {
const r = ObjectUtils.cloneObject(request);

cmcdManager.applyManifestData(r, manifestInfo);
const regex = new RegExp(`sid%3D%22${uuidRegex}%22`, 'i');
expect(regex.test(r.uris[0])).toBe(true);

expect(sidRegex.test(r.uris[0])).toBe(true);
});

it('generates a session id via configure', () => {
config.sessionId = sid;
cmcdManager = new CmcdManager(playerInterface, config);

const r = ObjectUtils.cloneObject(request);
cmcdManager.applyManifestData(r, manifestInfo);
expect(r.uris[0].includes(sid)).toBe(true);

config.sessionId = sessionId;
cmcdManager.configure(config);
cmcdManager.applyManifestData(r, manifestInfo);
expect(r.uris[0].includes(sid)).toBe(false);
expect(r.uris[0].includes(sessionId)).toBe(true);

config.sessionId = '';
cmcdManager.configure(config);
cmcdManager.applyManifestData(r, manifestInfo);
expect(r.uris[0].includes(sid)).toBe(false);
expect(r.uris[0].includes(sessionId)).toBe(false);
expect(sidRegex.test(r.uris[0])).toBe(true);
});
});

Expand Down

0 comments on commit 2166cfa

Please sign in to comment.