overte-org / overte

Overte open source virtual worlds platform.
https://overte.org/
Other
132 stars 48 forks source link

WebSocketServer JS API is badly documented #788

Open ksuprynowicz opened 5 months ago

ksuprynowicz commented 5 months ago

It doesn't show how to open websocket server on a given port, even though this is possible and it's extremely important feature.

Relevant C++ code:

ScriptValue WebSocketServerClass::constructor(ScriptContext* context, ScriptEngine* engine) {
    // the serverName is used in handshakes
    QString serverName = QStringLiteral("HighFidelity - Scripted WebSocket Listener");
    // port 0 will auto-assign a free port
    quint16 port = 0;
    ScriptValue callee = context->callee();
    if (context->argumentCount() > 0) {
        ScriptValue options = context->argument(0);
        ScriptValue portOption = options.property(QStringLiteral("port"));
        if (portOption.isValid() && portOption.isNumber()) {
            port = portOption.toNumber();
        }
        ScriptValue serverNameOption = options.property(QStringLiteral("serverName"));
        if (serverNameOption.isValid() && serverNameOption.isString()) {
            serverName = serverNameOption.toString();
        }
    }
    return engine->newQObject(new WebSocketServerClass(engine, serverName, port), ScriptEngine::ScriptOwnership);
}
daleglass commented 5 months ago

Dev meeting: we should think about whether this has security implications