示例#1
0
U2WebChannel::U2WebChannel(QWebEnginePage *page)
    : QObject(page),
      channel(new QWebChannel(this)),
      port(INVALID_PORT)
{
#if (QT_VERSION < 0x050500)
    QWebSocketServer *server = new QWebSocketServer(QStringLiteral("UGENE Standalone Server"), QWebSocketServer::NonSecureMode, this);
    port = 12346;
    while (!server->listen(QHostAddress::LocalHost, port)) { //TODO: need more useful solution
        port++;
    }

    WebSocketClientWrapper *clientWrapper = new WebSocketClientWrapper(server, this);
    connect(clientWrapper, &WebSocketClientWrapper::clientConnected, channel, &QWebChannel::connectTo);
#else
    page->setWebChannel(channel);
#endif
}
示例#2
0
void TitleBar::initWebChannel()
{
    QWebSocketServer *server = new QWebSocketServer(QStringLiteral("Wiz Socket Server"), QWebSocketServer::NonSecureMode, this);
    if (!server->listen(QHostAddress::LocalHost, 0)) {
        qFatal("Failed to open web socket server.");
        return;
    }

    // wrap WebSocket clients in QWebChannelAbstractTransport objects
    WebSocketClientWrapper *clientWrapper  = new WebSocketClientWrapper(server, this);

    // setup the dialog and publish it to the QWebChannel
    QWebChannel *webChannel = new QWebChannel(this);
    // setup the channel
    QObject::connect(clientWrapper, &WebSocketClientWrapper::clientConnected,
                     webChannel, &QWebChannel::connectTo);
    CWizCommentsExternal* exteranl = new CWizCommentsExternal(this);
    webChannel->registerObject(QStringLiteral("externalObject"), exteranl);

    m_strWebchannelUrl = server->serverUrl().toString();
}