forked from borismus/keysocket
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace generic API with Media Control API
- Loading branch information
Showing
5 changed files
with
83 additions
and
47 deletions.
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
This file was deleted.
Oops, something went wrong.
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
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,44 @@ | ||
// Tab registration by MediaControlled event | ||
document.addEventListener("MediaControlled", function () { | ||
chrome.runtime.sendMessage({command: "registerTab"}); | ||
}); | ||
|
||
// Tab unregistration by MediaUncontrolled event | ||
document.addEventListener("MediaUncontrolled", function () { | ||
chrome.runtime.sendMessage({command: "unregisterTab"}); | ||
}); | ||
|
||
// Media Events emmiter | ||
chrome.runtime.onMessage.addListener(function(request) { | ||
switch (request.command) { | ||
case "play-pause": | ||
document.dispatchEvent(new Event("MediaPlayPause")); | ||
break; | ||
|
||
case "stop": | ||
document.dispatchEvent(new Event("MediaStop")); | ||
break; | ||
|
||
case "prev": | ||
document.dispatchEvent(new Event("MediaPrev")); | ||
break; | ||
|
||
case "next": | ||
document.dispatchEvent(new Event("MediaNext")); | ||
break; | ||
} | ||
}); | ||
|
||
// Tell document that we are ready | ||
console.log('Keysocket Media Control API initialized'); | ||
document.dispatchEvent(new Event("MediaControlApiInit")); | ||
|
||
// Tab registration by meta tag | ||
if (document.getElementsByName("media-controlled").length > 0) { | ||
chrome.runtime.sendMessage({command: "registerTab"}); | ||
} | ||
|
||
// Unregister tab before move to another URI | ||
window.onunload = function() { | ||
chrome.runtime.sendMessage({command: "unregisterTab"}); | ||
} |
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