eyevinn-channel-engine 3.3.11 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +5 -3
- package/dist/engine/ad_request.d.ts +14 -0
- package/dist/engine/ad_request.js +121 -0
- package/dist/engine/chaos_monkey.d.ts +1 -0
- package/dist/engine/chaos_monkey.js +55 -0
- package/dist/engine/event_stream.d.ts +6 -0
- package/dist/engine/event_stream.js +20 -0
- package/dist/engine/index.d.ts +0 -0
- package/dist/engine/index.js +0 -0
- package/dist/engine/memcached_state_store.d.ts +12 -0
- package/dist/engine/memcached_state_store.js +164 -0
- package/dist/engine/memory_state_store.d.ts +11 -0
- package/dist/engine/memory_state_store.js +105 -0
- package/dist/engine/playhead_state.d.ts +26 -0
- package/dist/engine/playhead_state.js +156 -0
- package/dist/engine/redis_state_store.d.ts +12 -0
- package/dist/engine/redis_state_store.js +236 -0
- package/dist/engine/server.d.ts +135 -0
- package/dist/engine/server.js +1113 -0
- package/dist/engine/session.d.ts +109 -0
- package/dist/engine/session.js +2194 -0
- package/dist/engine/session_live.d.ts +119 -0
- package/dist/engine/session_live.js +1723 -0
- package/dist/engine/session_live_state.d.ts +24 -0
- package/dist/engine/session_live_state.js +231 -0
- package/dist/engine/session_state.d.ts +45 -0
- package/dist/engine/session_state.js +365 -0
- package/dist/engine/shared_state_store.d.ts +21 -0
- package/dist/engine/shared_state_store.js +170 -0
- package/dist/engine/stream_switcher.d.ts +29 -0
- package/dist/engine/stream_switcher.js +813 -0
- package/dist/engine/util.d.ts +19 -0
- package/dist/engine/util.js +281 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/package.json +47 -0
- package/dist/server-demux.d.ts +1 -0
- package/dist/server-demux.js +104 -0
- package/dist/server-livemix.d.ts +1 -0
- package/dist/server-livemix.js +196 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +101 -0
- package/engine/index.ts +0 -0
- package/engine/{server.js → server.ts} +138 -6
- package/index.ts +12 -0
- package/package.json +11 -7
- package/{server-demux.js → server-demux.ts} +18 -11
- package/{server-livemix.js → server-livemix.ts} +21 -13
- package/{server.js → server.ts} +13 -8
- package/spec/engine/engine_spec.js +1 -1
- package/spec/engine/interface_spec.js +1 -1
- package/tsconfig.json +10 -0
- package/index.js +0 -3
|
@@ -12,9 +12,11 @@ jobs:
|
|
|
12
12
|
- uses: actions/checkout@v1
|
|
13
13
|
- uses: actions/setup-node@v1
|
|
14
14
|
with:
|
|
15
|
-
node-version:
|
|
15
|
+
node-version: 16
|
|
16
16
|
registry-url: https://registry.npmjs.org/
|
|
17
|
-
- run:
|
|
18
|
-
|
|
17
|
+
- run: |
|
|
18
|
+
npm install
|
|
19
|
+
npm run build
|
|
20
|
+
npm publish
|
|
19
21
|
env:
|
|
20
22
|
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export = AdRequest;
|
|
2
|
+
declare class AdRequest {
|
|
3
|
+
constructor(adCopyMgrUri: any, adXchangeUri: any);
|
|
4
|
+
_adCopyMgrUri: any;
|
|
5
|
+
_adXchangeUri: any;
|
|
6
|
+
_splices: any[];
|
|
7
|
+
resolve(): Promise<any>;
|
|
8
|
+
get splices(): any[];
|
|
9
|
+
_requestBreaks(): Promise<any>;
|
|
10
|
+
_requestAdsFromXchange(): Promise<any>;
|
|
11
|
+
_requestAds(): Promise<any>;
|
|
12
|
+
_fillBreak(adbreak: any): Promise<any>;
|
|
13
|
+
_getAdById(ad: any): Promise<any>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var MOCK_VAST = "<VAST version=\"4.0\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://www.iab.com/VAST\"> <Ad id=\"20001\" sequence=\"1\" conditionalAd=\"false\"> <InLine> <AdSystem version=\"4.0\">iabtechlab</AdSystem> <Error>http://example.com/error</Error> <Impression id=\"Impression-ID\">http://example.com/track/impression</Impression> <Pricing model=\"cpm\" currency=\"USD\"> <![CDATA[ 25.00 ]]> </Pricing> <AdTitle>Inline Simple Ad</AdTitle> <AdVerifications></AdVerifications> <Advertiser>IAB Sample Company</Advertiser> <Category authority=\"http://www.iabtechlab.com/categoryauthority\">AD CONTENT description category</Category> <Creatives> <Creative id=\"5480\" sequence=\"1\" adId=\"2447226\"> <UniversalAdId idRegistry=\"Eyevinn-Ad-ID\" idValue=\"1\">1</UniversalAdId> <Linear> <TrackingEvents> <Tracking event=\"start\" offset=\"09:15:23\">http://example.com/tracking/start</Tracking> <Tracking event=\"firstQuartile\">http://example.com/tracking/firstQuartile</Tracking> <Tracking event=\"midpoint\">http://example.com/tracking/midpoint</Tracking> <Tracking event=\"thirdQuartile\">http://example.com/tracking/thirdQuartile</Tracking> <Tracking event=\"complete\">http://example.com/tracking/complete</Tracking> </TrackingEvents> <Duration>00:00:45</Duration> <MediaFiles/> <VideoClicks> <ClickThrough id=\"blog\"> <![CDATA[https://iabtechlab.com]]> </ClickThrough> </VideoClicks> </Linear> </Creative> </Creatives> </InLine> </Ad></VAST>";
|
|
2
|
+
var MOCK_VMAP = "<vmap:VMAP xmlns:vmap=\"http://www.iab.net/vmap-1.0\" version=\"1.0\"> <vmap:AdBreak breakType=\"linear\" breakId=\"midroll1\" timeOffset=\"00:00:15.000\"> <vmap:AdSource allowMultipleAds=\"true\" followRedirects=\"true\" id=\"1\"> <vmap:VASTAdData> <VAST version=\"3.0\" xsi:noNamespaceSchemaLocation=\"vast.xsd\"> ".concat(MOCK_VAST, "\n </VAST> </vmap:VASTAdData> </vmap:AdSource> <vmap:TrackingEvents> <vmap:Tracking event=\"breakStart\">http://server.com/breakstart</vmap:Tracking> <vmap:Tracking event=\"breakEnd\">http://server.com/breakend</vmap:Tracking> </vmap:TrackingEvents> </vmap:AdBreak> <vmap:AdBreak breakType=\"linear\" breakId=\"midroll2\" timeOffset=\"00:10:00.000\"> <vmap:AdSource allowMultipleAds=\"true\" followRedirects=\"true\" id=\"2\"> <vmap:VASTAdData> <VAST version=\"3.0\" xsi:noNamespaceSchemaLocation=\"vast.xsd\"> ").concat(MOCK_VAST, "\n </VAST> </vmap:VASTAdData> </vmap:AdSource> <vmap:TrackingEvents> <vmap:Tracking event=\"breakStart\">http://server.com/breakstart</vmap:Tracking> <vmap:Tracking event=\"breakEnd\">http://server.com/breakend</vmap:Tracking> </vmap:TrackingEvents> </vmap:AdBreak> </vmap:VMAP>");
|
|
3
|
+
var request = require('request');
|
|
4
|
+
var debug = require('debug')('engine-adrequest');
|
|
5
|
+
var DEFAULT_BREAK_PATTERN = [
|
|
6
|
+
{ position: 0.0 },
|
|
7
|
+
{ position: 10 * 60.0 }
|
|
8
|
+
];
|
|
9
|
+
var MOCK_ADS = [
|
|
10
|
+
'video-sff-impression',
|
|
11
|
+
'video-apotea-impression',
|
|
12
|
+
// 'video-spp-impression',
|
|
13
|
+
];
|
|
14
|
+
var ADID_MAP = {
|
|
15
|
+
'video-sff-impression': { adid: 4 },
|
|
16
|
+
'video-apotea-impression': { adid: 5 },
|
|
17
|
+
'video-spp-impression': { adid: 3 },
|
|
18
|
+
};
|
|
19
|
+
function shuffleArray(array) {
|
|
20
|
+
for (var i = array.length - 1; i > 0; i--) {
|
|
21
|
+
var j = Math.floor(Math.random() * (i + 1));
|
|
22
|
+
var temp = array[i];
|
|
23
|
+
array[i] = array[j];
|
|
24
|
+
array[j] = temp;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
var AdRequest = /** @class */ (function () {
|
|
28
|
+
function AdRequest(adCopyMgrUri, adXchangeUri) {
|
|
29
|
+
this._adCopyMgrUri = adCopyMgrUri;
|
|
30
|
+
this._adXchangeUri = adXchangeUri;
|
|
31
|
+
this._splices = [];
|
|
32
|
+
}
|
|
33
|
+
AdRequest.prototype.resolve = function () {
|
|
34
|
+
var _this = this;
|
|
35
|
+
return new Promise(function (resolve, reject) {
|
|
36
|
+
_this._requestBreaks().then(function (breaks) {
|
|
37
|
+
var adBreakPromises = [];
|
|
38
|
+
for (var i = 0; i < breaks.length; i++) {
|
|
39
|
+
adBreakPromises.push(_this._fillBreak(breaks[i]));
|
|
40
|
+
}
|
|
41
|
+
Promise.all(adBreakPromises).then(function () {
|
|
42
|
+
resolve(_this.splices);
|
|
43
|
+
}).catch(reject);
|
|
44
|
+
}).catch(reject);
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(AdRequest.prototype, "splices", {
|
|
48
|
+
get: function () {
|
|
49
|
+
return this._splices.sort(function (a, b) { return a.position - b.position; });
|
|
50
|
+
},
|
|
51
|
+
enumerable: false,
|
|
52
|
+
configurable: true
|
|
53
|
+
});
|
|
54
|
+
AdRequest.prototype._requestBreaks = function () {
|
|
55
|
+
return new Promise(function (resolve, reject) {
|
|
56
|
+
var breaks = DEFAULT_BREAK_PATTERN;
|
|
57
|
+
resolve(breaks);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
AdRequest.prototype._requestAdsFromXchange = function () {
|
|
61
|
+
return new Promise(function (resolve, reject) {
|
|
62
|
+
var ads = MOCK_ADS;
|
|
63
|
+
debug("Got ads from xchange:");
|
|
64
|
+
debug(ads);
|
|
65
|
+
resolve(ads);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
AdRequest.prototype._requestAds = function () {
|
|
69
|
+
var _this = this;
|
|
70
|
+
return new Promise(function (resolve, reject) {
|
|
71
|
+
_this._requestAdsFromXchange().then(function (ads) {
|
|
72
|
+
var resolvedAds = [];
|
|
73
|
+
var adPromises = [];
|
|
74
|
+
for (var i = 0; i < ads.length; i++) {
|
|
75
|
+
var ad = ADID_MAP[ads[i]];
|
|
76
|
+
resolvedAds.push(ad);
|
|
77
|
+
adPromises.push(_this._getAdById(ad));
|
|
78
|
+
}
|
|
79
|
+
Promise.all(adPromises).then(function () {
|
|
80
|
+
debug("Got ads:");
|
|
81
|
+
debug(resolvedAds);
|
|
82
|
+
resolve(resolvedAds);
|
|
83
|
+
})
|
|
84
|
+
.catch(reject);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
AdRequest.prototype._fillBreak = function (adbreak) {
|
|
89
|
+
var _this = this;
|
|
90
|
+
return new Promise(function (resolve, reject) {
|
|
91
|
+
_this._requestAds().then(function (ads) {
|
|
92
|
+
var p = 0.0;
|
|
93
|
+
for (var i = 0; i < ads.length; i++) {
|
|
94
|
+
_this._splices.push({ adid: ads[i].adid, position: adbreak.position + p, segments: ads[i].segments });
|
|
95
|
+
p += ads[i].duration;
|
|
96
|
+
}
|
|
97
|
+
resolve();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
AdRequest.prototype._getAdById = function (ad) {
|
|
102
|
+
var _this = this;
|
|
103
|
+
return new Promise(function (resolve, reject) {
|
|
104
|
+
request({ url: _this._adCopyMgrUri + '/ad/' + ad.adid }, function (err, resp, body) {
|
|
105
|
+
if (resp.statusCode == 200) {
|
|
106
|
+
var data = JSON.parse(body);
|
|
107
|
+
ad.adid = data.id;
|
|
108
|
+
ad.uri = data.uri;
|
|
109
|
+
ad.segments = data.segments;
|
|
110
|
+
ad.duration = (1 * data.duration);
|
|
111
|
+
resolve();
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
reject(err);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
return AdRequest;
|
|
120
|
+
}());
|
|
121
|
+
module.exports = AdRequest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function loadVod(p: any): Promise<any>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var _this = this;
|
|
38
|
+
var debug = require('debug')('chaos-monkey');
|
|
39
|
+
var CHAOS_MONKEY_PROBABILITY = process.env.CHAOS_MONKEY_PROBABILITY || 0.5;
|
|
40
|
+
var doChaos = function () { return process.env.CHAOS_MONKEY === "true" && Math.random() < CHAOS_MONKEY_PROBABILITY; };
|
|
41
|
+
var loadVod = function (p) { return __awaiter(_this, void 0, void 0, function () {
|
|
42
|
+
return __generator(this, function (_a) {
|
|
43
|
+
switch (_a.label) {
|
|
44
|
+
case 0:
|
|
45
|
+
if (!doChaos()) return [3 /*break*/, 1];
|
|
46
|
+
debug("Chaos Monkey is doing stuff");
|
|
47
|
+
throw new Error("Chaos monkey prevented you from loading a VOD");
|
|
48
|
+
case 1: return [4 /*yield*/, p];
|
|
49
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}); };
|
|
53
|
+
module.exports = {
|
|
54
|
+
loadVod: loadVod
|
|
55
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var EventStream = /** @class */ (function () {
|
|
2
|
+
function EventStream(session) {
|
|
3
|
+
this._session = session;
|
|
4
|
+
}
|
|
5
|
+
EventStream.prototype.poll = function () {
|
|
6
|
+
var _this = this;
|
|
7
|
+
return new Promise(function (resolve, reject) {
|
|
8
|
+
var event = {};
|
|
9
|
+
event = _this._session.consumeEvent();
|
|
10
|
+
if (event) {
|
|
11
|
+
resolve(JSON.stringify(event));
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
resolve(JSON.stringify({}));
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
return EventStream;
|
|
19
|
+
}());
|
|
20
|
+
module.exports = EventStream;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export = MemcachedStateStore;
|
|
2
|
+
declare class MemcachedStateStore {
|
|
3
|
+
constructor(keyPrefix: any, opts: any);
|
|
4
|
+
keyPrefix: any;
|
|
5
|
+
client: any;
|
|
6
|
+
initAsync(id: any, initData: any): Promise<{}>;
|
|
7
|
+
resetAsync(id: any, initData: any): Promise<void>;
|
|
8
|
+
getAsync(id: any, key: any): Promise<any>;
|
|
9
|
+
setAsync(id: any, key: any, value: any): Promise<any>;
|
|
10
|
+
setVolatileAsync(id: any, key: any, value: any): Promise<void>;
|
|
11
|
+
removeAsync(id: any, key: any): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var MemcacheClient = require("memcache-client");
|
|
38
|
+
var debug = require("debug")("memcached-state-store");
|
|
39
|
+
var MemcachedStateStore = /** @class */ (function () {
|
|
40
|
+
function MemcachedStateStore(keyPrefix, opts) {
|
|
41
|
+
this.keyPrefix = keyPrefix;
|
|
42
|
+
if (opts.version) {
|
|
43
|
+
var prependPrefix = opts.version.replace(/\./g, "X");
|
|
44
|
+
this.keyPrefix = prependPrefix + this.keyPrefix;
|
|
45
|
+
debug("Prepending keyprefix with ".concat(prependPrefix, " => ").concat(this.keyPrefix));
|
|
46
|
+
}
|
|
47
|
+
this.client = new MemcacheClient({ server: opts.memcachedUrl, cmdTimeout: 10000 });
|
|
48
|
+
}
|
|
49
|
+
MemcachedStateStore.prototype.initAsync = function (id, initData) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
var isInitiated, data, _i, _a, key, _b, _c, _d, _e, key, _f, _g;
|
|
52
|
+
return __generator(this, function (_h) {
|
|
53
|
+
switch (_h.label) {
|
|
54
|
+
case 0: return [4 /*yield*/, this.getAsync(id, "_initiated")];
|
|
55
|
+
case 1:
|
|
56
|
+
isInitiated = _h.sent();
|
|
57
|
+
data = {};
|
|
58
|
+
if (!!isInitiated) return [3 /*break*/, 7];
|
|
59
|
+
_i = 0, _a = Object.keys(initData);
|
|
60
|
+
_h.label = 2;
|
|
61
|
+
case 2:
|
|
62
|
+
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
63
|
+
key = _a[_i];
|
|
64
|
+
debug("".concat(this.keyPrefix, ":").concat(id, ": Initiating key ").concat(key, " with init data"));
|
|
65
|
+
_b = data;
|
|
66
|
+
_c = key;
|
|
67
|
+
return [4 /*yield*/, this.setAsync(id, key, initData[key])];
|
|
68
|
+
case 3:
|
|
69
|
+
_b[_c] = _h.sent();
|
|
70
|
+
_h.label = 4;
|
|
71
|
+
case 4:
|
|
72
|
+
_i++;
|
|
73
|
+
return [3 /*break*/, 2];
|
|
74
|
+
case 5: return [4 /*yield*/, this.setAsync(id, "_initiated", true)];
|
|
75
|
+
case 6:
|
|
76
|
+
_h.sent();
|
|
77
|
+
return [3 /*break*/, 11];
|
|
78
|
+
case 7:
|
|
79
|
+
debug("".concat(this.keyPrefix, ":").concat(id, ": Already initiated, not initiating with init data"));
|
|
80
|
+
_d = 0, _e = Object.keys(initData);
|
|
81
|
+
_h.label = 8;
|
|
82
|
+
case 8:
|
|
83
|
+
if (!(_d < _e.length)) return [3 /*break*/, 11];
|
|
84
|
+
key = _e[_d];
|
|
85
|
+
debug("".concat(this.keyPrefix, ":").concat(id, ": Initiating key ").concat(key, " with data from store"));
|
|
86
|
+
_f = data;
|
|
87
|
+
_g = key;
|
|
88
|
+
return [4 /*yield*/, this.getAsync(id, key)];
|
|
89
|
+
case 9:
|
|
90
|
+
_f[_g] = _h.sent();
|
|
91
|
+
_h.label = 10;
|
|
92
|
+
case 10:
|
|
93
|
+
_d++;
|
|
94
|
+
return [3 /*break*/, 8];
|
|
95
|
+
case 11: return [2 /*return*/, data];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
MemcachedStateStore.prototype.resetAsync = function (id, initData) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
switch (_a.label) {
|
|
104
|
+
case 0: return [4 /*yield*/, this.setAsync(id, "_initiated", false)];
|
|
105
|
+
case 1:
|
|
106
|
+
_a.sent();
|
|
107
|
+
return [4 /*yield*/, this.initAsync(id, initData)];
|
|
108
|
+
case 2:
|
|
109
|
+
_a.sent();
|
|
110
|
+
return [2 /*return*/];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
MemcachedStateStore.prototype.getAsync = function (id, key) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
117
|
+
var storeKey, data;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
switch (_a.label) {
|
|
120
|
+
case 0:
|
|
121
|
+
storeKey = "" + this.keyPrefix + id + key;
|
|
122
|
+
return [4 /*yield*/, this.client.get(storeKey)];
|
|
123
|
+
case 1:
|
|
124
|
+
data = _a.sent();
|
|
125
|
+
if (data) {
|
|
126
|
+
return [2 /*return*/, JSON.parse(data.value)];
|
|
127
|
+
}
|
|
128
|
+
return [2 /*return*/, null];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
MemcachedStateStore.prototype.setAsync = function (id, key, value) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var storeKey;
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
storeKey = "" + this.keyPrefix + id + key;
|
|
140
|
+
return [4 /*yield*/, this.client.set(storeKey, JSON.stringify(value))];
|
|
141
|
+
case 1:
|
|
142
|
+
_a.sent();
|
|
143
|
+
return [2 /*return*/, value];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
MemcachedStateStore.prototype.setVolatileAsync = function (id, key, value) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
throw new Error("memcached: setVolatileAsync not implemented yet");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
MemcachedStateStore.prototype.removeAsync = function (id, key) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
throw new Error("memcached: removeAsync not implemented yet");
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
return MemcachedStateStore;
|
|
163
|
+
}());
|
|
164
|
+
module.exports = MemcachedStateStore;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export = MemoryStateStore;
|
|
2
|
+
declare class MemoryStateStore {
|
|
3
|
+
constructor(type: any, opts: any);
|
|
4
|
+
sharedStates: {};
|
|
5
|
+
globalSharedStates: {};
|
|
6
|
+
initAsync(id: any, initData: any): Promise<any>;
|
|
7
|
+
getAsync(id: any, key: any): Promise<any>;
|
|
8
|
+
setAsync(id: any, key: any, value: any): Promise<any>;
|
|
9
|
+
setVolatileAsync(id: any, key: any, value: any): Promise<any>;
|
|
10
|
+
removeAsync(id: any, key: any): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var debug = require("debug")("memory-state-store");
|
|
38
|
+
var MemoryStateStore = /** @class */ (function () {
|
|
39
|
+
function MemoryStateStore(type, opts) {
|
|
40
|
+
this.sharedStates = {};
|
|
41
|
+
this.globalSharedStates = {};
|
|
42
|
+
}
|
|
43
|
+
MemoryStateStore.prototype.initAsync = function (id, initData) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
var _this = this;
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
if (!this.sharedStates[id]) {
|
|
48
|
+
this.sharedStates[id] = {};
|
|
49
|
+
Object.keys(initData).forEach(function (key) {
|
|
50
|
+
_this.sharedStates[id][key] = initData[key];
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return [2 /*return*/, this.sharedStates[id]];
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
MemoryStateStore.prototype.getAsync = function (id, key) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var value;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
if (id === "" || id === null) {
|
|
62
|
+
value = this.globalSharedStates[key];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
value = this.sharedStates[id][key];
|
|
66
|
+
}
|
|
67
|
+
return [2 /*return*/, value];
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
MemoryStateStore.prototype.setAsync = function (id, key, value) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
if (id === "" || id === null) {
|
|
75
|
+
this.globalSharedStates[key] = value;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.sharedStates[id][key] = value;
|
|
79
|
+
return [2 /*return*/, this.sharedStates[id][key]];
|
|
80
|
+
}
|
|
81
|
+
return [2 /*return*/];
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
MemoryStateStore.prototype.setVolatileAsync = function (id, key, value) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0: return [4 /*yield*/, this.setAsync(id, key, value)];
|
|
90
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
MemoryStateStore.prototype.removeAsync = function (id, key) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
delete this.sharedStates[id][key];
|
|
99
|
+
return [2 /*return*/];
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
return MemoryStateStore;
|
|
104
|
+
}());
|
|
105
|
+
module.exports = MemoryStateStore;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const PlayheadState: Readonly<{
|
|
2
|
+
RUNNING: 1;
|
|
3
|
+
STOPPED: 2;
|
|
4
|
+
CRASHED: 3;
|
|
5
|
+
IDLE: 4;
|
|
6
|
+
}>;
|
|
7
|
+
export class PlayheadStateStore extends SharedStateStore {
|
|
8
|
+
constructor(opts: any);
|
|
9
|
+
create(sessionId: any): Promise<SharedPlayheadState>;
|
|
10
|
+
}
|
|
11
|
+
import SharedStateStore = require("./shared_state_store.js");
|
|
12
|
+
declare class SharedPlayheadState {
|
|
13
|
+
constructor(store: any, sessionId: any, opts: any);
|
|
14
|
+
sessionId: any;
|
|
15
|
+
store: any;
|
|
16
|
+
state: number;
|
|
17
|
+
lastM3u8: any;
|
|
18
|
+
get(key: any): Promise<any>;
|
|
19
|
+
getState(): Promise<number>;
|
|
20
|
+
getLastM3u8(): Promise<any>;
|
|
21
|
+
getValues(keys: any): Promise<any>;
|
|
22
|
+
set(key: any, value: any): Promise<any>;
|
|
23
|
+
setState(newState: any): Promise<number>;
|
|
24
|
+
setLastM3u8(m3u8: any): Promise<any>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|