mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51899 changelog: [internal] Reviewed By: andrewdacenko Differential Revision: D76240550 fbshipit-source-id: 5817b80d8683d951ac686390ad74b0927a2d6d2a
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
namespace facebook::react {
|
|
|
|
class IWebSocketClient {
|
|
public:
|
|
using OnConnectCallback = std::function<void(bool, const std::string&)>;
|
|
using OnClosedCallback = std::function<void(const std::string&)>;
|
|
using OnMessageCallback = std::function<void(const std::string&)>;
|
|
|
|
virtual ~IWebSocketClient() = default;
|
|
|
|
virtual void setOnClosedCallback(OnClosedCallback&& callback) noexcept = 0;
|
|
|
|
virtual void setOnMessageCallback(OnMessageCallback&& callback) noexcept = 0;
|
|
|
|
virtual void connect(
|
|
const std::string& url,
|
|
OnConnectCallback&& = nullptr) = 0;
|
|
|
|
virtual void close(const std::string& reason) = 0;
|
|
|
|
virtual void send(const std::string& message) = 0;
|
|
|
|
virtual void ping() = 0;
|
|
};
|
|
|
|
extern const char WebSocketClientFactoryKey[];
|
|
|
|
using WebSocketClientFactory =
|
|
std::function<std::unique_ptr<IWebSocketClient>()>;
|
|
|
|
WebSocketClientFactory getWebSocketClientFactory();
|
|
|
|
} // namespace facebook::react
|