angular-sockets

Easy to use sockets module for angularjs.

Added by: Sam Deering

GitHub

Repository

cristianbote/angular-sockets

Stats

Stars: 1

Watchers: 1

Forks: 0

Module Description

angular-sockets

Easy to use sockets module for angularjs.

A. Usage

It's pretty straight forward, just include the version you want, import it in your app module definition and inside the app config method define the server's ip. Take a look inside the demo folder as well.

Example:

app.config(["$socketsProvider", function($socketsProvider) {

    /* Store the server ip */
    $socketsProvider.setup({
        server: 'ws://127.0.0.1:8080',
        handlers: {
            /* Just needs to be a refference there */
            customSocketCallback: null
        }
    });
}]);


/* Main controller */
function MainCtrl($scope, $sockets) {
    /* Register handlers for events */
    $sockets.setup({
        handlers: {
            onopen: function() {
                console.log("onopen");
            },

            /* Listens for incomming messages */
            onmessage: function(a) {
                console.log("onmessage", a);
                if (a && a.type !== "greet") {
                    $scope.messages.push(a);
                    $scope.$digest();
                }
            },

            /* On close */
            onclose: function() {
                console.log("onclose");
            },

            customSocketCallback: function() {
                //magical stuff
            }
        }
    });

    /*
        Then when you're ready, call: $sockets.send(<string>);
    */
}

B. Feedback

I need feedback :)

Module stats last updated: 2015-04-19 02:28:24

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!