@warren-bank/hls-proxy 3.6.6 → 3.6.7
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/README.md +7 -3
- package/hls-proxy/timers.js +17 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -312,10 +312,14 @@ options:
|
|
|
312
312
|
)
|
|
313
313
|
|
|
314
314
|
add_request_interval(
|
|
315
|
-
(1000 * 60 * 5), // run timer at 5 minute
|
|
316
|
-
(request) => {
|
|
315
|
+
(1000 * 60 * 5), // run timer at 5 minute intervals to refresh cookies
|
|
316
|
+
(request, timer_id) => {
|
|
317
317
|
request('https://example.com/heart-beat')
|
|
318
|
-
|
|
318
|
+
|
|
319
|
+
if (globalThis.someCondition)
|
|
320
|
+
clearInterval(timer_id)
|
|
321
|
+
},
|
|
322
|
+
(1000 * 60 * 60 * 1) // automatically stop after a max duration of 1 hour
|
|
319
323
|
)
|
|
320
324
|
|
|
321
325
|
}
|
package/hls-proxy/timers.js
CHANGED
|
@@ -23,13 +23,27 @@ const initialize_timers = function(params) {
|
|
|
23
23
|
return request(options, POST_data, config)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const add_request_interval = function(delay_ms, callback) {
|
|
26
|
+
const add_request_interval = function(delay_ms, callback, max_duration_ms) {
|
|
27
27
|
if (!delay_ms || (typeof delay_ms !== 'number') || isNaN(delay_ms) || (delay_ms < 0)) {
|
|
28
28
|
callback(request_wrapper)
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
if (max_duration_ms && ((typeof max_duration_ms !== 'number') || (max_duration_ms < 0)))
|
|
32
|
+
max_duration_ms = 0
|
|
33
|
+
|
|
34
|
+
const start_time_ms = max_duration_ms
|
|
35
|
+
? Date.now()
|
|
36
|
+
: null
|
|
37
|
+
|
|
38
|
+
const callback_wrapper = () => {
|
|
39
|
+
if (max_duration_ms && ((Date.now() - start_time_ms) > max_duration_ms))
|
|
40
|
+
clearInterval(timer_id)
|
|
41
|
+
else
|
|
42
|
+
callback(request_wrapper, timer_id)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const timer_id = setInterval(
|
|
46
|
+
callback_wrapper,
|
|
33
47
|
delay_ms
|
|
34
48
|
)
|
|
35
49
|
}
|
package/package.json
CHANGED