# all files / Core/Services/ RealTimeService.js

100% Statements 12/12
100% Branches 0/0
100% Functions 3/3
100% Lines 12/12

    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

    1

    1

    1

    1

    2

    1
    2
    2

    2
    1

    2

    1
     'use strict';

    // Utilities:
    var _ = require('lodash');

    // Dependencies:
    var socket = require('socket.io-client');

    // Module:
    var Core = require('../Core');

    var RealTimeService = function RealTimeService (
        config
    ) {
        return {
            connect: connect
        };

        function connect (room, events) {
            var url = 'http://localhost:' + config.port + '/' + room;
            var connection = socket.connect(url, {
                forceNew: true
            });
            _.each(events, function (handler, event) {
                connection.on(event, handler);
            });
            return connection;
        }
    };

    Core.service('realTimeService', RealTimeService);