Home

Awesome

socket.io for Play! Framework 2.0 (for Scala)

Socket.io server sode support for Play framework.

What is socket.io?

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.

Features

TODO

How To Use

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)

Note:

I found a bug

Please report it in github issues

Need help running it?

Mail -

saurabh.rawat90@gmail.com

Please mention socket.io.play in the subject.

This is great! I want to use it on my project!

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.