Realtime server and client library built on Socket.IO. Simple to setup and straight forward API for sending and receiving messages, managing permissions. Goal is for everyone to feel enabled to have realtime interactions in their apps. If you are enterprise you may choose options such as PubNub or Pusher, if you are experimenting or want to roll your own infrastructure Hatchet hopefully helps.
Checkout http://hatchet.io.s3-website-ap-southeast-2.amazonaws.com/ for more info.
More documentation coming soon. Bootstrappin at the moment.
You can send messages to connected subscribers by simply POSTing JSON data to a URL. See the example below. This means you can integrate Hatchet into your Ruby, PHP, Java, etc projects without needing to write a line of NodeJS code.
curl -v -H "Content-Type: application/json" -X POST -d '{ "auth": { "channel": "demo", "secret": "pub-token" }, "data": { "event": "log", "data": { "line": 100, "file": "test.js" } }}' http://api.hatchet.io/message
Install the module with: npm install hatchet.io
var hatchet = require('hatchet.io');
var subscriber = hatchet.subscriber('demo', 'sub-token', { log: true });
// Watch for 'log' events and run the defined function when it occurs
subscriber.watch('log', function(data) {
console.log('log', data);
});
// Watch another
subscriber.watch('signup', function(data) {
console.log('signup', data);
});
// You can also stop listening to an event
setTimeout(function() {
subscriber.unwatch('log');
}, 20000);
var hatchet = require('hatchet.io');
var publisher = hatchet.publisher('demo', 'pub-token', { log: true });
// Send 'log' event with data every 2 seconds
setInterval(function() {
var data = {
line: 100,
file: 'ben.txt'
};
publisher.broadcast('log', data);
}, 2000);
// Send 'signup' event with data every second
setInterval(function() {
var data = {
firstName: 'Frederick',
lastName: 'Gustaveerson',
created: new Date()
};
publisher.broadcast('signup', data);
}, 1000);
{
log: false // when enabled it will console.log out hatchet related log messages
host: 'api.hatchet.io', // change this to your Hatchet.IO instance
ports: {
subcribers: 5223,
publishers: 5224
}
}
HatchetSubscriber *subscriber = [[HatchetSubscriber alloc] init];
subscriber.delegate = self;
[subscriber auth:@"demo" secret:@"sub-token"];
[subscriber watch:@"log"];
...
- (void)hatchetEvent:(NSString *)event data:(NSDictionary *)data {
NSLog(@"Event: %@ Data: %@", event, data);
}
HatchetPublisher *publisher = [[HatchetPublisher alloc] init];
publisher.delegate = self;
[publisher auth:@"demo" secret:@"pub-token"];
[publisher broadcast:@"log" data:@{
@"line": @(100),
@"file": @"Hatchet.m"
}];
Please feel free to contribute. If you see any areas for improvement, particularly in regards to performance / reliability / security it'd be great to receive your pull requests / comments because it's really the main crux of the application.
- All code to date. Includes server, npm module, js client and objective c code.
Copyright (c) 2013 Ben Pearson Licensed under the MIT license.