Code coverage report for Model/SocketServices.js

Statements: 52.94% (9 / 17)      Branches: 0% (0 / 2)      Functions: 40% (4 / 10)      Lines: 52.94% (9 / 17)      Ignored: none     

All files » Model/ » SocketServices.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                                    1     1 38 38   216                                       1   49 38     49    
/*jshint node: true */
'use strict';
 
/*
* Name :  SocketServices.js
* Module : FrontEnd::Model
* Location : /frontend/app/Model
*
* History :
* Version       Date        Programmer                  Description
* =================================================================================================
* 0.1.0         2015-05-12  Maria Giovanna Chinellato   Add all attributes and all methods
*
* 0.0.1         2015-05-12  Maria Giovanna Chinellato   Initial code      
* =================================================================================================
*
*/
 
angular.module('norris-nrti')
.factory('SocketServicesFactory', function ($rootScope) {
 
    function SocketServices(url) {
        var socket = io.connect(url);
        return {
            on: function (eventName, callback) {
                socket.on(eventName, function () {
                    var args = arguments;
                    $rootScope.$apply(function () {
                        callback.apply(socket, args);
                    });
                });
            },
            emit: function (eventName, data, callback) {
                socket.emit(eventName, data, function () {
                    var args = arguments;
                    $rootScope.$apply(function () {
                        if (callback) {
                            callback.apply(socket, args);
                        }
                    });
                });
            }
        };
    }
 
    function SocketServicesFactory() {}
 
    SocketServicesFactory.build = function (url) {
        return new SocketServices(url);
    };
 
    return SocketServicesFactory;
 
});