eyevinn-channel-engine 4.3.3-rc.2 → 4.3.3-rc.3

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.
@@ -20,6 +20,7 @@ declare class SharedPlayheadState {
20
20
  getLastM3u8(): Promise<any>;
21
21
  getValues(keys: any): Promise<any>;
22
22
  set(key: any, value: any, isLeader: any): Promise<any>;
23
+ setValues(keyValues: any, isLeader: any): Promise<any>;
23
24
  setState(newState: any): Promise<4>;
24
25
  setLastM3u8(m3u8: any): Promise<any>;
25
26
  }
@@ -111,6 +111,20 @@ var SharedPlayheadState = /** @class */ (function () {
111
111
  });
112
112
  });
113
113
  };
114
+ SharedPlayheadState.prototype.setValues = function (keyValues, isLeader) {
115
+ return __awaiter(this, void 0, void 0, function () {
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0:
119
+ if (!isLeader) return [3 /*break*/, 2];
120
+ return [4 /*yield*/, this.store.setValues(this.sessionId, keyValues)];
121
+ case 1: return [2 /*return*/, _a.sent()];
122
+ case 2: return [4 /*yield*/, this.store.getValues(this.sessionId, Object.keys(keyValues))];
123
+ case 3: return [2 /*return*/, _a.sent()];
124
+ }
125
+ });
126
+ });
127
+ };
114
128
  SharedPlayheadState.prototype.setState = function (newState) {
115
129
  return __awaiter(this, void 0, void 0, function () {
116
130
  return __generator(this, function (_a) {
@@ -9,6 +9,7 @@ declare class RedisStateStore {
9
9
  resetAllAsync(): Promise<void>;
10
10
  getValues(id: any, keys: any): Promise<{}>;
11
11
  getAsync(id: any, key: any): Promise<any>;
12
+ setValues(id: any, data: any): Promise<{}>;
12
13
  setAsync(id: any, key: any, value: any): Promise<any>;
13
14
  setVolatileAsync(id: any, key: any, value: any): Promise<any>;
14
15
  removeAsync(id: any, key: any): Promise<void>;
@@ -54,51 +54,40 @@ var RedisStateStore = /** @class */ (function () {
54
54
  }
55
55
  RedisStateStore.prototype.initAsync = function (id, initData) {
56
56
  return __awaiter(this, void 0, void 0, function () {
57
- var isInitiated, data, _i, _a, key, _b, _c, _d, _e, key, _f, _g;
58
- return __generator(this, function (_h) {
59
- switch (_h.label) {
57
+ var isInitiated, data, _i, _a, key, _b, _c;
58
+ return __generator(this, function (_d) {
59
+ switch (_d.label) {
60
60
  case 0: return [4 /*yield*/, this.getAsync(id, "_initiated")];
61
61
  case 1:
62
- isInitiated = _h.sent();
62
+ isInitiated = _d.sent();
63
63
  data = {};
64
- if (!!isInitiated) return [3 /*break*/, 7];
65
- _i = 0, _a = Object.keys(initData);
66
- _h.label = 2;
64
+ if (!!isInitiated) return [3 /*break*/, 4];
65
+ debug("".concat(this.keyPrefix, ":").concat(id, ": Initiating keys ").concat(Object.keys(initData), " with init data"));
66
+ return [4 /*yield*/, this.setValues(id, initData)];
67
67
  case 2:
68
- if (!(_i < _a.length)) return [3 /*break*/, 5];
69
- key = _a[_i];
70
- debug("".concat(this.keyPrefix, ":").concat(id, ": Initiating key ").concat(key, " with init data"));
71
- _b = data;
72
- _c = key;
73
- return [4 /*yield*/, this.setAsync(id, key, initData[key])];
68
+ _d.sent();
69
+ return [4 /*yield*/, this.setAsync(id, "_initiated", true)];
74
70
  case 3:
75
- _b[_c] = _h.sent();
76
- _h.label = 4;
71
+ _d.sent();
72
+ return [3 /*break*/, 8];
77
73
  case 4:
78
- _i++;
79
- return [3 /*break*/, 2];
80
- case 5: return [4 /*yield*/, this.setAsync(id, "_initiated", true)];
81
- case 6:
82
- _h.sent();
83
- return [3 /*break*/, 11];
84
- case 7:
85
74
  debug("".concat(this.keyPrefix, ":").concat(id, ": Already initiated, not initiating with init data"));
86
- _d = 0, _e = Object.keys(initData);
87
- _h.label = 8;
88
- case 8:
89
- if (!(_d < _e.length)) return [3 /*break*/, 11];
90
- key = _e[_d];
75
+ _i = 0, _a = Object.keys(initData);
76
+ _d.label = 5;
77
+ case 5:
78
+ if (!(_i < _a.length)) return [3 /*break*/, 8];
79
+ key = _a[_i];
91
80
  debug("".concat(this.keyPrefix, ":").concat(id, ": Initiating key ").concat(key, " with data from store"));
92
- _f = data;
93
- _g = key;
81
+ _b = data;
82
+ _c = key;
94
83
  return [4 /*yield*/, this.getAsync(id, key)];
95
- case 9:
96
- _f[_g] = _h.sent();
97
- _h.label = 10;
98
- case 10:
99
- _d++;
100
- return [3 /*break*/, 8];
101
- case 11: return [2 /*return*/, data];
84
+ case 6:
85
+ _b[_c] = _d.sent();
86
+ _d.label = 7;
87
+ case 7:
88
+ _i++;
89
+ return [3 /*break*/, 5];
90
+ case 8: return [2 /*return*/, data];
102
91
  }
103
92
  });
104
93
  });
@@ -157,7 +146,12 @@ var RedisStateStore = /** @class */ (function () {
157
146
  pipeline.get(storeKey, function (err, reply) {
158
147
  if (!err) {
159
148
  debug("REDIS get(pipeline) ".concat(storeKey, ":").concat(reply ? reply.length + " chars" : "null"));
160
- data[key] = JSON.parse(reply);
149
+ try {
150
+ data[key] = JSON.parse(reply);
151
+ }
152
+ catch (err) {
153
+ console.error("REDIS get(pipeline): Failed to parse ".concat(storeKey, " data: '").concat(reply, "'"));
154
+ }
161
155
  }
162
156
  });
163
157
  };
@@ -188,7 +182,14 @@ var RedisStateStore = /** @class */ (function () {
188
182
  var ioTimeMs = Date.now() - startMs;
189
183
  debug("REDIS get ".concat(storeKey, ":").concat(reply ? reply.length + " chars" : "null", " (").concat(ioTimeMs, "ms) ").concat(ioTimeMs > 1000 ? 'REDISSLOW!' : ''));
190
184
  if (!err) {
191
- resolve(JSON.parse(reply));
185
+ var data_1;
186
+ try {
187
+ data_1 = JSON.parse(reply);
188
+ }
189
+ catch (err) {
190
+ console.error("REDIS get: Failed to parse ".concat(storeKey, " data: '").concat(reply, "'"));
191
+ }
192
+ resolve(data_1);
192
193
  }
193
194
  else {
194
195
  reject(err);
@@ -203,6 +204,37 @@ var RedisStateStore = /** @class */ (function () {
203
204
  });
204
205
  });
205
206
  };
207
+ RedisStateStore.prototype.setValues = function (id, data) {
208
+ return __awaiter(this, void 0, void 0, function () {
209
+ var returnData, pipeline, _loop_2, this_2, _i, _a, key;
210
+ return __generator(this, function (_b) {
211
+ switch (_b.label) {
212
+ case 0:
213
+ returnData = {};
214
+ pipeline = this.client.pipeline();
215
+ _loop_2 = function (key) {
216
+ var storeKey = "" + this_2.keyPrefix + id + key;
217
+ var value = data[key];
218
+ pipeline.set(storeKey, JSON.stringify(value), function (err, res) {
219
+ if (!err) {
220
+ debug("REDIS set(pipeline) ".concat(storeKey, ": ").concat(res));
221
+ returnData[key] = value;
222
+ }
223
+ });
224
+ };
225
+ this_2 = this;
226
+ for (_i = 0, _a = Object.keys(data); _i < _a.length; _i++) {
227
+ key = _a[_i];
228
+ _loop_2(key);
229
+ }
230
+ return [4 /*yield*/, pipeline.exec()];
231
+ case 1:
232
+ _b.sent();
233
+ return [2 /*return*/, returnData];
234
+ }
235
+ });
236
+ });
237
+ };
206
238
  RedisStateStore.prototype.setAsync = function (id, key, value) {
207
239
  return __awaiter(this, void 0, void 0, function () {
208
240
  var startMs, storeKey, setAsync;