There is some issues with the code from Peter, and with the new improvements on node.js 0.6 this lib don't work correctly.Work fine only with node.js 0.4
Please be sure of use node.js 0.4 (recommended 0.4.12) before use this lib.
Hook listening messages on WebSocket client connection.
Based on Peter Griess work. WebSocket Nodejs Client
npm install hook.io-ws
hookio-ws
Now you can require the hook.io-ws
module and instance a new Hook that try to connect to url
using WebSockets
#!/usr/bin/env node
var WebSocketHook = require('hook.io-ws').HookSocket;
var mtgoxTest = new WebSocketHook({
name: 'mtgox',
url:'ws://websocket.mtgox.com/mtgox',
debug:false
});
mtgoxTest.start();
Or you can use the Hook.io Magic
/*
* Hook class for interacting with mtgox.com
*/
var Hook = require('hook.io').Hook,
util = require('util');
var MtgoxHook = exports.MtgoxHook = function(options){
Hook.call(this, options);
var self = this;
self.on('hook::ready', function(){
/// Spawn a new hook as type have "ws"
self.spawn([{
"name": "mtgox-ws-hook",
"type": "ws", // Doing this. Hook.io will look for hook.io-ws
"debug": "false",
"url": "ws://websocket.mtgox.com/mtgox"
}], function(err){
// spawn ready
self.on('*::websocket::message',function(message){
if(message.op === 'subscribe') {
self.emit('subscribe', message);
} else {
self.emit(message.private, message);
}
});
});
});
};