On Github hydna / remote-control
Presentation by Isak Wiström <iw@hydna.com>
To control this slideshow from your iOS or Android phone (through Hydna): Visit bit.ly/18jEDRL and enter the following code:
2459
Slideshow code courtesy of reveal.js.
Hydna is a hosted backend into which you can send data and have it instantly appear on other devices.
Transports are the different protocols clients can use to communicate with Hydna. The following are currently supported:
WebSockets - Binary TCP - Flash - Comet - HTTP/Push
Routing is the act of accepting data from a sender and delivering it to the intended recipients. Routing works across transports.
Behaviors are small snippets of JavaScript that you deploy to Hydna's infrastructure. They are used to instruct Hydna how to behave when clients perform different actions (open channels, emit signals etc).
Authentication, communication with external services, global state etc
Hydna is ideal for building dashboards, activity streams, notification- and chat systems, real-time collaboration, live statistics, remote controls, multiplayer games, and more.
Client libraries detect and select best available transport.
JavaScript, Node.js, Erlang, Java, Objective-C, C++
Python, PHP, Ruby, Go etc.
// open a channel on the domain `public.hydna.net` in read and write mode. var channel = new HydnaChannel('public.hydna.net/hello-world', 'rw'); // register an event handler that alerts the data-part of messages when // they are received. channel.onmessage = function(e) { alert(e.data); }; // send a message immediately when the channel has been opened. channel.onopen = function() { channel.send('Hello there!'); };
Hydna Push API example
Javascript example
Simple HTTP interface. Limited to sending messages and emitting signals. Does not require a client library. Example using curl:
curl --data "hello world" http://public.hydna.net/hello-push
Python example
Push API example
Full documentation on GitHub
import hydna # send a message hydna.push('public.hydna.net/hello-push', 'test') # emit a signal hydna.emit('public.hydna.net/hello-emit', 'test')
Ruby example
Python example
Full documentation on GitHub
require 'hydna' # send a message Hydna.push('public.hydna.net/hello-push', 'test') # emit a signal Hydna.emit('public.hydna.net/hello-emit', 'test')
PHP example
Ruby example
Full documentation on GitHub
require("hydna-push.php"); $hydna = new Hydna(); try { // send a message $hydna->push("http://public.hydna.net/hello-push", "Hello World!"); // emit a signal $hydna->emit("http://public.hydna.net/hello-emit", "Hello World!"); } catch(Exception $e) { print $e->getMessage(); }
behavior('/admin', { open: function(event) { if (event.write) { // the client requested to write to the channel. let's examine // whether the token matches the secret password. if (event.token != 'secret password') { event.deny('Not allowed to write to channel.'); } else { event.allow('Allowed to write to channel.'); } } else { // the client did not request to write, we can allow that // without looking at the token. event.allow('Allowed to read from channel.'); } } });