<commit_before>/*
require('./Signaling-Server.js')(app, function(socket) {
    socket.on('custom-event', function(data) {
        socket.broadcast.emit('custom-event', data);
    });
});
*/

module.exports = exports = function(app, socketCallback) {
    var io = require('socket.io').listen(app, {
        log: false,
        origins: '*:*'
    });

    io.set('transports', [
        'websocket', // 'disconnect' EVENT will work only with 'websocket'
        'xhr-polling',
        'jsonp-polling'
    ]);

    var listOfUsers = {};
    var shiftedModerationControls = {};

    io.sockets.on('connection', function(socket) {
        var params = socket.handshake.query;
        var socketMessageEvent = params.msgEvent || 'RTCMultiConnection-Message';

        socket.userid = params.userid;

        listOfUsers[socket.userid] = {
            socket: socket,
            connectedWith: {},
            isPublic: false,
            extra: {}
        };

        socket.on('become-a-public-user', function() {
            if (!listOfUsers[socket.userid]) return;
            listOfUsers[socket.userid].isPublic = true;
        });

        socket.on('extra-data-updated', function(extra) {
            if (!listOfUsers[socket.userid]) return;
            listOfUsers[socket.userid].extra = extra;

            for (var user in listOfUsers[socket.userid].connectedWith) {
                listOfUsers[user].socket.emit('extra-data-updated', socket.userid, extra);
            }
        });

        socket.on('changed-uuid', function(newUserId) {
            if (listOfUsers[socket.userid]) {
                if (newUserId === socket.userid) return;

                var oldUserId = socket.userid;
                listOfUsers[newUserId] = listOfUsers[oldUserId];
                listOfUsers[newUserId].socket.userid = socket.userid = newUserId;
                delete listOfUsers[oldUserId];
                return;
            }

            socket.userid = newUserId;
            listOfUsers[socket.userid] = {
                socket: socket,
                connectedWith: {},
                isPublic: false,
                extra: {}
            };
        });

        socket.on('set-password', function(password) {
			if (listOfUsers[socket.userid]) {
				listOfUsers[socket.userid].password = password;
			}
        });

        socket.on('disconnect-with', function(remoteUserId, callback) {
            if (listOfUsers[socket.userid] && listOfUsers[socket.userid].connectedWith[remoteUserId]) {
                delete listOfUsers[socket.userid].connectedWith[remoteUserId];
                socket.emit('user-disconnected', remoteUserId);
            }

            if (!listOfUsers[remoteUserId]) return callback();

            if (listOfUsers[remoteUserId].connectedWith[socket.userid]) {
                delete listOfUsers[remoteUserId].connectedWith[socket.userid];
                listOfUsers[remoteUserId].socket.emit('user-disconnected', socket.userid);
            }
            callback();
        });

        function onMessageCallback(message) {<commit_msg>Fixed tab indentation<commit_after>/*
require('./Signaling-Server.js')(app, function(socket) {
    socket.on('custom-event', function(data) {
        socket.broadcast.emit('custom-event', data);
    });
});
*/

module.exports = exports = function(app, socketCallback) {
    var io = require('socket.io').listen(app, {
        log: false,
        origins: '*:*'
    });

    io.set('transports', [
        'websocket', // 'disconnect' EVENT will work only with 'websocket'
        'xhr-polling',
        'jsonp-polling'
    ]);

    var listOfUsers = {};
    var shiftedModerationControls = {};

    io.sockets.on('connection', function(socket) {
        var params = socket.handshake.query;
        var socketMessageEvent = params.msgEvent || 'RTCMultiConnection-Message';

        socket.userid = params.userid;

        listOfUsers[socket.userid] = {
            socket: socket,
            connectedWith: {},
            isPublic: false,
            extra: {}
        };

        socket.on('become-a-public-user', function() {
            if (!listOfUsers[socket.userid]) return;
            listOfUsers[socket.userid].isPublic = true;
        });

        socket.on('extra-data-updated', function(extra) {
            if (!listOfUsers[socket.userid]) return;
            listOfUsers[socket.userid].extra = extra;

            for (var user in listOfUsers[socket.userid].connectedWith) {
                listOfUsers[user].socket.emit('extra-data-updated', socket.userid, extra);
            }
        });

        socket.on('changed-uuid', function(newUserId) {
            if (listOfUsers[socket.userid]) {
                if (newUserId === socket.userid) return;

                var oldUserId = socket.userid;
                listOfUsers[newUserId] = listOfUsers[oldUserId];
                listOfUsers[newUserId].socket.userid = socket.userid = newUserId;
                delete listOfUsers[oldUserId];
                return;
            }

            socket.userid = newUserId;
            listOfUsers[socket.userid] = {
                socket: socket,
                connectedWith: {},
                isPublic: false,
                extra: {}
            };
        });

        socket.on('set-password', function(password) {
            if (listOfUsers[socket.userid]) {
                listOfUsers[socket.userid].password = password; 
            }
        });

        socket.on('disconnect-with', function(remoteUserId, callback) {
            if (listOfUsers[socket.userid] && listOfUsers[socket.userid].connectedWith[remoteUserId]) {
                delete listOfUsers[socket.userid].connectedWith[remoteUserId];
                socket.emit('user-disconnected', remoteUserId);
            }

            if (!listOfUsers[remoteUserId]) return callback();

            if (listOfUsers[remoteUserId].connectedWith[socket.userid]) {
                delete listOfUsers[remoteUserId].connectedWith[socket.userid];
                listOfUsers[remoteUserId].socket.emit('user-disconnected', socket.userid);
            }
            callback();
        });

        function onMessageCallback(message) {
{'fraction_non_alphanumeric': 0.12982399483287582, 'fraction_numerical': 0.0, 'mean_word_length': 2.0333006856023506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5384749', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1689, 'n_words': 260}