Shellminator V3.0.1
Simple Terminal
|
As mentioned in the previous example, there’s definitely room for improvement when it comes to user experience. For example, why does the terminal flicker when you start typing? We touched on this issue in the Buffering example as well, but it’s much more noticeable here compared to using the Serial class—any idea why? The reason is that WebSocket frames have overhead, whereas Serial doesn’t. This means that when we send a single character over WebSocket, it doesn’t just move one byte; it moves a lot more since it also encrypts, packages, etc. If you're curious, you can read more about it here.
Another important aspect for remote devices is that not everyone should have access to it. It’s not necessarily a bad thing if it's password-protected. This is actually pretty easy to do, and we showed how to set it up in the Password example.
Now, the important innovation here is that we have two callbacks we can use:
These callbacks will be triggered when a user connects or disconnects. The names of the callbacks don’t matter, but the return type and the argument should be exactly the same. You need to attach these callbacks to the WebSocket object like this:
Then, we implement the actual logic inside the callbacks:
Shellminator has a printLoginScreen
method designed specifically for the state after a wireless connection is established. It doesn’t matter whether there’s a logo or not, or if it’s password-protected or not—it's a good idea to call this method inside the connect callback.
Inside the disconnect callback, you absolutely must call the logOut
method. Otherwise, if the connection drops due to a network issue, the terminal will stay logged in. This is very dangerous and could easily be exploited.
It's worth noting that once you click the Open button, the terminal will redraw the logo and ask for the password every time. You can also try logging out using the CTRL-D combo to see if it works.