socket.io with play framework 2.0
Socket.io server sode support for Play framework.
socket.io provides browser independent bidirectional realtime socket-like communication between server ad browser. From socket.io site
Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It's care-free realtime 100% in JavaScript.
The easiest way to getting started would be to look at the sample app.
Manual Steps:
The below mentioned repo might not be updated, so it's best to compile and publish locally.
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings( resolvers += "OSS Repo" at "https://oss.sonatype.org/content/repositories/snapshots" )
"com.imaginea" %% "socket.io.play" % "0.0.3-SNAPSHOT"
Inside this implement the partial function, 'processMessage' which will handle the events/messages. Set clientTimeout to a duration(in seconds) for timeouts for heartbeat, client.
An example implementation from sample -
object MySocketIOController extends SocketIOController {val clientTimeout = Timeout(10.seconds) def processMessage(sessionId: String, packet: Packet) { ... } }
You have these functions to enqueue events/messages to clients:
def enqueueMsg(sessionId: String, msg: String)def enqueueEvent(sessionId: String, event: String) def enqueueJsonMsg(sessionId: String, msg: String) def broadcastMsg(msg: String) def broadcastEvent(event: String) def broadcastJsonMsg(msg: String)
GET /socket.io/1/$socketUrl<.> controllers.MySocketIOController.handler(socketUrl)
There is a parser available to you, all the events/messages that you enqueue are supposed to be already encoded strings. Use encodePacket from Parser. See sample app for details.
You get a sessionId in the processMessage, you can maintain a sessionId container and process events specific to clients.
Please report it in github issues
Mail -
Please mention socket.io.play in the subject.
Glad that you like it, go ahead and use it. It is licensed under Apache License, Version 2.0.
If possible put a mail to us, opensource at imaginea dot com.