/****************************************************************************
**
** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebChannel module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "websockettransport.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QDebug>
#include <QtWebSockets/QWebSocket>
/*!
\brief QWebChannelAbstractSocket implementation that uses a QWebSocket internally.
The transport delegates all messages received over the QWebSocket over its
textMessageReceived signal. Analogously, all calls to sendTextMessage will
be send over the QWebSocket to the remote client.
*/
QT_BEGIN_NAMESPACE
/*!
Construct the transport object and wrap the given socket.
The socket is also set as the parent of the transport object.
*/
WebSocketTransport::WebSocketTransport(QWebSocket *socket)
: QWebChannelAbstractTransport(socket)
, m_socket(socket)
{
connect(socket, &QWebSocket::textMessageReceived,
this, &WebSocketTransport::textMessageReceived);
connect(socket, &QWebSocket::disconnected,
this, &WebSocketTransport::deleteLater);
}
/*!
Destroys the WebSocketTransport.
*/
WebSocketTransport::~WebSocketTransport()
{
m_socket->deleteLater();
}
/*!
Serialize the JSON message and send it as a text message via the WebSocket to the client.
*/
void WebSocketTransport::sendMessage(const QJsonObject &message)
{
QJsonDocument doc(message);
m_socket->sendTextMessage(QString::fromUtf8(doc.toJson(QJsonDocument::Compact)));
}
/*!
Deserialize the stringified JSON messageData and emit messageReceived.
*/
void WebSocketTransport::textMessageReceived(const QString &messageData)
{
QJsonParseError error;
QJsonDocument message = QJsonDocument::fromJson(messageData.toUtf8(), &error);
if (error.error) {
qWarning() << "Failed to parse text message as JSON object:" << messageData
<< "Error is:" << error.errorString();
return;
} else if (!message.isObject()) {
qWarning() << "Received JSON message that is not an object: " << messageData;
return;
}
emit messageReceived(message.object(), this);
}
QT_END_NAMESPACE
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
qt嵌入cef示例和交互 (441个子文件)
QBrowser.aps 1KB
v8_context_snapshot.bin 693KB
snapshot_blob.bin 288KB
natives_blob.bin 81KB
simple_handler.cc 4KB
simple_app.cc 3KB
simple_handler_win.cc 561B
websockettransport.cpp 4KB
QBrowser.cpp 4KB
websocketclientwrapper.cpp 4KB
main.cpp 2KB
V8JsHandler.cpp 2KB
MyV8Accessor.cpp 1KB
QWebChannelClass.cpp 313B
stdafx.cpp 21B
icudtl.dat 9.93MB
data_0 8KB
data_1 264KB
data_2 8KB
data_3 8KB
Browse.VC.db 80.86MB
libcef.dll 107.48MB
opengl32sw.dll 19.95MB
Qt5Gui.dll 6.8MB
Qt5Core.dll 5.91MB
Qt5Widgets.dll 5.34MB
d3dcompiler_47.dll 4.14MB
libGLESv2.dll 3.59MB
Qt5Qml.dll 3.51MB
libGLESv2.dll 3.41MB
qwindows.dll 1.4MB
Qt5Network.dll 1.32MB
chrome_elf.dll 849KB
qwebp.dll 526KB
qjpeg.dll 411KB
libEGL.dll 394KB
qtiff.dll 377KB
Qt5Svg.dll 330KB
Qt5WebSockets.dll 158KB
qwindowsvistastyle.dll 137KB
Qt5WebChannel.dll 130KB
qgenericbearer.dll 51KB
qicns.dll 45KB
qsvgicon.dll 41KB
qico.dll 37KB
qgif.dll 37KB
qsvg.dll 30KB
qtga.dll 30KB
qwbmp.dll 29KB
libEGL.dll 23KB
QBrowser.exe 1.1MB
QBrowser.vcxproj.filters 4KB
cef_pack_strings.h 262KB
cef_bind_internal.h 118KB
cef_types.h 84KB
cef_pack_resources.h 73KB
cef_tuple.h 57KB
cef_v8_capi.h 37KB
cef_browser_capi.h 36KB
cef_net_error_list.h 35KB
cef_v8.h 33KB
cef_browser.h 33KB
cef_callback.h 33KB
cef_types_wrappers.h 30KB
cef_logging.h 29KB
cef_bind.h 29KB
cef_values_capi.h 27KB
cef_scoped_ptr.h 24KB
cef_values.h 23KB
cef_translator_test_capi.h 23KB
cef_string_wrappers.h 23KB
cef_trace_event.h 22KB
cef_translator_test.h 20KB
cef_bind_helpers.h 19KB
cef_menu_model_capi.h 19KB
cef_message_router.h 18KB
cef_request_context_capi.h 16KB
cef_menu_model.h 16KB
cef_server_capi.h 15KB
cef_request_context.h 15KB
cef_view_capi.h 14KB
cef_resource_manager.h 14KB
cef_callback_list.h 14KB
cef_server.h 14KB
cef_weak_ptr.h 13KB
cef_view.h 12KB
cef_bind_internal_win.h 12KB
cef_request_handler_capi.h 12KB
cef_resource_request_handler.h 12KB
cef_media_router_capi.h 12KB
cef_resource_request_handler_capi.h 12KB
cef_request_capi.h 12KB
cef_request_handler.h 12KB
cef_context_menu_handler_capi.h 11KB
cef_move.h 11KB
cef_life_span_handler_capi.h 11KB
cef_life_span_handler.h 11KB
cef_render_handler_capi.h 11KB
cef_window_capi.h 11KB
cef_dom_capi.h 11KB
共 441 条
- 1
- 2
- 3
- 4
- 5
Mr-Dong
- 粉丝: 4
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1