mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-23 10:51:58 -05:00
Add listening property
This commit is contained in:
parent
5da5804f84
commit
7dfb748500
2 changed files with 20 additions and 1 deletions
11
distribution/openrct2.d.ts
vendored
11
distribution/openrct2.d.ts
vendored
|
@ -1686,10 +1686,14 @@ declare global {
|
|||
* Based on node.js net.Server, see https://nodejs.org/api/net.html for more information.
|
||||
*/
|
||||
interface SocketServer {
|
||||
readonly listening: boolean;
|
||||
|
||||
listen(port: number): SocketServer;
|
||||
close(): SocketServer;
|
||||
|
||||
on(event: 'connection', callback: (socket: Socket) => void): SocketServer;
|
||||
|
||||
off(event: 'connection', callback: (socket: Socket) => void): SocketServer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1703,7 +1707,12 @@ declare global {
|
|||
end(data?: string): Socket;
|
||||
write(data: string): boolean;
|
||||
|
||||
on(event: 'data', callback: (data: string) => void): Socket;
|
||||
on(event: 'close', callback: (hadError: boolean) => void): Socket;
|
||||
on(event: 'error', callback: (hadError: boolean) => void): Socket;
|
||||
on(event: 'data', callback: (data: string) => void): Socket;
|
||||
|
||||
off(event: 'close', callback: (hadError: boolean) => void): Socket;
|
||||
off(event: 'error', callback: (hadError: boolean) => void): Socket;
|
||||
off(event: 'data', callback: (data: string) => void): Socket;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -358,6 +358,15 @@ namespace OpenRCT2::Scripting
|
|||
std::vector<std::shared_ptr<ScSocket>> _scClientSockets;
|
||||
bool _disposed{};
|
||||
|
||||
bool listening_get()
|
||||
{
|
||||
if (_socket != nullptr)
|
||||
{
|
||||
return _socket->GetStatus() == SOCKET_STATUS_LISTENING;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ScSocketServer* close()
|
||||
{
|
||||
Dispose();
|
||||
|
@ -482,6 +491,7 @@ namespace OpenRCT2::Scripting
|
|||
|
||||
static void Register(duk_context* ctx)
|
||||
{
|
||||
dukglue_register_property(ctx, &ScSocketServer::listening_get, nullptr, "listening");
|
||||
dukglue_register_method(ctx, &ScSocketServer::close, "close");
|
||||
dukglue_register_method(ctx, &ScSocketServer::listen, "listen");
|
||||
dukglue_register_method(ctx, &ScSocketServer::on, "on");
|
||||
|
|
Loading…
Add table
Reference in a new issue