Skip to content

@derickbailey /1.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
web sockets -> backbone app adapter
HIT = new Backbone.Marionette.Application();
// ... other settings here
// Socket.io Adapter
// -----------------
// This adapter forwards all socket.io 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;
HIT.vent.trigger("socket:connected");
});
socket.on("someData", function(data){
HIT.vent.trigger("someData", data);
});
socket.on("disconnect", function() {
SocketAdapter.connected = false;
HIT.vent.trigger("socket:disconnected");
});
socket.on("error", function(err){
console.log("ERROR: ", err);
});
};
HIT.addInitializer(initialize);
// Handle the event, start the app and the socket adapter
HIT.vent.on("someData", function(data){
alert("some data came through!");
});
HIT.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.