-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(middleware): cache grows even if no middleware created #8674
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cf3a61a
chore(middleware): add sandbox to show issue with growing cache
GiuseppePiscopo d189f9b
fix(middleware): when player is removed and no middleware was set, pr…
GiuseppePiscopo 75c5311
Merge branch 'main' into issue-8653
mister-ben 7d6b4cf
Merge branch 'main' into issue-8653
mister-ben 9c116f1
refactor(middleware): when player is removed and no middleware was se…
GiuseppePiscopo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Video.js Sandbox</title> | ||
<link href="../dist/video-js.css" rel="stylesheet" type="text/css"> | ||
<script src="../dist/video.js"></script> | ||
<link rel="icon" href="data:;base64,="> | ||
</head> | ||
<body> | ||
<div style="background-color:#eee; border: 1px solid #777; padding: 10px; margin-bottom: 20px; font-size: .8em; line-height: 1.5em; font-family: Verdana, sans-serif;"> | ||
<p>You can use /sandbox/ for writing and testing your own code. Nothing in /sandbox/ will get checked into the repo, except files that end in .example (so don't edit or add those files). To get started run `npm start` and open the index.html</p> | ||
<pre>npm start</pre> | ||
<pre>open http://localhost:9999/sandbox/index.html</pre> | ||
</div> | ||
|
||
<div style="background-color:#eee; border: 1px solid #777; padding: 10px; margin-bottom: 20px; font-size: 1em; line-height: 1.5em; font-family: Verdana, sans-serif;"> | ||
<p> | ||
In developer console, Sources tab, look for <code>clearCacheForPlayer</code> function. | ||
Place a logpoint at function closing. Logpoint content should be: | ||
</p> | ||
<pre style="font-size: 1.2em;">'middlewareInstances nr', Object.keys(middlewareInstances).length</pre> | ||
<p> | ||
When one or more players are removed, the number of instances should *NOT* grow. | ||
</p> | ||
</div> | ||
|
||
<div> | ||
<button id="add-player" style="min-height: 36px;">Add player</button> | ||
<button id="remove-all" style="min-height: 36px;">Remove all players</button> | ||
</div> | ||
|
||
<div id="player-container"></div> | ||
|
||
<script> | ||
let playerList = []; | ||
|
||
document.querySelector('#add-player').addEventListener('click', addPlayer); | ||
document.querySelector('#remove-all').addEventListener('click', removeAll); | ||
|
||
function addPlayer() { | ||
const videoJsElem = document.createElement('video-js'); | ||
videoJsElem.setAttribute('controls', ''); | ||
videoJsElem.setAttribute('preload', 'auto'); | ||
videoJsElem.setAttribute('width', '640'); | ||
videoJsElem.setAttribute('height', '264'); | ||
videoJsElem.setAttribute('poster', 'https://vjs.zencdn.net/v/oceans.png'); | ||
|
||
document.querySelector('#player-container').appendChild(videoJsElem); | ||
|
||
const player = videojs(videoJsElem); | ||
player.src({ | ||
src: 'https://vjs.zencdn.net/v/oceans.mp4', | ||
type: 'video/mp4', | ||
}); | ||
|
||
playerList.push(player); | ||
|
||
player.log('Video.js player created', player.id()); | ||
} | ||
|
||
function removeAll() { | ||
for (const player of playerList) { | ||
player.dispose(); | ||
} | ||
playerList.length = 0; | ||
} | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if
delete
is preferable, if the object having null properties was the issue being addressedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the issue being addressed is that
middlewareInstances
grows with new keys having null values. Not sure why the original code prefers setting to null instead of deleting.Just as a speculation: in
player.js
there's the global enumeration of players,Player.players
, and in that case it is explicitly mentioned that a disposed player should be left as a key with null value. Maybe that same behaviour has been applied inmiddlewareInstances
, even if there is no actual use of it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with
delete
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, commit is pushed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if - at this point - code should just delete without checking whether
middlewareInstances
has that property or not.