🌐
English
Socket.IO API#
Oasis supports communication with Socket.IO servers provided by Node.JS. Socket.IO is utilized as a Signaling Server in WebRTC and other technologies.
The Socket.IO client API of Oasis currently supports Node.JS Socket.IO version 3. If Node.JS uses Socket.IO version 4 or higher, configuration on the server side is required as follows:
let socketIO = require('socket.io');
let io = socketIO(https_server, {
allowEIO3: true,
});
Header File#
OasisNet.h
SocketIoEventDelegate Interface#
class SocketIoEventDelegate : public std::enable_shared_from_this<SocketIoEventDelegate>
{
public:
SocketIoEventDelegate();
virtual ~SocketIoEventDelegate();
virtual void onConnected(const SocketIoClientRef &sio, const char *sid);
virtual void onClosed(const SocketIoClientRef &sio, bool is_lost);
virtual void onEvent(const SocketIoClientRef &sio, const std::string &event, const std::list<std::string> &values);
virtual void onMessage(const SocketIoClientRef &sio, key_value_map_t &msg, const std::string &from_sid);
};
void
onConnected
(
const SocketIoClientRef &
sio
,
const char *
sid
)
OasisNet.h
Callback function called when connected.
Parameters
sio
Socket.IO client connection object.
sid
SID string allocated from the Socket.IO server.
void
onClosed
(
const SocketIoClientRef &
sio
,
bool
is_lost
)
OasisNet.h
Callback function called when the connection is closed or a Close packet is received from the server.
Parameters
sio
Socket.IO client connection object.
is_lost
If
true, it means the connection was disconnected due to no response from the server for a certain period of time. If false, it means a Close packet was received from the server.
void
onEvent
(
const SocketIoClientRef &
sio
,
const std::string &
event
,
const std::list<std::string> &
values
)
OasisNet.h
Callback function called when an event is received from the server.
Parameters
sio
Socket.IO client connection object.
event
Event name.
values
List of event values.
void
onMessage
(
const SocketIoClientRef &
sio
,
key_value_map_t &
msg
,
const std::string &
from_sid
)
OasisNet.h
Callback function called when a message is received.
Parameters
sio
Socket.IO client connection object.
msg
Message in the form of a key-value map.
from_sid
SID of the client that sent the message.
Functions#
SocketIoClientRef
sioConnect
(
const char *
url
,
int32_t
timeout
,
const std::shared_ptr<SocketIoEventDelegate> &
delegate
,
key_value_map_t &
parameters
)
OasisNet.h
Connects to the Socket.IO server.
Parameters
url
Server URL. Same format as a websocket server address.
timeout
Maximum time to wait until connected. Measured in milliseconds.
delegate
User-defined object derived from SocketIoEventDelegate for Socket.IO event processing.
parameters
Key-value map required for connection.
Return Value
Returns the Socket.IO client connection object on success. Returns nullptr on failure.
The key-value map required for sioConnect is as follows:
Key
Default
M
Description
tls-disable-certificate-validation
0
Does not validate the certificate of the server.
tls-use-sni
0
Includes the FQDN of the server in the Hello Handshake when connecting to the server.
int32_t
sioReconnect
(
SocketIoClientRef &
sio
)
OasisNet.h
Connects to the Socket.IO server. Used when networking becomes available again.
Parameters
sio
Socket.IO client connection object.
Return Value
- 0: Success
- -1: Failure
int32_t
sioClose
(
SocketIoClientRef &
sio
,
int32_t
timeout
)
OasisNet.h
Closes the connection.
Parameters
sio
Socket.IO client connection object.
timeout
Maximum time to wait until the connection closing is completed. Measured in milliseconds.
Return Value
- 0: Success
- -1: Failure
ssize_t
sioEmit
(
const SocketIoClientRef &
sio
,
const char *
event_name
,
const char *
event_value
)
OasisNet.h
Transmits an event with a single value.
Parameters
sio
Socket.IO client connection object.
event_name
Event name.
event_value
Event value. If nullptr, transmits the event name only.
Return Value
Returns the length of the event message on success. Returns -1 on failure.
ssize_t
sioEmit2
(
const SocketIoClientRef &
sio
,
const char *
event_name
,
const char *
event_value1
,
const char *
event_value2
)
OasisNet.h
Transmits an event with two values.
Parameters
sio
Socket.IO client connection object.
event_name
Event name.
event_value1
First event value.
event_value2
Second event value.
Return Value
Returns the length of the event message on success. Returns -1 on failure.
ssize_t
sioSend
(
const SocketIoClientRef &
sio
,
key_value_map_t &
msg
)
OasisNet.h
Transmits a message.
Parameters
sio
Socket.IO client connection object.
msg
Key-value map composing the message.
Return Value
Returns the transmitted message size on success. Returns -1 on failure.
ssize_t
sioSend
(
const SocketIoClientRef &
sio
,
const char *
room_id
,
key_value_map_t &
msg
)
OasisNet.h
Transmits a message containing a room id.
Parameters
sio
Socket.IO client connection object.
room_id
Room id string.
msg
Key-value map composing the message.
Return Value
Returns the transmitted message size on success. Returns -1 on failure.
const char *
sioSid
(
const SocketIoClientRef &
sio
)
OasisNet.h
Obtains the SID of the Socket.IO client connection object.
Parameters
sio
Socket.IO client connection object.
Return Value
Returns the SID string on success. Returns nullptr on failure.