Constructor
new NewgroundsPlugin(app_id, cipheropt)
Create the global newgrounds object
- Logs a view right away, for a guest and a logged in player alike, so a game does not have to
- Create the medals first: they take their name and icon from the server once it answers, and when logged in they are locked here until it does
- Call medalsInit too, before or after: an unlock asserts without it, and it keeps the medals while not logged in
| Name | Type | Attributes | Description |
|---|---|---|---|
app_id | string | The Newgrounds App ID | |
cipher | string | <optional> | The encryption key from the app's settings, AES-128 as Base64; medal unlocks and posted scores are encrypted with the browser's WebCrypto, which needs a secure page, https or localhost |
- Source
// create the newgrounds object, replace the app id with your own
const app_id = 'your_app_id_here';
new NewgroundsPlugin(app_id);Members
app_id
Properties| Type | Description |
|---|---|
| string | The Newgrounds App ID |
- Source
cipher :string|undefined
- string |
undefined
| Type | Description |
|---|---|
| string | | AES-128/Base64 encryption key, if any |
- Source
cryptoKey :CryptoKey|undefined
- CryptoKey |
undefined
- Source
host
Properties| Type | Description |
|---|---|
| string | Hostname sent with the view the plugin logs when it starts |
- Source
medals
Properties| Type | Description |
|---|---|
| Array | Medals fetched from Newgrounds, empty until ready, with the unlocks only when logged in |
- Source
pendingUnlocks :Map.<NewgroundsMedal, Promise.<boolean>>
- Map.<NewgroundsMedal, Promise.<boolean>>
| Type | Description |
|---|---|
| Map.<NewgroundsMedal, Promise.<boolean>> | Medals whose unlock is in flight or waiting to be resent, with their request's promise; one the server refused leaves it |
- Source
ready
Properties| Type | Description |
|---|---|
| Promise.<NewgroundsPlugin> | Resolves once the session is checked and the lists are in, empty if the server could not be reached |
- Source
scoreboards
Properties| Type | Description |
|---|---|
| Array | Scoreboards fetched from Newgrounds, empty until ready |
- Source
session_id :string|null
- string |
null
| Type | Description |
|---|---|
| string | | Newgrounds session id from the URL, null when not logged in or once the session is lost |
- Source
user :Object|null
- Object |
null
| Type | Description |
|---|---|
| Object | | The logged in player once ready, null when not logged in |
- Source
Methods
(async) call(component, parametersopt, session_idopt) → {Promise.<Object>}
Send a message to call a component of the Newgrounds API
| Name | Type | Attributes | Description |
|---|---|---|---|
component | string | Name of the component | |
parameters | Object | <optional> | Parameters to use for call |
session_id | string | | <optional> | The session to send, the player's by default |
- Source
- The response JSON object, undefined when the call failed or took over 15 seconds; a component's own success and error are in result.data, and a cipher that is not a key gives error 201
- Type:
- Promise.<Object>
(async) encrypt(text) → {Promise.<string>}
Encrypt text the way the Newgrounds gateway expects, AES-128 CBC with a random iv in front, as Base64
| Name | Type | Description |
|---|---|---|
text | string |
- Source
- Type:
- Promise.<string>
getScores(id, useropt, socialopt, skipopt, limitopt, periodopt) → {Promise.<Object>}
Get scores from a scoreboard
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
id | number | The scoreboard id | ||
user | string | | <optional> | A user's id or name, to load only their scores | |
social | boolean | <optional> | false | If true, only the scores of the user and their friends, the logged in player when user is left out |
skip | number | <optional> | 0 | Number of scores to skip over |
limit | number | <optional> | 10 | Number of scores to include in the list |
period | string | <optional> | 'D' today, which the server assumes when left out, 'W' this week, 'M' this month, 'Y' this year or 'A' all time |
- Source
- The response JSON object, undefined when the call failed; the scores are in result.data.scores, each with user.name, value and formatted_value; without a user or social it is the whole board
- Type:
- Promise.<Object>
logView()
- Deprecated
- since 1.20, the view is logged when the plugin starts, so this does nothing
- Source
postScore(id, value) → {Promise.<Object>}
Send message to post score
| Name | Type | Description |
|---|---|---|
id | number | The scoreboard id |
value | number | The score value, a whole number |
- Source
- The response JSON object, undefined when the call failed; result.data.success says whether it posted, which needs a logged in player; an answer that the session is gone makes the game play as not logged in, and one that timed out may still have posted
- Type:
- Promise.<Object>
resendUnlocks()
Send the unlocks whose request did not reach the server again, which the session check does every minute
- A request still out is left to answer, and while unlocks are prevented they wait
- Source
unlockMedal(id) → {Promise.<Object>}
Send a request to unlock a medal by id, the local medal is not changed; NewgroundsMedal.unlock sends this and waits for the answer
| Name | Type | Description |
|---|---|---|
id | number | The medal id |
- Source
- The response JSON object, undefined when the call failed
- Type:
- Promise.<Object>