googlecreativelab / coder

A simple way to make web stuff on Raspberry Pi
http://goo.gl/coder
Apache License 2.0
2.43k stars 275 forks source link

socket.io #87

Closed odensc closed 10 years ago

odensc commented 10 years ago

I see there is some things for socket.io, like socketio_routes and Coder.socketConnection. Is there any documentation for this stuff?

odensc commented 10 years ago

Never mind. Figured out how to do it. For those wondering: Node:

exports.socketio_routes = [
    {
        key: "msg",
        handler: "msg_handler"
    },
];

exports.msg_handler = function(socket, data)
{
    socket.emit("appdata",
    {
        appid: exports.settings.appname,
        key: "msg",
        data: data
    });
};

JS:

$(function()
{
    Coder.socketConnection.init();
    Coder.socketConnection.addListener("msg", function(data)
    {
        console.log(data);
    });
    $("#btn").click(function()
    {
        Coder.socketConnection.sendData("msg", "hi!");
    });
});