Skip to content

Commit 4ca0a6c

Browse files
committed
update readme for variable argument support.
1 parent 079950e commit 4ca0a6c

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

README.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,31 @@ Sockets are all managed by `client`, no public constructors.
114114
You can get it's pointer by `client.socket(namespace)`.
115115
116116
#### Event Emitter
117-
`void emit(std::string const& name, std::string const& message)`
117+
`void emit(std::string const& name, message::list const& msglist = nullptr, std::function<void (message::ptr const&)> const& ack = nullptr)`
118+
Universal event emition interface, backward compatible with all previous `emit` interfaces, can be used with multiple styles:
118119
119-
`void emit(std::string const& name, std::string const& message, std::function<void (message::ptr const&)> const& ack)`
120-
121-
Emit a plain text message, along with event's name and a optional ack callback function if you need server ack.
122-
123-
`void emit(std::string const& name, message::ptr const& args)`
124-
125-
`void emit(std::string const& name, message::ptr const& args, std::function<void (message::ptr const&)> const& ack)`
126-
127-
Emit a `message` (explained below) object, along with event's name and a optional ack callback function if you need server ack.
128-
129-
`void emit(std::string const& name, std::shared_ptr<const std::string> const& binary_ptr)`
130-
131-
`void emit(std::string const& name, std::shared_ptr<const std::string> const& binary_ptr, std::function<void (message::ptr const&)> const& ack)`
132-
133-
Emit a single binary buffer, along with event's name and a optional ack callback function if you need server ack.
120+
```C++
121+
//emit event name only:
122+
socket->emit("login");
123+
//emit with plain text:
124+
socket->emit("new message",text);
125+
//emit with single binary
126+
std::shared_ptr<std::string> voice_buf = std::make_shared<std::string>();
127+
...
128+
socket->emit("new voice",voice_buf);
129+
//emit with message object and requires an ack.
130+
message::ptr array = array_message::create();
131+
array->get_vector().push_back(string_message::create("item1"));
132+
array->get_vector().push_back(string_message::create("item2"));
133+
socket->emit("new arr",array,[](message::ptr const& ack_message){
134+
//handle ack
135+
});
136+
//emit with `message::list`
137+
message::list li("arg1");
138+
li.push(string_message::create("arg2"));
139+
socket->emit("new va",li);// support io.on("new va",function(arg1,arg2){}); style in server side.
140+
```
141+
* Items in `message::list` will be expanded in server side event callback function as function arguments.
134142

135143
#### Event Bindings
136144
`void on(std::string const& event_name,event_listener const& func)`

src/sio_message.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ namespace sio
232232
class message::list
233233
{
234234
public:
235+
list()
236+
{
237+
}
238+
235239
list(nullptr_t)
236240
{
237241
}

0 commit comments

Comments
 (0)