Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader > Kobo Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 05-22-2020, 06:06 PM   #1
jefferson
Member
jefferson began at the beginning.
 
Posts: 21
Karma: 10
Join Date: May 2014
Device: kindle
JavaScript problem: mirror my phone's screen in browser

I am trying to build an app to mirror my phone's screen in the ebook's browser.
The problem I am running in with my kobo and kindle that the browsers don't support websockets. I have also tryed to update the image via setInterval, but it's not working.
I am running out of ideas how I can do it. Is there a spec of Kobo/Kindle's browser Javascript Dom API somewhere?
Any ideas how to browser debugging? Other methods to show an updated picture on KOBO/Kindle?
jefferson is offline   Reply With Quote
Old 05-22-2020, 06:22 PM   #2
geek1011
Wizard
geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.
 
Posts: 2,798
Karma: 6990707
Join Date: May 2016
Location: Ontario, Canada
Device: Kobo Mini, Aura Edition 2 v1, Clara HD
Quote:
Originally Posted by jefferson View Post
Other methods to show an updated picture on KOBO/Kindle?
I'd recommend using @NiLuJe's FBInk, possibly with @shermp's Go bindings.
geek1011 is offline   Reply With Quote
Advert
Old 05-22-2020, 06:30 PM   #3
sherman
Guru
sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.
 
Posts: 873
Karma: 2676800
Join Date: Sep 2008
Location: Taranaki - NZ
Device: Kobo Aura H2O, Kobo Forma
If you want to stick with JavaScript, server sent events could potentially be used, as I know the Kobo browser supports that. Whether you send the image directly to the Kobo by base64 encoding it, or sending update info for the Kobo to fetch an image from a URL is up to you.
sherman is online now   Reply With Quote
Old 05-23-2020, 02:08 AM   #4
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,499
Karma: 26047188
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
The Kobo is probably going to have an *extremely* hard time dealing with anything image-related on its own at anything better than a snails pace, especially given the native resolution on the average midrange smartphone.

If you go this route, better have the source preprocess the image as much as possible, so that the Kobo ends up having to do almost zero work besides dumping that to the framebuffer verbatim (i.e., match the target pixel format, ideally after having switched to 8bpp on the Kobo to save some bandwidth).

(The examples in the Python FBInk bindings have some musings about that sort of things).

Last edited by NiLuJe; 05-23-2020 at 02:11 AM.
NiLuJe is offline   Reply With Quote
Old 05-23-2020, 04:26 AM   #5
jefferson
Member
jefferson began at the beginning.
 
Posts: 21
Karma: 10
Join Date: May 2014
Device: kindle
Quote:
Originally Posted by sherman View Post
If you want to stick with JavaScript, server sent events could potentially be used, as I know the Kobo browser supports that. Whether you send the image directly to the Kobo by base64 encoding it, or sending update info for the Kobo to fetch an image from a URL is up to you.
Do you have any examples? I have tried Websockets for sending images, but the Kobo browser have ignored it o crashed. Kindle's browser seems not to have websockets or fetch.
My last workaround Idea was to use setInterval to trigger an update of an img element with webser serving the latest image at a url.
Unfortunately setInterval doesn't seem to work
jefferson is offline   Reply With Quote
Advert
Old 05-23-2020, 04:33 AM   #6
jefferson
Member
jefferson began at the beginning.
 
Posts: 21
Karma: 10
Join Date: May 2014
Device: kindle
Quote:
Originally Posted by NiLuJe View Post
The Kobo is probably going to have an *extremely* hard time dealing with anything image-related on its own at anything better than a snails pace, especially given the native resolution on the average midrange smartphone.

If you go this route, better have the source preprocess the image as much as possible, so that the Kobo ends up having to do almost zero work besides dumping that to the framebuffer verbatim (i.e., match the target pixel format, ideally after having switched to 8bpp on the Kobo to save some bandwidth).

(The examples in the Python FBInk bindings have some musings about that sort of things).
The plan is to optimize the image before sending - optimize black and white, resolution and choose only the part of the screen I care to see and not the whole screen.
I will check out FBInk, do you have more recommendations for an optimal image format - 8bpp is already something I don't understand.
Do you think it's possible to fetch and show images with FBInk? What would be an easy proof of concept?
jefferson is offline   Reply With Quote
Old 05-23-2020, 04:48 AM   #7
sherman
Guru
sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.
 
