Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Hook for messages on a websocket client
JavaScript
tree: 087f6a2c07

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
.gitignore
README.md
config.json
package.json

README.md

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-websocket

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.