A program from Python to the browser
Python is the server and the browser the client, since a page cannot be
listened to. Three terminals, from osepy/host and web.o.se.
Serve the page:
cd web.o.se && make serve # http://localhost:8000
Start Python and listen:
>>> import sys; sys.path.insert(0, "examples")
>>> import ose, osc, beep
>>> srv, conn = beep.listen()
listening on ws://localhost:8080
put that in the page's socket field and press Connect
Open http://localhost:8000, put ws://localhost:8080 in the socket
field and press Connect; the prompt comes back with browser connected.
Click somewhere on the page, since a browser will not start audio until
the user has touched the document. Then send the program and read the
reply:
>>> vm = ose.VM()
>>> conn.send(ose.program(vm, beep.BEEP))
>>> osc.values(conn.recv()[1])
['beep done']
A 440 Hz beep plays in the tab. The machine in Python only parses;
the program runs in the browser. python3 examples/beep.py is the same
thing as one script.