Socket.io with require.js example setup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
// Require.js allows us to configure shortcut alias require.config({ // The shim config allows us to configure dependencies for // scripts that do not call define() to register a module shim: { 'socketio': { exports: 'io' }, 'underscore': { exports: '_' }, 'backbone': { deps: [ 'underscore', 'jquery' ], exports: 'Backbone' } }, paths: { jquery: 'jquery.min', underscore: 'lodash.min', backbone: 'backbone', socketio: '../socket.io/socket.io', } }); define([ 'jquery', 'backbone', 'socketio', ], function( $, Backbone, io ) { var socket = io.connect('https://localhost'); socket.on('news', function (data) { console.log(data); socket.emit('my other event', { my: 'data' }); }); //Ready to write Backbone Models and Socket.io communication protocol in here :) }); |
refs:
https://gist.github.com/guerrerocarlos/3651490/raw/adeab05cb881fb585f92827df35b085751e65ee3/main.js