Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fa28a9364 | |||
| 148f442857 | |||
| 326bc0e017 |
@@ -1,3 +1,12 @@
|
|||||||
|
## 1.0.2
|
||||||
|
### 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.
|
||||||
|
- `executeForEveryone` and `executeForAllGMs` now execute locally as well, as they should
|
||||||
|
|
||||||
|
|
||||||
## 1.0.1
|
## 1.0.1
|
||||||
### New features
|
### New features
|
||||||
- Added support for game systems
|
- Added support for game systems
|
||||||
|
|||||||
28
README.md
28
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...);
|
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.
|
- **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.
|
- **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);
|
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.
|
- **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.
|
- **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.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "socketlib",
|
"name": "socketlib",
|
||||||
"title": "socketlib",
|
"title": "socketlib",
|
||||||
"description": "A library for easier handling of foundry sockets",
|
"description": "A library for easier handling of foundry sockets",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"minimumCoreVersion" : "0.7.9",
|
"minimumCoreVersion" : "0.7.9",
|
||||||
"compatibleCoreVersion" : "0.8.1",
|
"compatibleCoreVersion" : "0.8.1",
|
||||||
"library": true,
|
"library": true,
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
"src/socketlib.js"
|
"src/socketlib.js"
|
||||||
],
|
],
|
||||||
"url": "https://github.com/manuelVo/foundryvtt-socketlib",
|
"url": "https://github.com/manuelVo/foundryvtt-socketlib",
|
||||||
"download": "https://github.com/manuelVo/foundryvtt-socketlib/archive/v1.0.1.zip",
|
"download": "https://github.com/manuelVo/foundryvtt-socketlib/archive/v1.0.2.zip",
|
||||||
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-socketlib/master/module.json",
|
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-socketlib/master/module.json",
|
||||||
"readme": "https://github.com/manuelVo/foundryvtt-socketlib/blob/master/README.md",
|
"readme": "https://github.com/manuelVo/foundryvtt-socketlib/blob/master/README.md",
|
||||||
"changelog": "https://github.com/manuelVo/foundryvtt-socketlib/blob/master/CHANGELOG.md",
|
"changelog": "https://github.com/manuelVo/foundryvtt-socketlib/blob/master/CHANGELOG.md",
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ class SocketlibSocket {
|
|||||||
|
|
||||||
async executeAsUser(handler, userId, ...args) {
|
async executeAsUser(handler, userId, ...args) {
|
||||||
const [name, func] = this._resolveFunction(handler);
|
const [name, func] = this._resolveFunction(handler);
|
||||||
|
if (userId === game.userId)
|
||||||
|
return func(...args);
|
||||||
const user = game.users.get(userId);
|
const user = game.users.get(userId);
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new SocketlibInvalidUserError(`No user with id '${userId}' exists.`);
|
throw new SocketlibInvalidUserError(`No user with id '${userId}' exists.`);
|
||||||
@@ -107,18 +109,39 @@ class SocketlibSocket {
|
|||||||
async executeForAllGMs(handler, ...args) {
|
async executeForAllGMs(handler, ...args) {
|
||||||
const [name, func] = this._resolveFunction(handler);
|
const [name, func] = this._resolveFunction(handler);
|
||||||
this._sendCommand(name, args, RECIPIENT_TYPES.ALL_GMS);
|
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 executeForOtherGMs(handler, ...args) {
|
||||||
|
const [name, func] = this._resolveFunction(handler);
|
||||||
|
this._sendCommand(name, args, RECIPIENT_TYPES.ALL_GMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
async executeForEveryone(handler, ...args) {
|
async executeForEveryone(handler, ...args) {
|
||||||
const [name, func] = this._resolveFunction(handler);
|
const [name, func] = this._resolveFunction(handler);
|
||||||
this._sendCommand(name, args, RECIPIENT_TYPES.EVERYONE);
|
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) {
|
async executeForUsers(handler, recipients, ...args) {
|
||||||
if (!(recipients instanceof Array))
|
if (!(recipients instanceof Array))
|
||||||
throw new TypeError("Recipients parameter must be an array of user ids.");
|
throw new TypeError("Recipients parameter must be an array of user ids.");
|
||||||
const [name, func] = this._resolveFunction(handler);
|
const [name, func] = this._resolveFunction(handler);
|
||||||
|
const currentUserIndex = recipients.indexOf(game.userId);
|
||||||
|
if (currentUserIndex >= 0)
|
||||||
|
recipients.splice(currentUserIndex, 1);
|
||||||
this._sendCommand(name, args, recipients);
|
this._sendCommand(name, args, recipients);
|
||||||
|
if (currentUserIndex >= 0)
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendRequest(handlerName, args, recipient) {
|
_sendRequest(handlerName, args, recipient) {
|
||||||
|
|||||||
Reference in New Issue
Block a user