eyevinn-channel-engine 4.3.3 → 4.3.5

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.
@@ -36,7 +36,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  var Redis = require("ioredis");
38
38
  var debug = require("debug")("redis-state-store");
39
+ var cloudWatchLog = require("./util.js").cloudWatchLog;
39
40
  var DEFAULT_VOLATILE_KEY_TTL = 5; // Timeout so it should not expire within one normal increment iteration (in seconds)
41
+ function isTrue(s) {
42
+ var regex = /^\s*(true|1)\s*$/i;
43
+ return regex.test(s);
44
+ }
45
+ var REDIS_VERBOSE_LOG = process.env.REDIS_VERBOSE_LOG ? isTrue(process.env.REDIS_VERBOSE_LOG) : false;
40
46
  var RedisStateStore = /** @class */ (function () {
41
47
  function RedisStateStore(keyPrefix, opts) {
42
48
  this.keyPrefix = keyPrefix;
@@ -135,12 +141,13 @@ var RedisStateStore = /** @class */ (function () {
135
141
  };
136
142
  RedisStateStore.prototype.getValues = function (id, keys) {
137
143
  return __awaiter(this, void 0, void 0, function () {
138
- var pipeline, data, _loop_1, this_1, _i, keys_1, key;
144
+ var pipeline, data, startMs, _loop_1, this_1, _i, keys_1, key, ops, ioTimeMs;
139
145
  return __generator(this, function (_a) {
140
146
  switch (_a.label) {
141
147
  case 0:
142
148
  pipeline = this.client.pipeline();
143
149
  data = {};
150
+ startMs = Date.now();
144
151
  _loop_1 = function (key) {
145
152
  var storeKey = "" + this_1.keyPrefix + id + key;
146
153
  pipeline.get(storeKey, function (err, reply) {
@@ -160,9 +167,12 @@ var RedisStateStore = /** @class */ (function () {
160
167
  key = keys_1[_i];
161
168
  _loop_1(key);
162
169
  }
170
+ ops = pipeline.length;
163
171
  return [4 /*yield*/, pipeline.exec()];
164
172
  case 1:
165
173
  _a.sent();
174
+ ioTimeMs = Date.now() - startMs;
175
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis', { event: 'getValues', operations: ops, ioTimeMs: ioTimeMs });
166
176
  return [2 /*return*/, data];
167
177
  }
168
178
  });
@@ -189,6 +199,7 @@ var RedisStateStore = /** @class */ (function () {
189
199
  catch (err) {
190
200
  console.error("REDIS get: Failed to parse ".concat(storeKey, " data: '").concat(reply, "'"));
191
201
  }
202
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis', { event: 'get', operations: 1, ioTimeMs: ioTimeMs });
192
203
  resolve(data_1);
193
204
  }
194
205
  else {
@@ -206,11 +217,12 @@ var RedisStateStore = /** @class */ (function () {
206
217
  };
207
218
  RedisStateStore.prototype.setValues = function (id, data) {
208
219
  return __awaiter(this, void 0, void 0, function () {
209
- var returnData, pipeline, _loop_2, this_2, _i, _a, key;
220
+ var returnData, startMs, pipeline, _loop_2, this_2, _i, _a, key, ops, ioTimeMs;
210
221
  return __generator(this, function (_b) {
211
222
  switch (_b.label) {
212
223
  case 0:
213
224
  returnData = {};
225
+ startMs = Date.now();
214
226
  pipeline = this.client.pipeline();
215
227
  _loop_2 = function (key) {
216
228
  var storeKey = "" + this_2.keyPrefix + id + key;
@@ -227,9 +239,12 @@ var RedisStateStore = /** @class */ (function () {
227
239
  key = _a[_i];
228
240
  _loop_2(key);
229
241
  }
242
+ ops = pipeline.length;
230
243
  return [4 /*yield*/, pipeline.exec()];
231
244
  case 1:
232
245
  _b.sent();
246
+ ioTimeMs = Date.now() - startMs;
247
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis', { event: 'setValues', operations: ops, ioTimeMs: ioTimeMs });
233
248
  return [2 /*return*/, returnData];
234
249
  }
235
250
  });
@@ -249,6 +264,7 @@ var RedisStateStore = /** @class */ (function () {
249
264
  var ioTimeMs = Date.now() - startMs;
250
265
  debug("REDIS set ".concat(storeKey, ": ").concat(res, " (").concat(ioTimeMs, "ms) ").concat(ioTimeMs > 1000 ? "REDISSLOW!" : ""));
251
266
  if (!err) {
267
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis', { event: 'set', operations: 1, ioTimeMs: ioTimeMs });
252
268
  resolve(value);
253
269
  }
254
270
  else {
@@ -305,6 +321,7 @@ var RedisStateStore = /** @class */ (function () {
305
321
  var ioTimeMs = Date.now() - startMs;
306
322
  debug("REDIS remove ".concat(storeKey, ": (").concat(ioTimeMs, "ms) ").concat(ioTimeMs > 1000 ? "REDISSLOW!" : ""));
307
323
  if (!err) {
324
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis', { event: 'remove', operations: 1, ioTimeMs: ioTimeMs });
308
325
  resolve();
309
326
  }
310
327
  else {
@@ -16,6 +16,7 @@ export interface ChannelEngineOpts {
16
16
  dummySubtitleEndpoint?: string;
17
17
  subtitleSliceEndpoint?: string;
18
18
  useVTTSubtitles?: boolean;
19
+ vttBasePath?: string;
19
20
  alwaysNewSegments?: boolean;
20
21
  partialStoreHLSVod?: boolean;
21
22
  alwaysMapBandwidthByNearest?: boolean;
@@ -30,6 +31,7 @@ export interface ChannelEngineOpts {
30
31
  volatileKeyTTL?: number;
31
32
  autoCreateSession?: boolean;
32
33
  sessionResetKey?: string;
34
+ keepAliveTimeout?: number;
33
35
  }
34
36
  export interface VodRequest {
35
37
  sessionId: string;
@@ -59,8 +59,8 @@ var sessionsLive = {}; // Should be a persistent store...
59
59
  var sessionSwitchers = {}; // Should be a persistent store...
60
60
  var switcherStatus = {}; // Should be a persistent store...
61
61
  var eventStreams = {};
62
- var DefaultDummySubtitleEndpointPath = "/vtt/dummyUrl";
63
- var DefaultSubtitleSpliceEndpointPath = "/vtt/sliceUrl";
62
+ var DefaultDummySubtitleEndpointPath = "/dummyUrl";
63
+ var DefaultSubtitleSpliceEndpointPath = "/sliceUrl";
64
64
  var ScheduleStreamType;
65
65
  (function (ScheduleStreamType) {
66
66
  ScheduleStreamType[ScheduleStreamType["LIVE"] = 1] = "LIVE";
@@ -84,8 +84,9 @@ var ChannelEngine = /** @class */ (function () {
84
84
  this.useDemuxedAudio = true;
85
85
  }
86
86
  this.useVTTSubtitles = (options && options.useVTTSubtitles) ? options.useVTTSubtitles : false;
87
- this.dummySubtitleEndpoint = (options && options.dummySubtitleEndpoint) ? options.dummySubtitleEndpoint : DefaultDummySubtitleEndpointPath;
88
- this.subtitleSliceEndpoint = (options && options.subtitleSliceEndpoint) ? options.subtitleSliceEndpoint : DefaultSubtitleSpliceEndpointPath;
87
+ var vttBasePath = (options && options.vttBasePath) ? options.vttBasePath : '/vtt';
88
+ this.dummySubtitleEndpoint = (options && options.dummySubtitleEndpoint) ? options.dummySubtitleEndpoint : vttBasePath + DefaultDummySubtitleEndpointPath;
89
+ this.subtitleSliceEndpoint = (options && options.subtitleSliceEndpoint) ? options.subtitleSliceEndpoint : vttBasePath + DefaultSubtitleSpliceEndpointPath;
89
90
  this.sessionResetKey = "";
90
91
  if (options && options.sessionResetKey) {
91
92
  this.sessionResetKey = options.sessionResetKey;
@@ -116,6 +117,11 @@ var ChannelEngine = /** @class */ (function () {
116
117
  this.assetMgr = assetMgr;
117
118
  this.monitorTimer = {};
118
119
  this.server = restify.createServer();
120
+ if (options && options.keepAliveTimeout) {
121
+ this.server.server.keepAliveTimeout = options.keepAliveTimeout;
122
+ this.server.server.headersTimeout = options.keepAliveTimeout + 1000;
123
+ }
124
+ console.log(this.server);
119
125
  this.server.use(restify.plugins.queryParser());
120
126
  this.serverStartTime = Date.now();
121
127
  this.instanceId = uuidv4();
@@ -269,8 +275,8 @@ var ChannelEngine = /** @class */ (function () {
269
275
  this.server.get('/health/:sessionId', this._handleSessionHealth.bind(this));
270
276
  this.server.get('/reset', this._handleSessionsReset.bind(this));
271
277
  this.server.get('/reset/:sessionId', this._handleSessionReset.bind(this));
272
- this.server.get(DefaultDummySubtitleEndpointPath, this._handleDummySubtitleEndpoint.bind(this));
273
- this.server.get(DefaultSubtitleSpliceEndpointPath, this._handleSubtitleSliceEndpoint.bind(this));
278
+ this.server.get(vttBasePath + DefaultDummySubtitleEndpointPath, this._handleDummySubtitleEndpoint.bind(this));
279
+ this.server.get(vttBasePath + DefaultSubtitleSpliceEndpointPath, this._handleSubtitleSliceEndpoint.bind(this));
274
280
  this.server.on('NotFound', function (req, res, err, next) {
275
281
  res.header("X-Instance-Id", _this.instanceId + "<".concat(version, ">"));
276
282
  return next();
@@ -94,6 +94,7 @@ var engineOptions = {
94
94
  defaultSlateUri: "https://maitv-vod.lab.eyevinn.technology/slate-consuo.mp4/master.m3u8",
95
95
  slateRepetitions: 10,
96
96
  redisUrl: process.env.REDIS_URL,
97
+ keepAliveTimeout: process.env.KEEP_ALIVE_TIMEOUT ? parseInt(process.env.KEEP_ALIVE_TIMEOUT) * 1000 : undefined
97
98
  };
98
99
  var engine = new index_1.ChannelEngine(refAssetManager, engineOptions);
99
100
  engine.start();
@@ -100,7 +100,8 @@ var engineOptions = {
100
100
  redisUrl: process.env.REDIS_URL,
101
101
  useDemuxedAudio: true,
102
102
  alwaysNewSegments: false,
103
- useVTTSubtitles: true
103
+ useVTTSubtitles: true,
104
+ vttBasePath: '/subtitles'
104
105
  };
105
106
  var engine = new index_1.ChannelEngine(refAssetManager, engineOptions);
106
107
  engine.start();
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyevinn-channel-engine",
3
- "version": "4.3.3",
3
+ "version": "4.3.5",
4
4
  "description": "OTT TV Channel Engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,8 +1,16 @@
1
1
  const Redis = require("ioredis");
2
2
  const debug = require("debug")("redis-state-store");
3
+ const { cloudWatchLog } = require("./util.js");
3
4
 
4
5
  const DEFAULT_VOLATILE_KEY_TTL = 5; // Timeout so it should not expire within one normal increment iteration (in seconds)
5
6
 
7
+ function isTrue(s) {
8
+ const regex = /^\s*(true|1)\s*$/i;
9
+ return regex.test(s);
10
+ }
11
+
12
+ const REDIS_VERBOSE_LOG = process.env.REDIS_VERBOSE_LOG ? isTrue(process.env.REDIS_VERBOSE_LOG) : false;
13
+
6
14
  class RedisStateStore {
7
15
  constructor(keyPrefix, opts) {
8
16
  this.keyPrefix = keyPrefix;
@@ -59,6 +67,7 @@ class RedisStateStore {
59
67
  async getValues(id, keys) {
60
68
  const pipeline = this.client.pipeline();
61
69
  let data = {};
70
+ const startMs = Date.now();
62
71
  for (const key of keys) {
63
72
  const storeKey = "" + this.keyPrefix + id + key;
64
73
  pipeline.get(storeKey, (err, reply) => {
@@ -72,7 +81,11 @@ class RedisStateStore {
72
81
  }
73
82
  });
74
83
  }
84
+ const ops = pipeline.length;
75
85
  await pipeline.exec();
86
+ const ioTimeMs = Date.now() - startMs;
87
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis',
88
+ { event: 'getValues', operations: ops, ioTimeMs: ioTimeMs });
76
89
  return data;
77
90
  }
78
91
 
@@ -90,6 +103,8 @@ class RedisStateStore {
90
103
  } catch (err) {
91
104
  console.error(`REDIS get: Failed to parse ${storeKey} data: '${reply}'`);
92
105
  }
106
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis',
107
+ { event: 'get', operations: 1, ioTimeMs: ioTimeMs });
93
108
  resolve(data);
94
109
  } else {
95
110
  reject(err);
@@ -102,6 +117,7 @@ class RedisStateStore {
102
117
 
103
118
  async setValues(id, data) {
104
119
  const returnData = {};
120
+ const startMs = Date.now();
105
121
  const pipeline = this.client.pipeline();
106
122
  for (const key of Object.keys(data)) {
107
123
  const storeKey = "" + this.keyPrefix + id + key;
@@ -113,7 +129,11 @@ class RedisStateStore {
113
129
  }
114
130
  });
115
131
  }
132
+ const ops = pipeline.length;
116
133
  await pipeline.exec();
134
+ const ioTimeMs = Date.now() - startMs;
135
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis',
136
+ { event: 'setValues', operations: ops, ioTimeMs: ioTimeMs });
117
137
  return returnData;
118
138
  }
119
139
 
@@ -125,6 +145,8 @@ class RedisStateStore {
125
145
  const ioTimeMs = Date.now() - startMs;
126
146
  debug(`REDIS set ${storeKey}: ${res} (${ioTimeMs}ms) ${ioTimeMs > 1000 ? "REDISSLOW!" : ""}`);
127
147
  if (!err) {
148
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis',
149
+ { event: 'set', operations: 1, ioTimeMs: ioTimeMs });
128
150
  resolve(value);
129
151
  } else {
130
152
  reject(err);
@@ -159,6 +181,8 @@ class RedisStateStore {
159
181
  const ioTimeMs = Date.now() - startMs;
160
182
  debug(`REDIS remove ${storeKey}: (${ioTimeMs}ms) ${ioTimeMs > 1000 ? "REDISSLOW!" : ""}`);
161
183
  if (!err) {
184
+ cloudWatchLog(!REDIS_VERBOSE_LOG, 'redis',
185
+ { event: 'remove', operations: 1, ioTimeMs: ioTimeMs });
162
186
  resolve();
163
187
  } else {
164
188
  reject(err);
package/engine/server.ts CHANGED
@@ -24,8 +24,8 @@ const sessionsLive = {}; // Should be a persistent store...
24
24
  const sessionSwitchers = {}; // Should be a persistent store...
25
25
  const switcherStatus = {}; // Should be a persistent store...
26
26
  const eventStreams = {};
27
- const DefaultDummySubtitleEndpointPath = "/vtt/dummyUrl"
28
- const DefaultSubtitleSpliceEndpointPath = "/vtt/sliceUrl"
27
+ const DefaultDummySubtitleEndpointPath = "/dummyUrl"
28
+ const DefaultSubtitleSpliceEndpointPath = "/sliceUrl"
29
29
 
30
30
  export interface ChannelEngineOpts {
31
31
  defaultSlateUri?: string;
@@ -45,6 +45,7 @@ export interface ChannelEngineOpts {
45
45
  dummySubtitleEndpoint?: string;
46
46
  subtitleSliceEndpoint?: string;
47
47
  useVTTSubtitles?: boolean;
48
+ vttBasePath?: string;
48
49
  alwaysNewSegments?: boolean;
49
50
  partialStoreHLSVod?: boolean;
50
51
  alwaysMapBandwidthByNearest?: boolean;
@@ -58,7 +59,8 @@ export interface ChannelEngineOpts {
58
59
  noSessionDataTags?: boolean;
59
60
  volatileKeyTTL?: number;
60
61
  autoCreateSession?: boolean;
61
- sessionResetKey?:string;
62
+ sessionResetKey?: string;
63
+ keepAliveTimeout?: number;
62
64
  }
63
65
 
64
66
  interface StreamerOpts {
@@ -220,8 +222,9 @@ export class ChannelEngine {
220
222
  }
221
223
 
222
224
  this.useVTTSubtitles = (options && options.useVTTSubtitles) ? options.useVTTSubtitles : false ;
223
- this.dummySubtitleEndpoint = (options && options.dummySubtitleEndpoint) ? options.dummySubtitleEndpoint : DefaultDummySubtitleEndpointPath;
224
- this.subtitleSliceEndpoint = (options && options.subtitleSliceEndpoint) ? options.subtitleSliceEndpoint : DefaultSubtitleSpliceEndpointPath;
225
+ const vttBasePath = (options && options.vttBasePath) ? options.vttBasePath : '/vtt';
226
+ this.dummySubtitleEndpoint = (options && options.dummySubtitleEndpoint) ? options.dummySubtitleEndpoint : vttBasePath + DefaultDummySubtitleEndpointPath;
227
+ this.subtitleSliceEndpoint = (options && options.subtitleSliceEndpoint) ? options.subtitleSliceEndpoint : vttBasePath + DefaultSubtitleSpliceEndpointPath;
225
228
 
226
229
  this.sessionResetKey = "";
227
230
  if (options && options.sessionResetKey) {
@@ -253,6 +256,11 @@ export class ChannelEngine {
253
256
  this.assetMgr = assetMgr;
254
257
  this.monitorTimer = {};
255
258
  this.server = restify.createServer();
259
+ if (options && options.keepAliveTimeout) {
260
+ this.server.server.keepAliveTimeout = options.keepAliveTimeout;
261
+ this.server.server.headersTimeout = options.keepAliveTimeout + 1000;
262
+ }
263
+ console.log(this.server);
256
264
  this.server.use(restify.plugins.queryParser());
257
265
  this.serverStartTime = Date.now();
258
266
  this.instanceId = uuidv4();
@@ -369,8 +377,8 @@ export class ChannelEngine {
369
377
  this.server.get('/health/:sessionId', this._handleSessionHealth.bind(this));
370
378
  this.server.get('/reset', this._handleSessionsReset.bind(this));
371
379
  this.server.get('/reset/:sessionId', this._handleSessionReset.bind(this));
372
- this.server.get(DefaultDummySubtitleEndpointPath, this._handleDummySubtitleEndpoint.bind(this));
373
- this.server.get(DefaultSubtitleSpliceEndpointPath, this._handleSubtitleSliceEndpoint.bind(this));
380
+ this.server.get(vttBasePath + DefaultDummySubtitleEndpointPath, this._handleDummySubtitleEndpoint.bind(this));
381
+ this.server.get(vttBasePath + DefaultSubtitleSpliceEndpointPath, this._handleSubtitleSliceEndpoint.bind(this));
374
382
 
375
383
  this.server.on('NotFound', (req, res, err, next) => {
376
384
  res.header("X-Instance-Id", this.instanceId + `<${version}>`);
@@ -106,6 +106,7 @@ const engineOptions: ChannelEngineOpts = {
106
106
  "https://maitv-vod.lab.eyevinn.technology/slate-consuo.mp4/master.m3u8",
107
107
  slateRepetitions: 10,
108
108
  redisUrl: process.env.REDIS_URL,
109
+ keepAliveTimeout: process.env.KEEP_ALIVE_TIMEOUT ? parseInt(process.env.KEEP_ALIVE_TIMEOUT) * 1000: undefined
109
110
  };
110
111
 
111
112
  const engine = new ChannelEngine(refAssetManager, engineOptions);
package/examples/demux.ts CHANGED
@@ -112,7 +112,8 @@ const engineOptions: ChannelEngineOpts = {
112
112
  redisUrl: process.env.REDIS_URL,
113
113
  useDemuxedAudio: true,
114
114
  alwaysNewSegments: false,
115
- useVTTSubtitles: true
115
+ useVTTSubtitles: true,
116
+ vttBasePath: '/subtitles'
116
117
  };
117
118
 
118
119
  const engine = new ChannelEngine(refAssetManager, engineOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyevinn-channel-engine",
3
- "version": "4.3.3",
3
+ "version": "4.3.5",
4
4
  "description": "OTT TV Channel Engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",