Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
web sockets -> backbone app adapter
HIT = new Backbone.Marionette.Application();
// ... other settings here
// Adapter
// -----------------
// This adapter forwards all events
// to the application's event aggregator. The
// intention of this is to decouple the specific
// websockets implementation from the application's
// use of it.
var socket;
var initialize = function() {
socket = io.connect(HIT.socketUrl);
socket.on("connect", function() {
SocketAdapter.connected = true;
socket.on("someData", function(data){
HIT.vent.trigger("someData", data);
socket.on("disconnect", function() {
SocketAdapter.connected = false;
socket.on("error", function(err){
console.log("ERROR: ", err);
// Handle the event, start the app and the socket adapter
HIT.vent.on("someData", function(data){
alert("some data came through!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment