Closed adrums86 closed 1 year ago
Merging #1393 (e56d103) into main (bdd842a) will increase coverage by
0.04%
. The diff coverage is95.74%
.
@@ Coverage Diff @@
## main #1393 +/- ##
==========================================
+ Coverage 85.40% 85.45% +0.04%
==========================================
Files 40 40
Lines 9963 10010 +47
Branches 2308 2317 +9
==========================================
+ Hits 8509 8554 +45
- Misses 1454 1456 +2
Impacted Files | Coverage Δ | |
---|---|---|
src/videojs-http-streaming.js | 90.96% <94.73%> (+0.32%) |
:arrow_up: |
src/xhr.js | 100.00% <100.00%> (ø) |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
I thought about this kind of simplification
xhr._requestHooksSet = new Set();
xhr._responseHooksSet = new Set();
const addOnRequestHook = (callback) => xhr._requestHooksSet.add(callback);
const addOnResponseHook = (callback) => xhr._responseHooksSet.add(callback);
const removeOnRequestHook = (callback) => xhr._requestHooksSet.delete(callback);
const removeOnResponseHook = (callback) => xhr._responseHooksSet.delete(callback);
but then I realized that those 2 XHRs are not the same pointers...
LGTM!
@gkatsev I totally agree regarding namespacing these to the xhr object to separate the hooks from fetch. Update incoming.
@gkatsev and @misteroneill the namespace changes are pushed. Another quick look would be appreciated before merging. Thanks!
Description
This PR would add xhr request and response hooks via an
onRequest(callback)
andonResponse(callback)
API. The user can add as many unique hook callbacks as they want, and they will be called in the order they were added before the request and after the response is received respectively. The user can un-register these callbacks via theoffRequest(callback)
andoffResponse(callback)
API. The callback functions can take the following parameters:onRequest
callbacks will pass the xhrrequest
Object to the callback.onResponse
callbacks will pass the xhrrequest, error, and response
Objects to the callback in that order.In addition, the user can use both global
videojs.Vhs
and playerplayer.tech().xhr
scoped API functions to add these hooks, where player hooks will override any global hooks.Note:
onRequest
hooks are called after thebeforeRequest
function, so be aware that these hooks may further modify request options passed through that function.Specific Changes proposed
Adding API functions to both
Vhs
and theVhsHandler
for adding and removing unique xhr request and response hooks, passing those hooks to the xhr module, then calling them in the order they were added before an xhr request and in the response callback respectively.Requirements Checklist