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!
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/")
)
Add a WAMP endpoint to your routes file:
# Send websocket connections to the WAMPlay server
GET /wamp ws.wamplay.controllers.WAMPlayServer.connect()
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);
}
}
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());
}
}
Now head over to the RPC Sample Index to see how to use AutobahnJS with your new server!
- No support for prefix messages
- This is currently in beta state, there may be bugs and the API may change
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.