📜 ⬆️ ⬇️

STB - dive

Good day to all.

I think that many of you have heard about home television, and the offer to buy a TV decoder (set-top box) in your home so that you can enjoy high-quality TV, buy movies, check the weather, and do much more without leaving the TV.

Now I will tell you what it is - this prefix, from the developer of software products.
If it is interesting to you - welcome under kat.
')
image


What is a prefix?


The prefix ( STB, Set-Top Box, Box ) is a single board computer that has the most truncated axis from the GNU / Linux family installed.

Uname -a command:
# uname -a Linux (none) 3.1.5-1.7 #66 SMP Wed Oct 22 14:40:19 EEST 2014 mips GNU/Linux 


Boxes are usually weak.
Strong representatives (and, accordingly, expensive) may have:



Each box has (the list contains only important elements):



Depending on the task of boxing and some other factors, boxing may have:



This is how it might look (pictures from the network, for example):

image

image

And here is javascript?


When a subscriber launches a set-top box at home, he sees a beautiful convenient portal that he can use using the console's console.

This portal is nothing more than a single-page application ( SPA - Single Page Application ) written in JavaScript , and opened in the tab of the browser running on the console.

When we turn on the box (on nutrition) in the general case the following occurs (I do not describe all the excess):

  1. The axis of the console started up
  2. The prefix launches the browser, and opens the HTML file in it.


It has its own features:



Added by rule :
Not all consoles allow you to change the portal page or portal address. For example, Amino on your first page requires you to have special keys for this manufacturer. There are several access levels for this.


It turns out that almost no skills are needed to develop a portal on the console? Is it enough just to set up the console, and learn how to deploy your application on it? - this is not quite so .

A prefix is ​​a platform with very low performance , and therefore development for the web and for boxing are completely different levels of complexity. That is why almost any coding error makes itself felt - your application will be incorrectly rendered, rendered a “ladder”, slow down, refuse to work, “crash” the browser, issue artifacts, consume memory, and much, much more. I will tell about it a bit later.

Why do you need a prefix?




Accordingly, the vast majority of portals on the console are aimed at solving one big task - on the one hand, to create the possibility of selling services (selling films, watching pay channels, and much more), and on the other hand, to make the most convenient application integrated with other services (map, mail, social networks, news, SMS, surfing the Internet and more), which allows you to watch TV and solve many other problems in one “box”.

If this is a regular browser, can we really implement all this? A television? Films? SMS? - we can, because the prefix is ​​not just a box with a browser inside . Each box offers its own JavaScript API.

JavaScript API consoles


In the general case, API consoles can be divided into groups:



This is more than enough for most tasks.

How does the user interact with the portal?


Each console comes with a remote control. Usually it contains buttons for solving the main tasks related to TV:



How does the portal interact with the console?

When developing an application, you need to catch a button click and process it. Everything is quite simple here - pressing a button on the remote is treated like a normal keystroke. One difference - the key codes for each vendor are their own.

Bonus-track - on some boxes, the events “keyup” and “keydown” come at the same time. Therefore, if you want to do the processing of the clamping of the remote control key (there are such cases), think about the picture of crutches and bike.jpg

What we have?


Let's summarize a small intermediate result of this quick introductory:



Thus, any prefix is ​​a low-performance platform with which you can solve tasks one way or another connected with TV. All the necessary tools for this in this platform.

It sounds good? - sounds great! However, in practice everything does not sound so good, and now we move on to the more interesting, second part of the article: Notes

Notes


I repeat - the prefix is ​​a computer with a sawn Linux, and the browser in which an additional API is screwed in, thanks to which most of the tasks facing the portal on the prefix become realizable.

For us, only the second part of this statement is important - box manufacturers finish browsers!

In the boxes, various browsers are installed, but Opera or webKit browsers are most common. As a result, browsers start to have a variety of bugs: memory leaks in unexpected places, partially inactive garbage collector, browser crashes as a result of the most common method call, drawing bugs, and much more.

Notes that are written below are subjective conclusions based on stuffed cones and rakes found. I really hope that they will be useful to you.

Go..

DOM operations


DOM operations are the hardest operations . On the console, it is very (!) Noticeable (literally).

If the number of DOM operations is not minimized, then there is a possibility:



