-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added sendRequestAsync which returns a promise when sending requests
- Loading branch information
1 parent
7f4e406
commit 6ea16eb
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const RustPlus = require('@liamcottle/rustplus.js'); | ||
var rustplus = new RustPlus('ip', 'port', 'playerId', 'playerToken'); | ||
|
||
// wait until connected before sending commands | ||
rustplus.on('connected', () => { | ||
|
||
/** | ||
* sendRequestAsync will return a promise for your request. | ||
* you can optionally pass in a second parameter for the timeout in milliseconds | ||
* - AppResponse packets will be sent to `then` on success. | ||
* - AppError packets and Timeout Errors will be sent to `catch`. | ||
*/ | ||
rustplus.sendRequestAsync({ | ||
getInfo: {}, // get server info with a timeout of 2 seconds | ||
}, 2000).then((response) => { | ||
|
||
// AppResponse | ||
console.log(response); | ||
|
||
}).catch((error) => { | ||
|
||
// AppError or Error('Timeout'); | ||
console.log(error); | ||
|
||
}).finally(() => { | ||
|
||
// disconnect so our script is finished | ||
rustplus.disconnect(); | ||
|
||
}); | ||
|
||
}); | ||
|
||
// connect to rust server | ||
rustplus.connect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters