comm_socket.on("connect", () => {
    let list = [];
    for (let id in state) {
        list.push(id);
    }
    if (list.length) {
        comm_socket.send("user/monitor", list);
    }
});
 setTimeout(() => {
     comm_socket.send("user/monitor", subscribe_queue);
     subscribe_queue = null;
 }, 1);
Example #3
0
 send: (event, data) => {
     comm_socket.send("itc", {"event": event, "data": data});
 }
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import {comm_socket} from "sockets";
import {EventEmitter} from "eventemitter3";

let listeners: {[id: number]: Array<any>} = {};
let state = {};
let event_emitter = new EventEmitter();

comm_socket.on("connect", () => {
    let list = [];
    for (let id in state) {
        list.push(id);
    }
    if (list.length) {
        comm_socket.send("user/monitor", list);
    }
});

comm_socket.on("user/state", (states) => {
    let i;
    for (let id in states) {
        state[id] = states[id];
        for (i = 0; i < listeners[id].length; ++i) {
            listeners[id][i](id, state[id]);
        }
    }
    event_emitter.emit("users-online-updated");
});
Example #5
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* Inter tab communications library */
import {comm_socket} from "sockets";

let registrations = {};

comm_socket.on("itc", (obj) => {
    if (obj.event in registrations) {
        for (let i = 0; i < registrations[obj.event].length; ++i) {
            registrations[obj.event][i](obj.data);
        }
    }
});

export default {
    register: (event, cb) => {
        if (!(event in registrations)) {
            registrations[event] = [];
        }
        registrations[event].push(cb);
    },
    send: (event, data) => {
        comm_socket.send("itc", {"event": event, "data": data});
    }
};