Skip to content

Commit

Permalink
Sio to websocket (#135)
Browse files Browse the repository at this point in the history
* Extract signaling client from webrtc clients.

* Extract signaling client from webrtc clients.

* Fix SignalingClient.js

* Use WebSocket instead of sio, C++ not done.

* Replace sio::message by nlohmann::json (Not working yet).

* Migrate from sio to ws.

* Fix python tests.

* Fix python tests.
  • Loading branch information
mamaheux authored Jan 8, 2024
1 parent 816c00e commit 8b5cefe
Show file tree
Hide file tree
Showing 86 changed files with 2,383 additions and 1,737 deletions.
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "opentera-webrtc-native-client/3rdParty/googletest"]
path = opentera-webrtc-native-client/3rdParty/googletest
url = https://github.com/google/googletest.git
[submodule "opentera-webrtc-native-client/3rdParty/socket.io-client-cpp"]
path = opentera-webrtc-native-client/3rdParty/socket.io-client-cpp
url = https://github.com/introlab/socket.io-client-cpp.git
[submodule "opentera-webrtc-native-client/3rdParty/cpp-subprocess"]
path = opentera-webrtc-native-client/3rdParty/cpp-subprocess
url = https://github.com/arun11299/cpp-subprocess.git
Expand All @@ -16,3 +13,9 @@
[submodule "opentera-webrtc-native-client/3rdParty/opencv"]
path = opentera-webrtc-native-client/3rdParty/opencv
url = https://github.com/opencv/opencv.git
[submodule "opentera-webrtc-native-client/3rdParty/json"]
path = opentera-webrtc-native-client/3rdParty/json
url = https://github.com/nlohmann/json
[submodule "opentera-webrtc-native-client/3rdParty/IXWebSocket"]
path = opentera-webrtc-native-client/3rdParty/IXWebSocket
url = https://github.com/machinezone/IXWebSocket.git
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.7
1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ set(LIBRARY_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})

include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(BEFORE SYSTEM ${webrtc_native_INCLUDE})
include_directories(../../opentera-webrtc-native-client/3rdParty/socket.io-client-cpp/src)
include_directories(../../opentera-webrtc-native-client/3rdParty/socket.io-client-cpp/lib/rapidjson/include)
include_directories(../../opentera-webrtc-native-client/3rdParty/json/include)
include_directories(../../opentera-webrtc-native-client/3rdParty/IXWebSocket)
include_directories(../../opentera-webrtc-native-client/3rdParty/cpp-httplib)
include_directories(../../opentera-webrtc-native-client/OpenteraWebrtcNativeClient/include)

Expand Down
16 changes: 15 additions & 1 deletion examples/cpp-data-channel-client-reliability-tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool waitFor(F f)
{
this_thread::sleep_for(SLEEP_TIME);

if (std::chrono::duration_cast<std::chrono::milliseconds>(chrono::steady_clock::now() - start) > TIMEOUT)
if (chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start) > TIMEOUT)
{
return false;
}
Expand Down Expand Up @@ -80,6 +80,20 @@ int main(int argc, char* argv[])
}
cout << endl;

string wsUrl;
if (baseUrl.find("http://") == 0)
{
wsUrl = "ws://" + baseUrl.substr(7) + "/signaling";
}
else if (baseUrl.find("https://") == 0)
{
wsUrl = "wss://" + baseUrl.substr(8) + "/signaling";
}
else
{
cout << "Invalid base URL (" << baseUrl << ")" << endl;
return -1;
}
auto signalingServerConfiguration =
SignalingServerConfiguration::create(baseUrl, name, "reliability", password);
auto webrtcConfiguration = WebrtcConfiguration::create(iceServers);
Expand Down
4 changes: 2 additions & 2 deletions examples/cpp-data-channel-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ set(LIBRARY_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})

include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(BEFORE SYSTEM ${webrtc_native_INCLUDE})
include_directories(../../opentera-webrtc-native-client/3rdParty/socket.io-client-cpp/src)
include_directories(../../opentera-webrtc-native-client/3rdParty/socket.io-client-cpp/lib/rapidjson/include)
include_directories(../../opentera-webrtc-native-client/3rdParty/json/include)
include_directories(../../opentera-webrtc-native-client/3rdParty/IXWebSocket)
include_directories(../../opentera-webrtc-native-client/3rdParty/cpp-httplib)
include_directories(../../opentera-webrtc-native-client/OpenteraWebrtcNativeClient/include)

