Photon Paw

An easy and convenient lib to add HTML-based UI to a console app

License

License

Categories

Categories

Net
GroupId

GroupId

net.timzh
ArtifactId

ArtifactId

photon-paw
Last Version

Last Version

0.10.0
Release Date

Release Date

Type

Type

jar
Description

Description

Photon Paw
An easy and convenient lib to add HTML-based UI to a console app
Project URL

Project URL

http://timzh.net/photon-paw/
Source Code Management

Source Code Management

http://github.com/tim-zh/photon-paw/tree/master

Download photon-paw

How to add to project

<!-- https://jarcasting.com/artifacts/net.timzh/photon-paw/ -->
<dependency>
    <groupId>net.timzh</groupId>
    <artifactId>photon-paw</artifactId>
    <version>0.10.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.timzh/photon-paw/
implementation 'net.timzh:photon-paw:0.10.0'
// https://jarcasting.com/artifacts/net.timzh/photon-paw/
implementation ("net.timzh:photon-paw:0.10.0")
'net.timzh:photon-paw:jar:0.10.0'
<dependency org="net.timzh" name="photon-paw" rev="0.10.0">
  <artifact name="photon-paw" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.timzh', module='photon-paw', version='0.10.0')
)
libraryDependencies += "net.timzh" % "photon-paw" % "0.10.0"
[net.timzh/photon-paw "0.10.0"]

Dependencies

compile (3)

Group / Artifact Type Version
io.undertow : undertow-core jar 2.0.28.Final
commons-logging : commons-logging jar 1.2
net.sourceforge.htmlunit : htmlunit jar 2.36.0

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.5.2
org.junit.jupiter : junit-jupiter-engine jar 5.5.2
org.junit.jupiter : junit-jupiter-params jar 5.5.2

Project Modules

There are no modules declared in this project.

PhotonPaw

Maven Central

CircleCI

Backend Example:

new net.timzh.photonpaw.PhotonPaw()
    //optional, configure main port and websocket port
    .ports(19081, 19082)

    //set location of static resources if any, empty string to refer to jar resources
    .resourcesRoot("")

    //add additional routes if static resources are not enough
    .bindPath("/test", request -> UiHttpResponse.of("application/javascript", "alert('custom routing')"))

    //subscribe to events from ui by name
    .handleCommand("a", (msg, out) -> System.out.println("command received"))

    //subscribe to requests from ui that expect some response
    .handleQuery("b", msg -> "server response")

    //subscribe to events with dynamic names
    .defaultHandler((msg, out) -> System.out.println("unknown event " + msg))

    //execute some code after establishing a connection with ui
    .start(out ->

         //send an event to ui
         out.send("b", "server command")
    )

    .println("ui server started")
    .openBrowser("/index.html")
    .waitForTabToUnload()
    .stop();

Frontend Example:

<!DOCTYPE html>
<html>
<body>
<script src="photonpaw_client.js"></script>
<script>
PhotonPaw
    //subscribe to events from ui server by name
    .handleCommand("a", msg => alert("command received"))

    //subscribe to events with dynamic names
    .defaultHandler((event, msg) => alert("unknown event " + event + " " + msg))

    //execute some code after establishing the connection with ui server
    .start().then(() => {

        //send an event to ui server
        PhotonPaw.send("b", "ui command");

        //send a request to ui server and process the response
        PhotonPaw.ask("c", "ui query").then(response => alert("query response received"));
    });
</script>
</body>
</html>

Versions

Version
0.10.0
0.9.2
0.9.1
0.9.0