mirror of
https://github.com/AeThex-Corporation/AeThex-OS.git
synced 2026-04-18 22:37:21 +00:00
98 lines
No EOL
2.9 KiB
JavaScript
98 lines
No EOL
2.9 KiB
JavaScript
"use strict";
|
|
/**
|
|
* AeThex DataSync - Cross-Platform State Synchronization
|
|
* Sync data across multiple metaverse platforms
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.DataSync = void 0;
|
|
class DataSync {
|
|
/**
|
|
* Sync data across platforms
|
|
*/
|
|
static async sync(data, platforms) {
|
|
// In production, this would sync to AeThex platform service
|
|
// For now, store locally
|
|
const dataKey = JSON.stringify(data);
|
|
const platformsMap = new Map();
|
|
for (const platform of platforms) {
|
|
platformsMap.set(platform, { ...data, syncedAt: new Date() });
|
|
}
|
|
this.syncedData.set(dataKey, platformsMap);
|
|
console.log(`Data synced across platforms: ${platforms.join(', ')}`);
|
|
// Notify listeners
|
|
this.notifyListeners(dataKey, data);
|
|
}
|
|
/**
|
|
* Pull data from specific platform
|
|
*/
|
|
static async pull(userId, platform) {
|
|
// In production, this would fetch from AeThex platform service
|
|
// For now, return from local storage
|
|
for (const [key, platformsMap] of this.syncedData.entries()) {
|
|
if (key.includes(userId)) {
|
|
return platformsMap.get(platform) || null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
/**
|
|
* Push data to specific platform
|
|
*/
|
|
static async push(userId, platform, data) {
|
|
const key = `user:${userId}`;
|
|
if (!this.syncedData.has(key)) {
|
|
this.syncedData.set(key, new Map());
|
|
}
|
|
const platformsMap = this.syncedData.get(key);
|
|
platformsMap.set(platform, { ...data, updatedAt: new Date() });
|
|
console.log(`Data pushed to ${platform} for user ${userId}`);
|
|
}
|
|
/**
|
|
* Listen for updates
|
|
*/
|
|
static onUpdate(userId, callback) {
|
|
const key = `user:${userId}`;
|
|
if (!this.listeners.has(key)) {
|
|
this.listeners.set(key, []);
|
|
}
|
|
this.listeners.get(key).push(callback);
|
|
}
|
|
/**
|
|
* Notify listeners of data changes
|
|
*/
|
|
static notifyListeners(key, data) {
|
|
const callbacks = this.listeners.get(key) || [];
|
|
for (const callback of callbacks) {
|
|
callback(data);
|
|
}
|
|
}
|
|
/**
|
|
* Get sync status
|
|
*/
|
|
static getSyncStatus(userId) {
|
|
const key = `user:${userId}`;
|
|
const platformsMap = this.syncedData.get(key);
|
|
if (!platformsMap) {
|
|
return {};
|
|
}
|
|
const status = {};
|
|
for (const [platform, data] of platformsMap.entries()) {
|
|
status[platform] = {
|
|
synced: true,
|
|
lastSync: data.syncedAt || data.updatedAt
|
|
};
|
|
}
|
|
return status;
|
|
}
|
|
/**
|
|
* Clear synced data (for testing)
|
|
*/
|
|
static clear() {
|
|
this.syncedData.clear();
|
|
this.listeners.clear();
|
|
}
|
|
}
|
|
exports.DataSync = DataSync;
|
|
DataSync.syncedData = new Map();
|
|
DataSync.listeners = new Map();
|
|
//# sourceMappingURL=DataSync.js.map
|