I found, that connecting from a webassembly websocket client to a wss server works with the sshechoclient and sshechoserver example programs by doing a little modification to the sshechocilent program: delete or comment out the parts which relate to security:
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "sslechoclient.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtWebSockets/QWebSocket>
QT_USE_NAMESPACE
//! [constructor]
SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) :
QObject(parent)
{
connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected);
// connect(&m_webSocket, QOverload<const QList<QSslError>&>::of(&QWebSocket::sslErrors),
// this, &SslEchoClient::onSslErrors);
// QSslConfiguration sslConfiguration;
// QFile certFile(QStringLiteral(":/localhost.cert"));
// certFile.open(QIODevice::ReadOnly);
// QSslCertificate certificate(&certFile, QSsl::Pem);
// certFile.close();
// sslConfiguration.addCaCertificate(certificate);
// m_webSocket.setSslConfiguration(sslConfiguration);
m_webSocket.open(QUrl(url));
}
//! [constructor]
//! [onConnected]
void SslEchoClient::onConnected()
{
qDebug() << "WebSocket connected";
connect(&m_webSocket, &QWebSocket::textMessageReceived,
this, &SslEchoClient::onTextMessageReceived);
m_webSocket.sendTextMessage(QStringLiteral("Hello, world!"));
}
//! [onConnected]
//! [onTextMessageReceived]
void SslEchoClient::onTextMessageReceived(QString message)
{
qDebug() << "Message received:" << message;
qApp->quit();
}
// void SslEchoClient::onSslErrors(const QList<QSslError> &errors)
// {
// qWarning() << "SSL errors:" << errors;
// m_webSocket.ignoreSslErrors();
//qApp->quit();
// }
//! [onTextMessageReceived]
Important!: If the wss server is running on localhost with fake certs, then in Edge browser, client connecting to the server will work, but not in other browsers. But if your wss server has domain name with valid cert (e.g. type of Let's Encrypt), then it will work in major browsers (Chrome, Edge, Firefox) (I tested, it works). Also, host your client application through https connection, e.g. with qtwasmserver.