Git Product home page Git Product logo

play-sockjs-1's Introduction

play-sockjs

Play2 plugin for SockJS (Not ready yet for using it)

  • So far, you can add only one sockjs

How to use

  1. Clone the repo to your local machine
	git clone https://github.com/ashihaby/play-sockjs.git
  1. Compile and publish the plugin to local play repo
	cd play-sockjs/project-code
	play publish-local
  1. Add it to your play project dependencies
	val sockjs = "play-sockjs" % "play-sockjs_2.10" % "1.0-SNAPSHOT"
	val appDependencies = Seq(
	  sockjs
	)
  1. Include the pluing in conf/play.plugins
	10000:com.cloud9ers.play2.sockjs.SockJsPlugin
  1. Write your controller and inherit from SockJsTrait
	package controllers
	
	import com.cloud9ers.play2.sockjs.SockJs
	
	import play.api.libs.concurrent.Promise
	import play.api.libs.iteratee.{Concurrent, Iteratee}
	import play.api.libs.json.JsValue
	import play.api.mvc.{Controller, RequestHeader}
	
	object SockJsService extends Controller with SockJs {
	  def handler(rh: RequestHeader) = {
	    val (enumerator, channel) = Concurrent.broadcast[JsValue]
	    val iteratee = Iteratee.foreach[JsValue] { msg =>
	      // msg: is the message comming from the client
	      // channel: is where you send messages to the client
	      channel push msg // just send back the message
	    }
	    Promise.pure(iteratee, enumerator)
	  }
	
	  def sockJsAction = SockJs.async(handler)
	
	  def websocket[String] = SockJs.websocket(handler)
	}
  1. Add object Global in the default package in Global.scala
    • This is required so far to avoid play routing because sockjs requires complex routing scheme
    • We hope to find a better approach soon
	import com.cloud9ers.play2.sockjs.SockJsGlobalSettings
	
	object Global extends SockJsGlobalSettings {
	  def sockJsAction = controllers.SockJsService.sockJsHandler
	  def sockJsWebsocket = controllers.SockJsService.websocket
	}
  1. Finnaly, you need to add the base Url to the configuration in application.con
	sockjs.prefix=echo
  • Full configurations:
	sockjs.prefix=echo
	sockjs.responseLimit=1000
	sockjs.jsessionid=false
	sockjs.heartbeetDelay=1000
	sockjs.diconnectDelay=5000
	sockjs.websocketEnabled=false
	sockjs {
	 akka {
	  stdout-loglevel = "DEBUG"
	  loglevel = "DEBUG"
	    log-dead-letters = 10
	    log-dead-letters-during-shutdown = on
	  }
	}

play-sockjs-1's People

Contributors

lambda-mostafa avatar

Watchers

Dmitry Kurinskiy avatar James Cloos 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.