This is the remote-js Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 07:35:46 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
remote-js
Send JavaScript from Common Lisp to a browser.
Fernando Borretti <eudoxiahp@gmail.com>
Fernando Borretti <eudoxiahp@gmail.com>
(GIT git@github.com:ceramic/remote-js.git)
MIT
# remote-js
[![Build Status](https://travis-ci.org/ceramic/remote-js.svg?branch=master)](https://travis-ci.org/ceramic/remote-js)
Send JavaScript from Common Lisp to a browser.
# Overview
# Usage
## Simple Example
First, we create a context object:
“‘lisp
(defvar ctx (remote-js:make-context))
“‘
Then we start the WebSockets server:
“‘lisp
(remote-js:start ctx)
“‘
Now, remote-js gives us a function that generates the HTML of a simple page that
connects to this context and notifies it when it’s connected. We write the HTML
to ‘~/test.html‘:
“‘lisp
(with-open-file (stream (merge-pathnames #p"test.html" (user-homedir-pathname))
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(write-string (remote-js:html ctx) stream))
“‘
Open the file in your browser. Now you can do:
“‘lisp
(remote-js:eval ctx "alert(’hello!’)")
“‘
And you will see the alert box pop up in your browser.
## Talking to the server
remote-js defines a function in the generated HTML, ‘RemoteJS.send‘, which takes
a string and sends it to the server. You can specify a callback for receiving
messages like this:
“‘lisp
(defvar ctx (remote-js:make-context
:callback #’(lambda (message) (format t "Received: ~A~%" message))))
“‘
Then, start everything and generate the HTML file again:
“‘lisp
(remote-js:start ctx)
(with-open-file (stream (merge-pathnames #p"test.html" (user-homedir-pathname))
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(write-string (remote-js:html ctx) stream))
“‘
And open ‘test.html‘ in your browser.
Now you can send messages to the server like this:
“‘lisp
CL-USER> (remote-js:eval ctx "RemoteJS.send(’hi!’)")
Received: hi!
“‘
**Note:** when a client connects to the server, it sends the string
‘remote-js:+connected-message+‘.
# Tests
The tests use [trivial-open-browser][tob], and running them will open your
default browser to a temporary file.
# License
Copyright (c) 2016 Fernando Borretti
Licensed under the MIT License.
[tob]: http://quickdocs.org/trivial-open-browser/
0.1
trivial-ws
(system).
cl-markup
(system).
find-port
(system).
src
(module).
Modules are listed depth-first from the system components tree.
remote-js/src
remote-js
(system).
remote-js.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
remote-js/src/remote-js.lisp
src
(module).
+connected-message+
(special variable).
buffered-context
(class).
context
(class).
context-address
(reader method).
context-connected-p
(reader method).
(setf context-connected-p)
(writer method).
context-port
(reader method).
context-running-p
(reader method).
(setf context-running-p)
(writer method).
context-server
(reader method).
(setf context-server)
(writer method).
eval
(generic function).
html
(generic function).
initialize-instance
(method).
js
(generic function).
make-buffered-context
(function).
make-context
(function).
start
(generic function).
stop
(generic function).
+default-callback+
(special variable).
+script-template+
(special variable).
context-buffer
(reader method).
(setf context-buffer)
(writer method).
context-callback
(reader method).
(setf context-callback)
(writer method).
context-handler
(reader method).
(setf context-handler)
(writer method).
context-record-p
(reader method).
(setf context-record-p)
(writer method).
context-timeout
(reader method).
server-for-context
(function).
Packages are listed by definition order.
remote-js
The main package.
common-lisp
.
+connected-message+
(special variable).
buffered-context
(class).
context
(class).
context-address
(generic reader).
context-connected-p
(generic reader).
(setf context-connected-p)
(generic writer).
context-port
(generic reader).
context-running-p
(generic reader).
(setf context-running-p)
(generic writer).
context-server
(generic reader).
(setf context-server)
(generic writer).
eval
(generic function).
html
(generic function).
js
(generic function).
make-buffered-context
(function).
make-context
(function).
start
(generic function).
stop
(generic function).
+default-callback+
(special variable).
+script-template+
(special variable).
context-buffer
(generic reader).
(setf context-buffer)
(generic writer).
context-callback
(generic reader).
(setf context-callback)
(generic writer).
context-handler
(generic reader).
(setf context-handler)
(generic writer).
context-record-p
(generic reader).
(setf context-record-p)
(generic writer).
context-timeout
(generic reader).
server-for-context
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Create a buffered context object.
Create a context object.
buffered-context
)) ¶buffered-context
)) ¶Whether or not the client is connected.
Send some JavaScript to evaluate remotely. Return the string.
buffered-context
) string) ¶Send JavaScript to evaluate, if the buffer is connected. Otherwise, add the code to the buffer.
If there’s anything in the buffer and the client is connected, send it all in
order before evaluating the string.
Return the HTML for this context.
Return the JS for this context.
Start the WebSockets server.
Stop the WebSockets server.
buffered-context
) &key) ¶The buffered context stores evaluation commands in a buffer until a client connects, then sends all of them at once.
A context object.
The address the WebSockets server will run on.
string
trivial-ws:+default-address+
:address
This slot is read-only.
The port the WebSockets server will run on.
integer
(find-port:find-port)
:port
This slot is read-only.
The number of seconds after which the WebSockets server will disconnect an inactive client.
integer
trivial-ws:+default-timeout+
:timeout
This slot is read-only.
The trivial-websockets server.
:server
The server handler.
:handler
Whether the server is running.
Whether or not to record sent HTML.
boolean
:recordp
The function that is called when the client sends a message.
remote-js::+default-callback+
:callback
buffered-context
)) ¶buffered-context
)) ¶A list of JavaScript strings to evaluate.
Jump to: | (
C E F G H I J M S |
---|
Jump to: | (
C E F G H I J M S |
---|
Jump to: | %
+
A B C H P R S T |
---|
Jump to: | %
+
A B C H P R S T |
---|
Jump to: | B C F M P R S |
---|
Jump to: | B C F M P R S |
---|