Skip to content

Commit a32f4d7

Browse files
Update readme.md and jsdoc
1 parent cfd5b45 commit a32f4d7

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

readme.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ global.server = new GameServer(3000);
3939
function GameClient(_ip, _port) : TCPSocket(_ip, _port) constructor {
4040
setEvent("connected", function() {
4141
// Send ping after connection is established
42-
rpc.sendRequest("ping", current_time, function(_previous_time) {
43-
// Show ping
44-
var _ping = current_time - _previous_time;
45-
show_debug_message($"{_ping} ms");
46-
}, function(_error) {
47-
// Show error message
48-
show_debug_message($"Error {_error.code}: {_error.message}");
49-
});
42+
rpc.sendRequest("ping", current_time)
43+
.onCallback(function(_previous_time) {
44+
// Show ping
45+
var _ping = current_time - _previous_time;
46+
show_debug_message($"{_ping} ms");
47+
})
48+
.onError(function(_error) {
49+
// Show error message
50+
show_debug_message($"Error {_error.code}: {_error.message}");
51+
});
5052
});
5153
}
5254
```

scripts/RPC/RPC.gml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function RPC(_socket) constructor {
2121
network.sendData(_data, _socket);
2222
}
2323
/// @function sendRequest()
24-
///
2524
/// @description
2625
/// Function to send requests by invoking the specified method with the given parameters
2726
/// over the provided socket. Allows handling both successful results and errors through callbacks.
@@ -41,12 +40,27 @@ function RPC(_socket) constructor {
4140
requests.setElement(_id, _request);
4241
return _request;
4342
}
43+
/// @function sendNotification()
44+
/// @description
45+
/// Sends a notification with the specified method and parameters over the given socket.
46+
///
47+
/// @param {String} method - Name of the method to be invoked.
48+
/// @param {Struct|Array} params - Parameters to be used in the notification.
49+
/// @param {Function} socket - Socket to which the notification will be sent.
4450
static sendNotification = function(_method, _params, _socket = socket) {
4551
sendJSON({
4652
"method": _method,
4753
"params": _params
4854
}, _socket);
4955
}
56+
/// @function sendError()
57+
/// @description
58+
/// Sends an error with the specified code, message, and ID over the given socket.
59+
///
60+
/// @param {Real} code - Error code.
61+
/// @param {string} message - Error message.
62+
/// @param {Real} id - ID associated with the error.
63+
/// @param {Function} socket - Socket to which the error will be sent.
5064
static sendError = function(_code, _message, _id, _socket) {
5165
sendJSON({
5266
"error": {
@@ -128,6 +142,13 @@ function RPC(_socket) constructor {
128142
requests.removeElement(_id);
129143
}
130144
}
145+
/// @function registerHandler()
146+
/// @description
147+
/// Registers a Remote Procedure Call (RPC) handler with the specified name and method.
148+
/// This function allows associating a method with a unique name for later invocation.
149+
///
150+
/// @param {String} name - The name associated with the RPC handler.
151+
/// @param {Function} method - The method to be registered as the RPC handler.
131152
static registerHandler = function(_name, _method) {
132153
handlers[$ _name] = _method;
133154
}

0 commit comments

Comments
 (0)