Skip to content
forked from blopker/WAMPlay

WAMP implementation for the Play! Framework

License

Notifications You must be signed in to change notification settings

dkichler/WAMPlay

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

WAMP implementation for the Play! Framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published