@eyevinn/cmcd
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -182,2 +182,13 @@ "use strict"; | ||
exports.CMCDVersion = CMCDVersion; | ||
function strcmp(a, b) { | ||
if (a === b) { | ||
return 0; | ||
} | ||
else if (a > b) { | ||
return 1; | ||
} | ||
else if (a < b) { | ||
return -1; | ||
} | ||
} | ||
function create(ctor, v) { | ||
@@ -259,5 +270,22 @@ return v !== undefined ? new ctor(v) : undefined; | ||
get version() { return this._version.value; } | ||
get headers() { | ||
let hdrs = {}; | ||
Object.keys(CMCD_MAP).forEach(k => { | ||
const key = '_' + CMCD_MAP[k]; | ||
if (this[key]) { | ||
const header = this[key].header.toString(); | ||
if (!hdrs[header]) { | ||
hdrs[header] = []; | ||
} | ||
hdrs[header].push(this[key].toString()); | ||
} | ||
}); | ||
Object.keys(hdrs).forEach(k => { | ||
hdrs[k] = hdrs[k].sort((a, b) => strcmp(a, b)).join(','); | ||
}); | ||
return hdrs; | ||
} | ||
toString() { | ||
let kv = []; | ||
Object.keys(CMCD_MAP).forEach(k => { | ||
Object.keys(CMCD_MAP).sort((a, b) => strcmp(a, b)).forEach(k => { | ||
const key = '_' + CMCD_MAP[k]; | ||
@@ -264,0 +292,0 @@ if (this[key]) { |
{ | ||
"name": "@eyevinn/cmcd", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "NPM library for Common Media Client Data (CTA-5004)", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -40,2 +40,22 @@ # node-cmcd | ||
Return as headers | ||
```javascript | ||
import { Payload } from "@eyevinn/cmcd"; | ||
const payload = new Payload({ | ||
sessionId: '6e2fb550-c457-11e9-bb97-0800200c9a66', | ||
bufferStarvation: true, | ||
requestedMaximumThroughput: 15000, | ||
encodedBitrate: 3200, | ||
objectDuration: 4004, | ||
objectType: CMCDObjectTypeToken.video, | ||
topBitrate: 6000, | ||
measuredThroughput: 25400 | ||
}); | ||
console.log(payload.headers['CMCD-Object']); | ||
// br=3200,d=4004,ot=v,tb=6000 | ||
``` | ||
# Support | ||
@@ -42,0 +62,0 @@ |
@@ -114,2 +114,20 @@ import { createPayload, CMCDString, CMCDBoolean, CMCDInteger, CMCDDecimal, CMCDEncodedBitrate, CMCDBufferLength, CMCDBufferStarvation, CMCDContentId, CMCDObjectDuration, CMCDDeadline, CMCDMeasuredThroughput, CMCDNextObjectRequest, CMCDObjectType, CMCDNextRangeRequest, CMCDObjectTypeToken, CMCDHdr, CMCDPlaybackRate, CMCDRequestedMaximumThroughput, CMCDStreamingFormat, CMCDStreamingFormatToken, CMCDSessionId, CMCDStreamType, CMCDStreamTypeToken, CMCDStartup, CMCDTopBitrate, CMCDVersion, CMCDKey, Payload } from "."; | ||
}); | ||
test("can be constructed and returned as headers", () => { | ||
const payload = new Payload({ | ||
sessionId: '6e2fb550-c457-11e9-bb97-0800200c9a66', | ||
bufferStarvation: true, | ||
requestedMaximumThroughput: 15000, | ||
encodedBitrate: 3200, | ||
objectDuration: 4004, | ||
objectType: CMCDObjectTypeToken.video, | ||
topBitrate: 6000, | ||
measuredThroughput: 25400 | ||
}); | ||
const headers = payload.headers; | ||
expect(headers['CMCD-Request']).toEqual('mtp=25400'); | ||
expect(headers['CMCD-Object']).toEqual('br=3200,d=4004,ot=v,tb=6000'); | ||
expect(headers['CMCD-Status']).toEqual('bs,rtp=15000'); | ||
expect(headers['CMCD-Session']).toEqual('sid="6e2fb550-c457-11e9-bb97-0800200c9a66"') | ||
}); | ||
}); |
@@ -161,2 +161,12 @@ export enum CMCDKey { | ||
function strcmp(a: string, b: string) { | ||
if (a === b) { | ||
return 0 | ||
} else if (a > b) { | ||
return 1; | ||
} else if (a < b) { | ||
return -1; | ||
} | ||
} | ||
function create<T>(ctor: { new (raw): T }, v): T { | ||
@@ -258,5 +268,23 @@ return v !== undefined ? new ctor(v) : undefined; | ||
get headers() { | ||
let hdrs = {}; | ||
Object.keys(CMCD_MAP).forEach(k => { | ||
const key = '_' + CMCD_MAP[k]; | ||
if (this[key]) { | ||
const header = this[key].header.toString(); | ||
if (!hdrs[header]) { | ||
hdrs[header] = []; | ||
} | ||
hdrs[header].push(this[key].toString()); | ||
} | ||
}); | ||
Object.keys(hdrs).forEach(k => { | ||
hdrs[k] = hdrs[k].sort((a, b) => strcmp(a, b)).join(','); | ||
}); | ||
return hdrs; | ||
} | ||
toString() { | ||
let kv = []; | ||
Object.keys(CMCD_MAP).forEach(k => { | ||
Object.keys(CMCD_MAP).sort((a, b) => strcmp(a, b)).forEach(k => { | ||
const key = '_' + CMCD_MAP[k]; | ||
@@ -263,0 +291,0 @@ if (this[key]) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42654
725
76