diff --git a/CHANGELOG.md b/CHANGELOG.md index aec2505..415f26c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ ## In development +### New API endpoints +- Added `executeForOthers` and `executeForOtherGMs` that execute for all users/all GMs except the local client. + ### Bugfixes -- `ExecuteAsUser` and `ExecuteForUsers` didn't execute locally if the id of the current user was passed in as recipient. +- `executeAsUser` and `executeForUsers` didn't execute locally if the id of the current user was passed in as recipient. +- `executeForEveryone` and `executeForAllGMs` now execute locally as well, as they should ## 1.0.1 diff --git a/README.md b/README.md index 7db7a2d..671882b 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,19 @@ Executes a function on the client of the specified user. This function will fail async socket.executeForAllGMs(handler, parameters...); ``` -Executes a function on the clients of all connected GMs. +Executes a function on the clients of all connected GMs. If the current user is a GM the function will be executed locally as well. + +- **handler** can either be the function that should be executed or the name given to that function during registration. +- **parameters...** the parameters that should be passed to the called function. Pass the parameters in comma separated, as you would do for a regular function call. + +**Return value**: The promise returned by this function will resolve as soon as the request for execution has been sent to the connected GM clients and *will not* wait until those clients have finished processing that function. The promise will not yield any return value. + +#### socket.executeForOtherGMs +```javascript +async socket.executeForOtherGMs(handler, parameters...); +``` + +Executes a function on the clients of all connected GMs, except for the current user. If the current user is not a GM this function has the same behavior as [`socket.executeForAllGMs`](#socketexecuteasgm). - **handler** can either be the function that should be executed or the name given to that function during registration. - **parameters...** the parameters that should be passed to the called function. Pass the parameters in comma separated, as you would do for a regular function call. @@ -129,7 +141,19 @@ Executes a function on the clients of all connected GMs. async socket.executeForEveryone(handler, ...args); ``` -Executes a function on all connected clients. +Executes a function on all connected clients, including on the local client. + +- **handler** can either be the function that should be executed or the name given to that function during registration. +- **parameters...** the parameters that should be passed to the called function. Pass the parameters in comma separated, as you would do for a regular function call. + +**Return value**: The promise returned by this function will resolve as soon as the request for execution has been sent to the connected clients and *will not* wait until those clients have finished processing that function. The promise will not yield any return value. + +#### socket.executeForOthers +```javascript +async socket.executeForOthers(handler, ...args); +``` + +Executes a function on all connected clients, but not locally. - **handler** can either be the function that should be executed or the name given to that function during registration. - **parameters...** the parameters that should be passed to the called function. Pass the parameters in comma separated, as you would do for a regular function call. diff --git a/src/socketlib.js b/src/socketlib.js index 7f2fc29..6347395 100644 --- a/src/socketlib.js +++ b/src/socketlib.js @@ -109,11 +109,26 @@ class SocketlibSocket { async executeForAllGMs(handler, ...args) { const [name, func] = this._resolveFunction(handler); this._sendCommand(name, args, RECIPIENT_TYPES.ALL_GMS); + if (game.user.isGM) + // TODO Make this function call run async, even if the function isn't delcared as async to prevent exceptions to propagate through executeForUsers + func(...args); + } + + async executeForAllOtherGMs(handler, ...args) { + const [name, func] = this._resolveFunction(handler); + this._sendCommand(name, args, RECIPIENT_TYPES.ALL_GMS); } async executeForEveryone(handler, ...args) { const [name, func] = this._resolveFunction(handler); this._sendCommand(name, args, RECIPIENT_TYPES.EVERYONE); + // TODO Make this function call run async, even if the function isn't delcared as async to prevent exceptions to propagate through executeForUsers + func(...args); + } + + async executeForOthers(handler, ...args) { + const [name, func] = this._resolveFunction(handler); + this._sendCommand(name, args, RECIPIENT_TYPES.EVERYONE); } async executeForUsers(handler, recipients, ...args) {