The main problem arising from this is that the UX deteriorates significantly. I, as a user, want to press a button, and see the instantly opened page, without a mash from redrawn layers and waiting for 1-3 seconds. If I see it all the time - I will get unpleasant feelings from interaction with the portal. As a user, I first of all want to experience the pleasure of interacting with the application, and to think that I spent my money for a reason.

Dig a little deeper - What specifically needs to be mined?

It is necessary to minimize or eliminate:



We summarize. Recipes when working with DOM:



CSS


Without extra water, recipes for optimizing style sheets, and interacting with classes :



As a result, using CSS frameworks (for example, Bootstrap) is undesirable.

There is a great solution that gives a powerful performance boost - try to drop classes, and generate a layout with inline-styles (style tag). Perhaps there are even plugins for Gulp / Grunt.

A little about the support of CSS properties. Most boxes have WebKit, and a lot of CSS3 is supported. If you are developing an application not for one box, but for several at once, then I do not recommend using various new “buns”. It is possible that on one platform they will work perfectly, and on the second you will not get bugs.

Add specifics. What is often supported (from CSS3; the list is very incomplete, based on real cases, from memory):



Bugs


In addition to the usual bugs that may arise as a consequence of incorrectly programmed logic, boxing quite often can bazhit in not obvious places.

What are the bugs?

The most common bugs are related to the rendering of the page: the div's background was not drawn, the old background was not unloaded when the element was redrawn, while the transparent border is drawn, the browser ignores all the layers under it (you can see the background of the page), and many other bugs.

Rarely there are bugs in the engine: calling the native method brings down the browser, if the browser collapses in special conditions, iterating over the keys of the object takes place in an un- sorted form ( perhaps not a bug is not a bug: from gibson_dev “That's all and there are, in the sorted form, only arrays, and the construction for..in does not guarantee this ”), and other even rarer cases.

A separate group of bugs, these are vendor bugs: streams work crookedly, the file system is incorrectly read, answers are generated incorrectly when using the API, and much more.

The moral of the above is always to thoroughly check your solution on all platforms supported by you. If your solution works on one platform, then there is no guarantee that it will work on all your other platforms.

Memory leaks


A memory leak on the console can be out of nowhere. No examples, because there is no universal recipe for how to get around this.

The rule is simple - periodically run your application for memory leaks. If there are leaks, we are looking for from where, and close the “leak”.

Other


How is the application usually deployed (during development)?


There are few ways, and they are all simple. The whole deployment is to copy files from your machine to a folder on the box, or (even easier) to set up the console so that it pulls the source code not from your file system, but from the network (for example, from your local server).

I wrote about each method (as an instruction), but in order not to overload the article, everything is wrapped up in a spoiler.

Hidden text
Method # 1 - Via USB Flash Drive

  1. We collect our application
  2. Copy the source code to the USB flash drive
  3. Insert the USB flash drive into the box
  4. We go to the console through telnet or ssh (depending on the box)
  5. Replacing the sources in the directory from which the console tries to run an HTML file (usually the index.html file)


Method # 2 - Download the source from your machine

  1. Expand the server (for example, on express), which distributes the static from the directory where your application is going
  2. We collect application
  3. We archive the application
  4. We go to the console through telnet or ssh (depending on the box)
  5. We download the source from our machine (wget, curl)
  6. Replacing the sources in the directory from which the console tries to run an HTML file (usually the index.html file)


I think the best way is # 3.

Method # 3 - No Deploy
This method will work if you can tell the console where the HTML file comes from (almost all boxes are possible).

  1. Expand the server (for example, on express), which distributes the static from the directory where your application is going
  2. We go to the console through telnet or ssh (depending on the box)
  3. We edit the config box - specify the URL of the HTML file on your local server


After restarting, the prefix browser will request a file from your server, and will extract all source codes (scripts, styles, images, other) by itself.



Smart card


Boxes may have a smart card. I am not an expert in this field, so we read about it in Wikipedia .

In boxing, it can be present in two forms:



I will not write anything more about this — not an expert, and I understand how it works only at the “touched-felt” level. I don't want to lie to you by accident.

Finish


Boxing (prefix) is an interesting platform, working with which you can gain experience on how to write the most productive applications. Moreover, tons of interesting tasks and bugs when working with this platform, you will be provided with iron.

If you like hardcore (in the good sense of the word) programming, single-page applications, and are looking for an invaluable experience that will be useful for you - try writing an application for the console.

PS

, - . , , .

, , - .

, — , .

Source: https://habr.com/ru/post/259113/


All Articles