Permalink
Browse files

Update code to use socket.io 0.7 API.

  • Loading branch information...
1 parent b6b6d66 commit 72a1c6ad7de183f5fa72b5f0ab830c46fa1e9cd4 @andrewdavey committed Jul 20, 2011
Showing with 9 additions and 17 deletions.
  1. +4 −7 src/VogueClient.js
  2. +4 −9 src/client/vogue-client.js
  3. +1 −1 src/vogue.js
View
@@ -7,16 +7,13 @@ function VogueClient(clientSocket, watcher) {
this.socket = clientSocket;
this.watcher = watcher;
this.watchedFiles = {};
- clientSocket.on('message', this.handleMessage.bind(this));
+ clientSocket.on('watch', this.handleMessage.bind(this));
clientSocket.on('disconnect', this.disconnect.bind(this));
}
// Parse an incoming message from the client and dispatch accordingly.
-VogueClient.prototype.handleMessage = function(message) {
- var match = message.match(/^watch (.*)$/);
- if (!match) return;
- var href = match[1];
- this.watchFile(href);
+VogueClient.prototype.handleMessage = function(data) {
+ this.watchFile(data.href);
};
VogueClient.prototype.watchFile = function(href) {
@@ -46,7 +43,7 @@ VogueClient.prototype.updateFile = function(filename) {
// Only send message to client if the file was modified
// since we last saw it.
if (fileInfo.mtime < stats.mtime) {
- this.socket.send('update ' + fileInfo.href);
+ this.socket.emit('update', { href: fileInfo.href });
fileInfo.mtime = stats.mtime;
}
}.bind(this));
View
@@ -13,23 +13,18 @@ loadScripts({
function vogue() {
window.WEB_SOCKET_SWF_LOCATION = script.url + 'socket.io/lib/vendor/web-socket-js/WebSocketMain.swf';
var stylesheets = getLocalStylesheets();
- var socket = new io.Socket(script.domain, { port: script.port });
+ var socket = io.connect("http://" + script.domain + ":" + script.port);
socket.on('connect', watchAllStylesheets);
- socket.on('message', handleMessage);
- socket.connect();
+ socket.on('update', handleMessage);
function watchAllStylesheets() {
for (var href in stylesheets) {
- socket.send('watch ' + href);
+ socket.emit('watch', { href: href });
}
}
function handleMessage(message) {
- var match = message.match(/^update (.*)$/);
- if (match) {
- var href = match[1];
- reloadStylesheet(href);
- }
+ reloadStylesheet(message.href);
}
function reloadStylesheet(href) {
View
@@ -25,7 +25,7 @@ var options = getOptions()
, watcher = new Watcher(options.webDirectory,options.rewrite);
server.listen(options.port);
-socket.on('connection', function(clientSocket) {
+socket.sockets.on('connection', function(clientSocket) {
watcher.addClient(new VogueClient(clientSocket, watcher));
});

0 comments on commit 72a1c6a

Please sign in to comment.