<commit_before>import QtWebSockets 1.0

WebSocketServer {
    id: server

    name: 'QakDebugServer'

    listen: true
    port: 40402

    property var clients: ({})

    property int clientId: 0

    signal connectionError(string errorString)

    signal messageReceived(string message)


    onClientConnected: {
        clients['qdbs-'+clientId] = webSocket
        console.debug('Client',clientId,'connected')

        webSocket.onTextMessageReceived.connect(function(message) {
            for(var id in clients) {
                if(clients[id] === webSocket) {
                    console.info('Message from',id,message)
                    webSocket.sendTextMessage(id)
                    messageReceived(message)
                }
            }
        });

        webSocket.onStatusChanged.connect(function(status) {
            for(var id in clients) {
                if(clients[id] === webSocket) {
                    if (status === WebSocket.Error) {
                        console.error('Qak.Debug.DebugServer','websocket to client',id,'error',webSocket.errorString)
                    } else if (status === WebSocket.Closed) {
                        console.info('Qak.Debug.DebugServer','websocket to client',id,'closed connection')
                        clients[id] = undefined
                    } else if (status === WebSocket.Closing) {
                        console.info('Qak.Debug.DebugServer','websocket to client',id,'closing connection')
                    } else if (status === WebSocket.Connecting) {
                        console.info('Qak.Debug.DebugServer','websocket to client',id,'is connecting')
                    } else if (status === WebSocket.Open) {
                        console.info('Qak.Debug.DebugServer','websocket to client',id,'connected')
                    } else
                        console.error('Qak.Debug.DebugServer','websocket to client',id,'unknown status',status)
                }
            }
        });

        clientId++
    }

    onErrorStringChanged: {
        connectionError(server.errorString)
    }

}

<commit_msg>Swag is comming<commit_after>import QtWebSockets 1.0

WebSocketServer {
    id: server

    name: 'QakDebugServer'

    listen: true
    port: 40402

    property var clients: ({})

    property int clientId: 0

    signal connectionError(string errorString)

    signal request(var client, var request)

    function extend(target, source) {
        target = target || {}
        for (var prop in source) {
            if (typeof source[prop] === 'object')
                target[prop] = extend(target[prop], source[prop])
            else
                target[prop] = source[prop]
        }
        return target
    }

    function getClientId(ws) {
        for(var id in clients) {
            var client = clients[id]
            if('socket' in client && client.socket === ws)
                return id
        }
        return
    }

    function getClient(cid) {
        return clients[cid]
    }

    function handleRequest(cid, message) {

        var client = getClient(cid)
        if(client) {
            if(isJSON(message)) {
                message = JSON.parse(message)

                if('r' in message && message.r === 'auth') {
                    var rId = { auth: cid }
                    client.socket.sendTextMessage(JSON.stringify(rId))
                    return
                }

                if('auth' in message) {
                    if('log' in message && 'type' in message) {
                        if(message.type === 'log')
                            console.log(message.log)
                        if(message.type === 'info')
                            console.info(message.log)
                        if(message.type === 'error')
                            console.error(message.log)
                        if(message.type === 'warn')
                            console.warn(message.log)
                        if(message.type === 'debug')
                            console.debug(message.log)
                    }

                    request(client,message)
                } else {
                    console.error('Client',cid,'with message',message,'is not authorized')
                }

            } else
                console.info('Raw message from',cid,message)
        } else
            console.error('Unknown client',cid,message)
    }

    function isJSON(str) {
        try {
            JSON.parse(str)
        } catch (e) {
            return false
        }
        return true
    }

    onClientConnected: {
        clientId++
        clients['qdbs-'+clientId] = { id: 'qdbs-'+clientId, socket: webSocket }

        console.debug('Qak.Debug.DebugServer','client',clientId,'connected')

        webSocket.onTextMessageReceived.connect(function(message) {
            var id = getClientId(webSocket)
            if(id)
                handleRequest(id,message)
            else
                console.error('Qak.Debug.DebugServer','can\'t handle client request from websocket',webSocket,'body',message)
        });

        webSocket.onStatusChanged.connect(function(status) {
            for(var id in clients) {
                if(clients[id] === webSocket) {
                    if (status === WebSocket.Error) {
                        console.error('Qak.Debug.DebugServer','websocket to client',id,'error',webSocket.errorString)
                    } else if (status === WebSocket.Closed) {
                        console.info('Qak.Debug.DebugServer','websocket to client',id,'closed connection')
                        clients[id] = undefined
                    } else if (status === WebSocket.Closing) {
                        console.info('Qak.Debug.DebugServer','websocket to client',id,'closing connection')
                    } else if (status === WebSocket.Connecting) {
                        console.info('Qak.Debug.DebugServer','websocket to client',id,'is connecting')
                    } else if (status === WebSocket.Open) {
                        console.info('Qak.Debug.DebugServer','websocket to client',id,'connected')
                    } else
                        console.error('Qak.Debug.DebugServer','websocket to client',id,'unknown status',status)
                }
            }
        });


    }

    onErrorStringChanged: {
        connectionError(server.errorString)
    }

}


{'fraction_non_alphanumeric': 0.11206492898392384, 'fraction_numerical': 0.0024972686124551274, 'mean_word_length': 1.5652522017614092, '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': '4790615', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1581, 'n_words': 308}