SignalingServer.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Qt signaling server example for libdatachannel
  3. * Copyright (c) 2022 cheungxiongwei
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  8. */
  9. #ifndef SIGNALINGSERVER_H
  10. #define SIGNALINGSERVER_H
  11. #include <QAbstractSocket>
  12. #include <QByteArray>
  13. #include <QHostAddress>
  14. #include <QObject>
  15. #include <QString>
  16. class QWebSocketServer;
  17. class QWebSocket;
  18. class SignalingServer : public QObject {
  19. Q_OBJECT
  20. public:
  21. explicit SignalingServer(QObject *parent = nullptr);
  22. bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0);
  23. private slots:
  24. void onNewConnection();
  25. void onDisconnected();
  26. void onWebSocketError(QAbstractSocket::SocketError error);
  27. void onBinaryMessageReceived(const QByteArray &message);
  28. void onTextMessageReceived(const QString &message);
  29. private:
  30. QWebSocketServer *server;
  31. QMap<QString, QWebSocket *> clients;
  32. };
  33. #endif // SIGNALINGSERVER_H