Git Product home page Git Product logo

photon-paw's Introduction

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>

photon-paw's People

Contributors

tim-zh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.