Expand Down
2 changes: 1 addition & 1 deletion examples/cpp-data-channel-client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int main(int argc, char* argv[])
}

auto signalingServerConfiguration =
SignalingServerConfiguration::create("http://localhost:8080", "C++", "chat", "abc");
SignalingServerConfiguration::create("ws://localhost:8080/signaling", "C++", "chat", "abc");
auto webrtcConfiguration = WebrtcConfiguration::create(iceServers);
auto dataChannelConfiguration = DataChannelConfiguration::create();
DataChannelClient client(signalingServerConfiguration, webrtcConfiguration, dataChannelConfiguration);
Expand Down
4 changes: 2 additions & 2 deletions examples/cpp-stream-client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ set(LIBRARY_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})

include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(BEFORE SYSTEM ${webrtc_native_INCLUDE})
include_directories(../../opentera-webrtc-native-client/3rdParty/socket.io-client-cpp/src)
include_directories(../../opentera-webrtc-native-client/3rdParty/socket.io-client-cpp/lib/rapidjson/include)
include_directories(../../opentera-webrtc-native-client/3rdParty/json/include)
include_directories(../../opentera-webrtc-native-client/3rdParty/IXWebSocket)
include_directories(../../opentera-webrtc-native-client/3rdParty/cpp-httplib)
include_directories(../../opentera-webrtc-native-client/OpenteraWebrtcNativeClient/include)

Expand Down
2 changes: 1 addition & 1 deletion examples/cpp-stream-client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int main(int argc, char* argv[])
}

