
Show HN: PHONK, JavaScript scripting for Android devices - victornomad
https://phonk.app
======
victornomad
Just to add a few more things about PHONK:

\- PHONK is a full dev environment that lives within the phone / tablet

\- The Web Editor is hosted inside the device and served using a web server.
So no 3rd party servers / cloud needed.

\- It can access the device sensors in a couple of lines of code

\- Has support for Websockets, MQTT, OSC, Midi, Bluetooth, Bluetooth BLE, NFC
and more in a very concise way

\- You can connect an Arduino straight to the phone with a USB OTG cable and
communicate with it

\- UI uses normalized coordinates, which is very handy for prototyping. It
comes with a variety of views for most needs. You can also create a custom
one.

\- There is live code execution from the Web Editor. Just select the code =>
Control (or CMD) + Shift + X and that code will be live executed.

\- PHONK comes with a Console, so you can console out wirelessly to the Web
Editor.

\- It comes with OpenStreetMaps support by default

\- More advanced 2d and 3d graphics can be done through Processing which is
included as a library.

------
eggy
Great work! I'm having a blast. I have tried 8th (a Forth that compiles to
many platforms), a bunch of Basics, picoLisp, and some others, but using my
mobile as a hotspot and coding from my laptop is so easy. I love that you
included libPd and Processing.

One error I see: I ran the Date under JavaScript Basics, and it gives the
right long string date (Mon Jun 29 2020 13:38:02 GMT-0400 (EDT)), but when it
pulls the fields it has a '5' for month.

~~~
kioleanu
5 sounds about right, months are counted 0 to 11 -
[https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Refe...](https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)

~~~
eggy
Thanks! I am use to 0-indexing in J and other PLs, but for some reason I
thought month numbers were always cardinal numbers and should start at 1 in my
subconscious!

------
mkgolden
Phonk is also a genre that typically takes samples from early-1990s hip hop,
combining them with sounds from jazz,and deploys distorting techniques such as
chopped and screwed to create a darker sound.

\- From wikipedia

Really cool stuff I might add

~~~
victornomad
yes and thanks :)

I realized about the music genre a bit later and quite like it! I should get
some vibes from the music into the project :)

------
tn1
This could be a nice alternative to LlamaLab Automate [1], which is really
useful for automating UI things on Android. That one is flowchart based, sort
of like Scratch.

Theoretically one could write a scripting language for it, but it stores its
programs in a proprietary binary format and the parser class is too hairy for
me to reverse engineer. (the decompiler in jadx only gives you smali for most
of it, control flow is too complex)

[1] [https://llamalab.com/automate/](https://llamalab.com/automate/)

~~~
victornomad
That's very interesting! In theory PHONK supports running scripts in the
background which could potentially listen to all those events and trigger
things in response.

Just opened an issue to have it in mind and check how feasible it is
[https://github.com/victordiaz/phonk/issues/20](https://github.com/victordiaz/phonk/issues/20)

------
truth_seeker
Very smart integration layer with Rhino and Android components factory API !
Although i would love to see if ES7/8 features are also make their way.... may
be GraalJS can help ... not sure about this.

Looking at the API it supports i think for the most apps i use on daily basis
can be prototyped without the bulky Android Studio.

[https://phonk.app/reference](https://phonk.app/reference)

~~~
victornomad
More modern Javascript implementations is something I had in mind since the
beginning. I played a bit with J2V8 but the amount of work to migrate it from
Rhino is a bit too much!

I didn't know about GraalJS I will have a look and reopen this issue
[https://github.com/victordiaz/phonk/issues/4](https://github.com/victordiaz/phonk/issues/4)
Thanks for pointing at it!

------
httptoolkit
Slightly off topic, but I love the site design here - the demos at the top
illustrate it perfectly and simply, and it's one of few scroll-to-reveals I've
seen that actually makes sense, and doesn't feel over the top.

~~~
victornomad
Thanks! I made it the website from scratch using Nuxt.js and some simple CSS.
I'll share the source code in Github during this week :)

------
foobar_
How is this different from nativescript ?

~~~
victornomad
There is a bunch of differences

1\. The scripts you write calls directly to Java methods, so is much easier to
access Android API calls

2\. PHONK is not only a framework, is a development environment that lives in
your phone, so no needs to install npm or any other tool in your computer. You
can write scripts directly on the phone, or using a remote Web Editor that is
hosted by the device itself

3\. The PHONK API is tailored for quick prototyping, making and exploration. I
invite you to have a look to the built-int examples and see how easy is to
access sensor data, communicate with Bluetooth Low Energy, add maps or create
interactive sound to name a few things!

~~~
foobar_
> quick prototyping, making and exploration

Thats definitely the cool part. With a debugger I can definitely see some good
use cases for this.

~~~
victornomad
PHONK supports live execution. You can select the code you want to run and
press Control or CMD + Shift + X and it will execute, which is pretty handy.
Is not a debugger but it helps quite a lot to debug :)

What debugging workflow do you think would be important?

~~~
foobar_
It is lovely to mess with. What are the apps that are not possible with this ?
Is the API coverage full ? Can I make an app with it packaging PHONK + script
?

~~~
victornomad
PHONK has some "shortcuts" to make prototyping and experimentation fast, such
normalized UI positioning instead of complex but powerful layout systems.

so for example you can write the following to include a button

    
    
      ui.addButton('Click me', 0.1, 0.1, 0.8, 0.2)
    

That's quite fast to do, but on the other side it makes it a bit cumbersome if
your UI is complex and you need to support lots of screen sizes.

The good thing is that PHONK is quite easy to extend and virtually you could
expose any Android API to the Javascript engine.

Packaging a PHONK script is possible but I haven't had much time _yet_ to
write a guide. I you want, you can follow this issue and upvote it if you
think is worth it to have a guide!
[https://github.com/victordiaz/phonk/issues/9](https://github.com/victordiaz/phonk/issues/9)

~~~
foobar_
Its definitely worth it, heck make it a script so that I don't have to think
about it. Also IOS ?

~~~
victornomad
Sadly IOS is not supported, PHONK depends a lot on Android and Java. I would
be very happy to see this or something similar in IOS though!

------
thecupisblue
What JS engine are you using under the hood? :)

~~~
victornomad
I'm using Mozilla Rhino, its pretty old and it does not support ES6 but is
very easy to interface with the JVM

------
chr15m
A lot of work obviously went into this. Super cool!

~~~
victornomad
Thanks! :) I learned lots of things while making it!

