Skip to content

Commit

Permalink
feat: allow resource path to be set in connection URI (#134)
Browse files Browse the repository at this point in the history
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");
```
  • Loading branch information
joelnordell authored Feb 14, 2021
1 parent e7de4eb commit 36a8cd4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/internal/sio_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ namespace sio
} else {
ss<<uo.get_host();
}
ss<<":"<<uo.get_port()<<"/socket.io/?EIO=4&transport=websocket";

// If a resource path was included in the URI, use that, otherwise
// use the default /socket.io/.
const std::string path(uo.get_resource() == "/" ? "/socket.io/" : uo.get_resource());

ss<<":"<<uo.get_port()<<path<<"?EIO=4&transport=websocket";
if(m_sid.size()>0){
ss<<"&sid="<<m_sid;
}
Expand Down

0 comments on commit 36a8cd4

Please sign in to comment.