auto signalingServerConfiguration =
SignalingServerConfiguration::create("http://localhost:8080", "C++", "chat", "abc");
SignalingServerConfiguration::create("ws://localhost:8080/signaling", "C++", "chat", "abc");
auto webrtcConfiguration = WebrtcConfiguration::create(iceServers);
auto videoStreamConfiguration = VideoStreamConfiguration::create();
auto videoSource = make_shared<CvVideoCaptureVideoSource>(argv[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def on_data_channel_message_string(client, message):


if __name__ == '__main__':
signaling_server_configuration = webrtc.SignalingServerConfiguration.create(
'http://localhost:8080', 'Python', None, 'chat', 'abc')
signaling_server_configuration = webrtc.SignalingServerConfiguration.create_with_data(
'ws://localhost:8080/signaling', 'Python', None, 'chat', 'abc')
ice_servers = webrtc.IceServer.fetch_from_server(
'http://localhost:8080/iceservers', 'abc')
webrtc_configuration = webrtc.WebrtcConfiguration.create(ice_servers)
Expand Down
4 changes: 2 additions & 2 deletions examples/python-stream-client/python_stream_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def on_error(error):
frame = cv2.imread(os.path.join(os.path.dirname(
os.path.realpath(__file__)), 'frame.png'))

signaling_server_configuration = webrtc.SignalingServerConfiguration.create(
'http://localhost:8080', 'Python', None, 'chat', 'abc')
signaling_server_configuration = webrtc.SignalingServerConfiguration.create_with_data(
'ws://localhost:8080/signaling', 'Python', None, 'chat', 'abc')
ice_servers = webrtc.IceServer.fetch_from_server(
'http://localhost:8080/iceservers', 'abc')
webrtc_configuration = webrtc.WebrtcConfiguration.create(ice_servers)
Expand Down
4 changes: 2 additions & 2 deletions examples/web-data-channel-client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sendButton.disabled = true;
chatTextArea.value = '';

let dataChannelClient = null;
let dataChannelClient = null;

function connectDataChannelClientEvents() {
dataChannelClient.onSignalingConnectionOpen = () => {
Expand Down Expand Up @@ -84,7 +84,7 @@

connectButton.onclick = async () => {
const SignalingServerConfiguration = {
url: 'http://localhost:8080',
url: 'ws://localhost:8080/signaling',
name: nameInput.value,
data: {}, // Client custom data
room: 'chat',
Expand Down
2 changes: 1 addition & 1 deletion examples/web-stream-client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
};
connectButton.onclick = async () => {
const SignalingServerConfiguration = {
url: 'http://localhost:8080',
url: 'ws://localhost:8080/signaling',
name: nameInput.value,
data: {}, // Client custom data
room: 'chat',
Expand Down
2 changes: 1 addition & 1 deletion examples/web-stream-data-channel-client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
};
connectButton.onclick = async () => {
const SignalingServerConfiguration = {
url: 'http://localhost:8080',
url: 'ws://localhost:8080/signaling',
name: nameInput.value,
data: {}, // Client custom data
room: 'chat',
Expand Down
16 changes: 10 additions & 6 deletions opentera-webrtc-native-client/3rdParty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ set (BUILD_SHARED_LIBS OFF)
add_subdirectory(webrtc_native)

add_subdirectory(pybind11)
add_subdirectory(socket.io-client-cpp)
add_subdirectory(json)

if(WIN32)
target_compile_definitions(sioclient PRIVATE WIN32_LEAN_AND_MEAN)
endif()
set(USE_ZLIB OFF)
set(USE_TLS ON)
set(OPENSSL_FOUND TRUE)
set(OPENSSL_DEFINITIONS "")
set(OPENSSL_INCLUDE_DIR ${boringssl_INCLUDE})
set(OPENSSL_LIBRARIES ${boringssl_LIBRARY})
add_subdirectory(IXWebSocket)
set_property(TARGET ixwebsocket PROPERTY CXX_STANDARD 17)

if (OPENTERA_WEBRTC_ENABLE_TESTS)
add_subdirectory(googletest)
Expand Down Expand Up @@ -54,5 +59,4 @@ if(NOT OPENTERA_WEBRTC_USE_SYSTEM_OPENCV)

endif()

install(DIRECTORY socket.io-client-cpp/lib/rapidjson/include/rapidjson DESTINATION include
FILES_MATCHING PATTERN "*.h")
install(DIRECTORY json/include DESTINATION include FILES_MATCHING PATTERN "*.hpp")
1 change: 1 addition & 0 deletions opentera-webrtc-native-client/3rdParty/IXWebSocket
Submodule IXWebSocket added at 688af9
2 changes: 1 addition & 1 deletion opentera-webrtc-native-client/3rdParty/googletest
Submodule googletest updated 144 files
1 change: 1 addition & 0 deletions opentera-webrtc-native-client/3rdParty/json
Submodule json added at 9cca28
2 changes: 1 addition & 1 deletion opentera-webrtc-native-client/3rdParty/pybind11
Submodule pybind11 updated 112 files
Submodule socket.io-client-cpp deleted from 46d3a8
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(BEFORE SYSTEM ${webrtc_native_INCLUDE})
include_directories(BEFORE SYSTEM ${boringssl_INCLUDE})
include_directories(BEFORE SYSTEM ${libyuv_INCLUDE})
include_directories(../3rdParty/socket.io-client-cpp/src)
include_directories(../3rdParty/socket.io-client-cpp/lib/rapidjson/include)
include_directories(../3rdParty/json/include)
include_directories(../3rdParty/IXWebSocket)
include_directories(../3rdParty/cpp-httplib)
include_directories(include)

Expand All @@ -50,7 +50,7 @@ add_library(OpenteraWebrtcNativeClient
${source_files})

target_link_libraries(OpenteraWebrtcNativeClient
sioclient
ixwebsocket
${webrtc_native_LIBRARY}
${boringssl_LIBRARY}
${libyuv_LIBRARY}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef OPENTERA_WEBRTC_NATIVE_CLIENT_CONFIGURATIONS_SIGNALING_SERVER_CONFIGURATION_H
#define OPENTERA_WEBRTC_NATIVE_CLIENT_CONFIGURATIONS_SIGNALING_SERVER_CONFIGURATION_H

#include <sio_message.h>
#include <nlohmann/json.hpp>

#include <string>

Expand All @@ -14,14 +14,14 @@ namespace opentera
{
std::string m_url;
std::string m_clientName;
sio::message::ptr m_clientData;
nlohmann::json m_clientData;
std::string m_room;
std::string m_password;

SignalingServerConfiguration(
std::string&& url,
std::string&& clientName,
sio::message::ptr&& clientData,
nlohmann::json&& clientData,
std::string&& room,
std::string&& password);

Expand All @@ -32,19 +32,19 @@ namespace opentera

static SignalingServerConfiguration create(std::string url, std::string clientName, std::string room);
static SignalingServerConfiguration
create(std::string url, std::string clientName, sio::message::ptr clientData, std::string room);
createWithData(std::string url, std::string clientName, nlohmann::json clientData, std::string room);
static SignalingServerConfiguration
create(std::string url, std::string clientName, std::string room, std::string password);
static SignalingServerConfiguration create(
static SignalingServerConfiguration createWithData(
std::string url,
std::string clientName,
sio::message::ptr clientData,
nlohmann::json clientData,
std::string room,
std::string password);

[[nodiscard]] const std::string& url() const;
[[nodiscard]] const std::string& clientName() const;
[[nodiscard]] sio::message::ptr clientData() const;
[[nodiscard]] const nlohmann::json& clientData() const;
[[nodiscard]] const std::string& room() const;
[[nodiscard]] const std::string& password() const;

Expand All @@ -63,7 +63,7 @@ namespace opentera
inline SignalingServerConfiguration
SignalingServerConfiguration::create(std::string url, std::string clientName, std::string room)
{
return {std::move(url), std::move(clientName), sio::null_message::create(), std::move(room), ""};
return {std::move(url), std::move(clientName), nlohmann::json{}, std::move(room), ""};
}

/**
Expand All @@ -75,10 +75,10 @@ namespace opentera
* @param room The room name
* @return A signaling server configuration with the specified values
*/
inline SignalingServerConfiguration SignalingServerConfiguration::create(
inline SignalingServerConfiguration SignalingServerConfiguration::createWithData(
std::string url,
std::string clientName,
sio::message::ptr clientData,
nlohmann::json clientData,
std::string room)
{
return {std::move(url), std::move(clientName), std::move(clientData), std::move(room), ""};
Expand All @@ -102,7 +102,7 @@ namespace opentera
return {
std::move(url),
std::move(clientName),
sio::null_message::create(),
nlohmann::json{},
std::move(room),
std::move(password)};
}
Expand All @@ -117,10 +117,10 @@ namespace opentera
* @param password The signaling server password
* @return A signaling server configuration with the specified values
*/
inline SignalingServerConfiguration SignalingServerConfiguration::create(
inline SignalingServerConfiguration SignalingServerConfiguration::createWithData(
std::string url,
std::string clientName,
sio::message::ptr clientData,
nlohmann::json clientData,
std::string room,
std::string password)
{
Expand All @@ -143,7 +143,7 @@ namespace opentera
* @brief Returns the client data.
* @return The client data
*/
inline sio::message::ptr SignalingServerConfiguration::clientData() const { return m_clientData; }
inline const nlohmann::json& SignalingServerConfiguration::clientData() const { return m_clientData; }

/**
* @brief Returns the room name.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef OPENTERA_WEBRTC_NATIVE_CLIENT_DATA_CHANNEL_CLIENT_H
#define OPENTERA_WEBRTC_NATIVE_CLIENT_DATA_CHANNEL_CLIENT_H

#include <OpenteraWebrtcNativeClient/SignalingClient.h>
#include <OpenteraWebrtcNativeClient/WebrtcClient.h>
#include <OpenteraWebrtcNativeClient/Utils/ClassMacro.h>
#include <OpenteraWebrtcNativeClient/Configurations/DataChannelConfiguration.h>

Expand All @@ -12,7 +12,7 @@ namespace opentera
/**
* @brief Represents a client for data channel communication.
*/
class DataChannelClient : public SignalingClient
class DataChannelClient : public WebrtcClient
{
DataChannelConfiguration m_dataChannelConfiguration;

Expand Down Expand Up @@ -91,7 +91,10 @@ namespace opentera
*
* @param message The string message
*/
inline bool DataChannelClient::sendToAll(const std::string& message) { return sendToAll(webrtc::DataBuffer(message)); }
inline bool DataChannelClient::sendToAll(const std::string& message)
{
return sendToAll(webrtc::DataBuffer(message));
}

/**
* @brief Sets the callback that is called when a data channel opens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace opentera
{
class DataChannelPeerConnectionHandler : public PeerConnectionHandler, public webrtc::DataChannelObserver
{
std::string m_room;
DataChannelConfiguration m_dataChannelConfiguration;

std::function<void(const Client&)> m_onDataChannelOpen;
Expand All @@ -30,11 +29,10 @@ namespace opentera
std::string id,
Client peerClient,
bool isCaller,
std::function<void(const std::string&, const sio::message::ptr&)> sendEvent,
SignalingClient& m_signalingClient,
std::function<void(const std::string&)> onError,
std::function<void(const Client&)> onClientConnected,
std::function<void(const Client&)> onClientDisconnected,
std::string room,
DataChannelConfiguration dataChannelConfiguration,
std::function<void(const Client&)> onDataChannelOpen,
std::function<void(const Client&)> onDataChannelClosed,
Expand Down
Loading

0 comments on commit 8b5cefe

Please sign in to comment.