Posts: 873
Karma: 2676800
Join Date: Sep 2008
Location: Taranaki - NZ
Device: Kobo Aura H2O, Kobo Forma
Quote:
Originally Posted by jefferson View Post
Do you have any examples? I have tried Websockets for sending images, but the Kobo browser have ignored it o crashed. Kindle's browser seems not to have websockets or fetch.
My last workaround Idea was to use setInterval to trigger an update of an img element with webser serving the latest image at a url.
Unfortunately setInterval doesn't seem to work
See https://developer.mozilla.org/en-US/...er-sent_events for info about Server Sent Events.

TLDR, it's super easy to setup, assuming you don't need bi-directional communications. Although, if needed, you could set up your own return channel if required.

I know the Kobo browser supports it, because I've used it.
sherman is online now   Reply With Quote
Old 05-23-2020, 08:10 AM   #8
jefferson
Member
jefferson began at the beginning.
 
Posts: 21
Karma: 10
Join Date: May 2014
Device: kindle
thanks! Looks like a great option!
jefferson is offline   Reply With Quote
Old 05-23-2020, 01:01 PM   #9
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,499
Karma: 26047188
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
I was talking about the 'DIY' approach, i.e., stream raw image data in the proper pixel format.

For the browser approach, you probably actually *don't* want to do that, because Nickel runs @ 32bpp, so you'll probably want to send images encoded in a format that decodes to RGBA to avoid an extra Y8 <-> RGBA roundtrip on Qt's side on the device.

(The extra bandwidth needed by RGBA over Y8 is *usually* still faster than the extra processing power needed by the grayscale expansion to RGBA, but YMMV. Overhead is in a different place in each case, but it's still there one way or the other. Have to DIY to get rid of any overhead on that front ).

Last edited by NiLuJe; 05-23-2020 at 01:05 PM.
NiLuJe is offline   Reply With Quote
Old 05-25-2020, 09:26 AM   #10
jefferson
Member
jefferson began at the beginning.
 
Posts: 21
Karma: 10
Join Date: May 2014
Device: kindle
Quote:
Originally Posted by sherman View Post
See https://developer.mozilla.org/en-US/...er-sent_events for info about Server Sent Events.

TLDR, it's super easy to setup, assuming you don't need bi-directional communications. Although, if needed, you could set up your own return channel if required.

I know the Kobo browser supports it, because I've used it.
I am currently testing sse, but it doesn't seem to work. It might be some bug on my site, but it works on my desktop browser. Do you maybe still have some code samples which have worked for you?

Edit: nevermind, it works - I was just having es6 syntax in my js

Last edited by jefferson; 05-25-2020 at 10:22 AM.
jefferson is offline   Reply With Quote
Old 05-25-2020, 09:42 AM   #11
sherman
Guru
sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.sherman ought to be getting tired of karma fortunes by now.
 
Posts: 873
Karma: 2676800
Join Date: Sep 2008
Location: Taranaki - NZ
Device: Kobo Aura H2O, Kobo Forma
Quote:
Originally Posted by jefferson View Post
I am currently testing sse, but it doesn't seem to work. It might be some bug on my site, but it works on my desktop browser. Do you maybe still have some code samples which have worked for you?
Make sure you aren't using any modern javascript features. ECMAScript 2015 (ES6) is definitely a no go.

I've used the event field myself. Something like the following worked for me:
Code:
var evtSource = new EventSource("/messages");
evtSource.addEventListener("body", function (event) {
    // code goes here
});
Note, using let for declaring variables is a no-go. Possibly const as well. To be safe, I'd stick with var.
sherman is online now   Reply With Quote
Reply

Tags
browser, browser restrictions, javascript


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript debugging in mobile browser and WAF jnjitkoff Kindle Developer's Corner 4 03-13-2019 04:46 AM
Beta-Browser JavaScript debugging clausmuus Kindle Developer's Corner 0 09-28-2016 07:37 AM
Kindle touch browser javascript capabilities iPocketBook Kindle Developer's Corner 14 01-03-2013 10:10 AM
Javascript support in PB302 browser ? aruangra PocketBook 8 05-25-2010 08:11 PM
iLiad Is there an Iliad browser that supports javascript? Maike13 iRex Developer's Corner 0 12-09-2009 02:56 PM


All times are GMT -4. The time now is 07:17 PM.


MobileRead.com is a privately owned, operated and funded community.