Coder Social home page Coder Social logo

wamplay's Introduction

Logo

About

This is a WAMP implementation for the Play! Framework. Use it to add RPC and Pub/Sub websocket functionality to your site!

If this project helps you, please star it!

Getting Started

Build.scala

First add WAMPlay to appDependencies in the Build.scala file:

"ws.wamplay" %% "wamplay" % "0.1.6"

Then add the WAMPlay repo in the same file:

val main = play.Project(appName, appVersion, appDependencies).settings(
  resolvers ++= Seq("WAMPlay Repository" at "http://blopker.github.com/maven-repo/")
)

routes

Add a WAMP endpoint to your routes file:

# Send websocket connections to the WAMPlay server
GET     /wamp                     ws.wamplay.controllers.WAMPlayServer.connect()

WAMPlayController

Create a class that extends WAMPlayController. This is where your application will interact with clients. For more information on the annotations check out Annotations.

@URIPrefix("http://example.com/sample")
public class SampleController extends WAMPlayContoller {

	@onRPC("#meaningOfLife")
	public static String getMeaningOfLife(String sessionID) {
		return "Meaning of life is: 42";
	}

	@onRPC("#capital")
	public static String add(String sessionID, JsonNode[] args) {
		String ans = args[0].asText().toUpperCase();
		return ans;
	}

	@onSubscribe("/chat")
	public static boolean capitalSubscribe(String sessionID) {
		return true;
	}

	@onPublish("/chat")
	public static JsonNode truncatePublish(String sessionID, JsonNode event) {
		return Json.toJson(event);
	}
}

Global.java

In your Global.java file override onStart and add your controller to the WAMPlayServer.

public class Global extends GlobalSettings {
	@Override
	public void onStart(Application app) {
		WAMPlayServer.addController(new SampleController());
	}
}

Your server is ready!

Now head over to the RPC Sample Index to see how to use AutobahnJS with your new server!

Limitations

  • No support for prefix messages
  • This is currently in beta state, there may be bugs and the API may change

Samples

Check out the samples to see how to include WAMPlay in your app!

WAMPlay was made in conjunction with Pheme. You should look here for a real-world example.

wamplay's People

Contributors

blopker avatar

Watchers

Dave Kichler 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.