add media-player module#608
Conversation
AnatoleAM
left a comment
There was a problem hiding this comment.
Thanks for the cleanup so far 🙂
|
|
||
| definePropertyHook(props.instance.component, "props", { | ||
| value: (v: Twitch.MediaPlayerComponent["props"]) => { | ||
| if (v.mediaPlayerInstance) { |
There was a problem hiding this comment.
Assign v.mediaPlayerInstance to a ref and use a watcher. You can see an example of this here:
https://github.com/SevenTV/Extension/blob/master/src/site/twitch.tv/modules/chat/ChatController.vue#L246
By doing this we are making vue handle diffing and avoid re-hooking the component many times. This also ensures that if we receive a different pointer, the hooks can be removed from the previous one.
| const videoElement = mediaPlayer.core.mediaSinkManager.video; | ||
| if (!videoElement) return; | ||
|
|
||
| const overlayContainer = videoElement.nextElementSibling?.querySelector<HTMLElement>( | ||
| "div[data-a-target='player-overlay-click-handler']", | ||
| ); |
There was a problem hiding this comment.
nit: can avoid optional chaining
| const videoElement = mediaPlayer.core.mediaSinkManager.video; | |
| if (!videoElement) return; | |
| const overlayContainer = videoElement.nextElementSibling?.querySelector<HTMLElement>( | |
| "div[data-a-target='player-overlay-click-handler']", | |
| ); | |
| const videoElement = mediaPlayer.core.mediaSinkManager.video; | |
| if (!videoElement || !videoElement.nextElementSibling) return; | |
| const overlayContainer = videoElement.nextElementSibling.querySelector<HTMLElement>( | |
| "div[data-a-target='player-overlay-click-handler']", | |
| ); |
| const rootNode = inst.domNodes.root; | ||
| if (rootNode) { | ||
| const teleLoc = rootNode.querySelector<HTMLElement>("[data-a-target*='channel-viewers-count']") | ||
| ?.parentElement?.parentElement?.parentElement; | ||
| videoStatsTeleportLocation.value = teleLoc; | ||
| } |
There was a problem hiding this comment.
nit: less depth
| const rootNode = inst.domNodes.root; | |
| if (rootNode) { | |
| const teleLoc = rootNode.querySelector<HTMLElement>("[data-a-target*='channel-viewers-count']") | |
| ?.parentElement?.parentElement?.parentElement; | |
| videoStatsTeleportLocation.value = teleLoc; | |
| } | |
| const rootNode = inst.domNodes.root; | |
| if (!rootNode) return; | |
| const teleLoc = rootNode.querySelector<HTMLElement>("[data-a-target*='channel-viewers-count']") | |
| ?.parentElement?.parentElement?.parentElement; | |
| videoStatsTeleportLocation.value = teleLoc; |
| <p>Video: {{ props.width }}x{{ props.height }}p{{ props.framerate }}</p> | ||
| <p>Bitrate: {{ props.bitrate }} kbps</p> | ||
| <p>Dropped Frames: {{ props.droppedFrames }}</p> | ||
| <br /> |
There was a problem hiding this comment.
nit: use css instead of <br />
|
The master branch has its own Player module, please refactor in a new pull request |
This PR aims to add the foundational work of working with the media player by combining several requested features into one PR.
Player Settings Section

Stream info tooltip

Showcasing Twitch's auto speed up

Successful merge of this PR will close #485 and #562