@errorgamer2000/scratch-cloud v0.1.0
scratch-cloud
A TypeScript library that allows communication with the scratch cloud servers.
A short example:
import { ScratchCloud } from "@errorgamer2000/scratch-cloud";
async function main() {
const cloud = new ScratchCloud();
await cloud.login("<username>", "<password>");
const session = cloud.createSession(
"<project_id>",
false /* do not use TurboWarp servers */
);
session.on("set", (name: string, value: string) => {
console.log(`${name} was set to ${value}.`);
});
}
This is a rewrite of the cloudsession api from my original scratch3-api
module.
This module provides only methods to communicate with the Scratch/TurboWarp
cloud servers. To use methods that are not centered around the cloud servers,
use scratch-connect
(not yet published). For string to number conversions, see
stringstonumbers
.
Installation
Install with npm or other package manager:
npm install @errorgamer2000/scratch-cloud
Or by cloning this repository:
git clone https://github.com/ErrorGamer2000/scratch-cloud.git
Exports:
Classes
ScratchCloud
Kind: global class
new ScratchCloud()
scratchCloud.login(username, password)
Kind: instance method of ScratchCloud Throws:
- TypeError If the username or password are incorrect.
- Error If the scratch server gives an invalid response.
Param | Description |
---|---|
username | The username of the account to log in with. |
password | The password of the account to log in with. |
scratchCloud.createSession(project, turbowarp)
Kind: instance method of ScratchCloud
Param | Default | Description |
---|---|---|
project | The ID of the project to connect to. | |
turbowarp | false | Use the TurboWarp cloud servers rather than the Scratch cloud servers. |
Session
Kind: global class
new Session(userData, projectId, turbowarp)
Param | Default | Description |
---|---|---|
userData | Data used to validate the user's login and connect using the correct account. | |
projectId | The ID of the project to connect to. | |
turbowarp | false | Use the TurboWarp cloud servers rather than the Scratch cloud servers. |
session.set(name, value)
Kind: instance method of Session
Param | Description |
---|---|
name | The name of the cloud variable. |
value | The value to set it to. Can be a string or a number, but can only include numerical digits. |
session.get(name)
Kind: instance method of Session
Param | Description |
---|---|
name | The name of the cloud variable |
session.enableAutoPrefix()
Kind: instance method of Session See: Session.autoPrefix
session.disableAutoPrefix()
Kind: instance method of Session See: Session.autoPrefix
session.on(eventName, listener)
Kind: instance method of Session
Param | Description |
---|---|
eventName | The name of the event. |
listener | The callback function. |
session.once(eventName, listener)
Kind: instance method of Session
Param | Description |
---|---|
eventName | the name of the event. |
listener | the callback listener. |
© 2022 ErrorGamer2000
2 years ago