You can use connector.storage to save data to platform's cloud storage.
Supported Platforms
- ✅
VK Games
- ✅
OK Games
- ✅
Yandex Games
- ✅
Facebook Instant Games
Check for support
if (connector.storage.isSupported) {
// storage supported
}
Storage data is loaded automatically, you can wait for readiness:
await connector.storage.ready;
// or via event;
connector.storage.on("ready", () => {});
Setting data
// data you save must be a serializable object
const data = {
foo: "bar"
}
// you can wait for data to be saved
const success = await connector.storage.set("key", data);
if (success) {
// data saved successfully to platform's cloud storage
}
Getting data
const data = connector.storage.get("key");
List all saved keys
const keys = connector.storage.getKeys();
Loading data
You can force loading from cloud storage, overriding current in-memory data
const success = await connector.storage.load();
if (success) {
// successfully loaded from cloud storage
}
// or via event;
connector.storage.on("load", (success) => {});
Members
(static) ready :Promise
Returns promise you can use to wait for storage init
Type:
- Promise
(static) isSupported :boolean
Whether cloud storage is supported by the platform
Type:
- boolean
Methods
(static) set(key, data) → {Promise.<boolean>}
Set data for key
Parameters:
Name | Type | Description |
---|---|---|
key | string | Key |
data | object | An object to be saved to cloud storage. The object must contain only serializable values. |
Returns:
- Type:
- Promise.<boolean>
(static) get(key) → {object}
Get data for key
Parameters:
Name | Type | Description |
---|---|---|
key | string | Key |
Returns:
- Type:
- object
(static) getKeys() → {Array.<string>}
Returns list of all currently saved keys
Returns:
- Type:
- Array.<string>
(static) load() → {Promise.<boolean>}
Load data from server and override local data
Returns:
- Type:
- Promise.<boolean>