I wish to install a tiny deno background process (deamon- like)
that can do one thing.
i wish to register a protocol handler such that when i click on a vlc: or magnet: link i wish that i could trigger some kind of function that would initiate a callback that could either start downloading something using webtorrent or start playing something in vlc when i press a link.
i'm not sure how it would be able to call your own handler exactly... but some few ideas:
- would it only work as long as the process is running?
- would it automatically unregister itself when the process die?
- would it execute a file when clicking on such a link?
- could it deviate somewhat from the spec and take a callback function instad of a url?
// using the hashtag to call exported functions
navigator.registerProtocolHandler("vlc", import.meta.reesolve('#playUrl=%s'))
navigator.registerProtocolHandler("magnet", import.meta.reesolve('#downloadTorrent=%s'))
export function playUrl (mediaUrl) {
new URL(mediaUrl).hash.split('=')
}
export function downloadTorrent (magnetUrl) {
new URL(mediaUrl).hash.split('=')
}
// bootstrap.js
// register a handler once and let ower own process die,
// such that Deno will register that handler and then later execute our file
navigator.registerProtocolHandler("vlc", import.meta.resolve('../open-vlc.js?url=%s'))
// open-vlc.js
const url = new URL(import.meta.url).searchParams.get('url')
cmd.exec([vlc, url])
// deviated to use some sort of callback
// it would unregister itself once the process die
navigator.registerProtocolHandler("vlc", function (protocolLink) {
const url = new URL(protocolLink).searchParams.get('url')
cmd.exec([vlc, url])
}))
Maybe it could even spin up a own Worker in the same context...
navigator.registerProtocolHandler("vlc", import.meta.resolve('./vlc-worker.js?u=%s')
addEventListener('message', event => {
cmd.exec([ vlc, event.data.path ])
})
// vlc-worker.js
const path = new URL(import.meta.url).searchParam.get(u)
postMessage({ path })
// or as a single file
const code = `
const path = new URL(import.meta.url).searchParam.get(u)
postMessage({ path })
`
const blob = new Blob([ code ], { type: 'text/javascript' })
const workerUrl = URL.createObjectURL(blob)
navigator.registerProtocolHandler("vlc", workerUrl + '?u=%s')
addEventListener('message', event => {
cmd.exec([ vlc, event.data.path ])
})
kind of like the 2 last suggestion as it's kind of most cross-env friendliest way that would not require any deno specific code such that same code could work in other context in case if any other runtime would implement the same idea
I wish to install a tiny deno background process (deamon- like)
that can do one thing.
i wish to register a protocol handler such that when i click on a
vlc:ormagnet:link i wish that i could trigger some kind of function that would initiate a callback that could either start downloading something using webtorrent or start playing something in vlc when i press a link.i'm not sure how it would be able to call your own handler exactly... but some few ideas:
Maybe it could even spin up a own Worker in the same context...
kind of like the 2 last suggestion as it's kind of most cross-env friendliest way that would not require any deno specific code such that same code could work in other context in case if any other runtime would implement the same idea