-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Just some notes to help you get started.
There are two parts to this application, the client extension and the server. The extension is located in the extension/
subdirectory, and the server is located mainly in server.js
, importing some other files from shared/
.
The extension begins with ldn.js
. This is the background page of the Chrome extension.
constructor() {
this.user = new User();
this.ws = null;
this.tabListener = new TabListener();
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) =>
this._onRuntimeMessage(msg, sender, sendResponse)
);
}
Some things about ldn.js
:
- keeps a local variable user which is just a model that I use to hold user data
- keeps a local ws reference to the websocket client
- instantiates a
TabListener
- we listen to messages sent from content scripts via
_onRuntimeMessage
The tab listener listens to tab events and keeps the tab id of the active Netflix tab.
- executes
loader.js
if the user is navigating to awatch/
url
The loader.js
script is injected via the tab listener, and also as a content script (via manifest.json
). This is so we cover all cases (the script is loaded on a page reload, and also a Netflix SPA page transition)
- It injects our
controller.js
script into the DOM - Because our injected script no longer has access to chrome.* APIs, we have to use
window.postMessage()
to pass messages throughloader.js
as a middleman
The controller script controls all the DOM actions and events that we have to control. It uses MutationObserver to wait until the Netflix player is ready.
- Has the basic functions
pause
,play
,seek
,currentTime
,duration
- Passes messages back to
ldn.js
throughloader.js
to update theldn.user
variable
The popup is created via page_action
in manifest.json
.
- Uses a map of constant keys to jQuery elements to control view state
- We can get a reference to our background page using
getClient()
, which useschrome.extension.getBackgroundPage()
to get our background context
The server begins with server.js
. A simple WebSocket server, it keeps a map of lobbies and sockets.
There is a shared/
folder which contains code that is used by both the client and the server. The most important files here are the shared/model/
objects and constants.js
.