Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Hook for messages on a websocket client
JavaScript
tree: 48b7677c91

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
.gitignore
README.md
config.json Remove whitespace [Gun.io WhitespaceBot]
package.json

README.md

Node.js Compatibility

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.io-ws

Hook listening messages on WebSocket client connection.

Based on Peter Griess work. WebSocket Nodejs Client

Contributors

Requirements

Installation

npm install hook.io-ws

Usage

hookio-ws

Development Example

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);
        }

      });
    });
  });
};

Author

Something went wrong with that request. Please try again.