Skip to content

Commit 36a8cd4

Browse files
authored
feat: allow resource path to be set in connection URI (#134)
Please note that this implementation differs from the JS one, where the resource path is the namespace you want to reach: ```js const socket = io("https://example.com/my-namespace", { path: "/my-custom-path/" }); ``` Here, we will have: ```C++ sio::client h; h.connect("https://example.com/my-custom-path/"); h.socket("/my-namespace")->emit("hello"); ```
1 parent e7de4eb commit 36a8cd4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/internal/sio_client_impl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ namespace sio
238238
} else {
239239
ss<<uo.get_host();
240240
}
241-
ss<<":"<<uo.get_port()<<"/socket.io/?EIO=4&transport=websocket";
241+
242+
// If a resource path was included in the URI, use that, otherwise
243+
// use the default /socket.io/.
244+
const std::string path(uo.get_resource() == "/" ? "/socket.io/" : uo.get_resource());
245+
246+
ss<<":"<<uo.get_port()<<path<<"?EIO=4&transport=websocket";
242247
if(m_sid.size()>0){
243248
ss<<"&sid="<<m_sid;
244249
}

0 commit comments

Comments
 (0)