@photon-os/sdk 1.0.0-alpha.1 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1219,6 +1219,63 @@ var AppManager = class {
1219
1219
  }
1220
1220
  };
1221
1221
 
1222
+ // src/framework/DeviceManager.ts
1223
+ var DeviceManager = class {
1224
+ constructor(os) {
1225
+ this.messageCallbacks = /* @__PURE__ */ new Set();
1226
+ this.subscribed = false;
1227
+ this.os = os;
1228
+ }
1229
+ /** Get all registered Second Life devices for the current user */
1230
+ async getRegisteredDevices() {
1231
+ const api2 = await this.os.getRPCAPI();
1232
+ return await api2.devices_getRegistered();
1233
+ }
1234
+ /** Send a message to a registered device */
1235
+ async sendMessage(deviceId, type, payload = {}) {
1236
+ const api2 = await this.os.getRPCAPI();
1237
+ return await api2.devices_sendMessage(deviceId, type, payload);
1238
+ }
1239
+ /** Unregister a device */
1240
+ async unregisterDevice(deviceId) {
1241
+ const api2 = await this.os.getRPCAPI();
1242
+ await api2.devices_unregister(deviceId);
1243
+ }
1244
+ /** Subscribe to messages from all registered devices */
1245
+ subscribeToMessages(callback) {
1246
+ this.messageCallbacks.add(callback);
1247
+ if (!this.subscribed) {
1248
+ this.startSubscription();
1249
+ }
1250
+ return () => {
1251
+ this.messageCallbacks.delete(callback);
1252
+ if (this.messageCallbacks.size === 0 && this.subscribed) {
1253
+ this.stopSubscription();
1254
+ }
1255
+ };
1256
+ }
1257
+ /** Internal: Start the message subscription via RPC */
1258
+ async startSubscription() {
1259
+ const api2 = await this.os.getRPCAPI();
1260
+ await api2.devices_subscribe((message) => {
1261
+ for (const callback of this.messageCallbacks) {
1262
+ try {
1263
+ callback(message);
1264
+ } catch (error) {
1265
+ console.error("Error in device message callback:", error);
1266
+ }
1267
+ }
1268
+ });
1269
+ this.subscribed = true;
1270
+ }
1271
+ /** Internal: Stop the message subscription */
1272
+ async stopSubscription() {
1273
+ const api2 = await this.os.getRPCAPI();
1274
+ await api2.devices_unsubscribe();
1275
+ this.subscribed = false;
1276
+ }
1277
+ };
1278
+
1222
1279
  // src/framework/PreferencesManager.ts
1223
1280
  var PreferencesManager = class {
1224
1281
  constructor(os) {
@@ -1290,6 +1347,7 @@ var OS = class {
1290
1347
  this.config = config;
1291
1348
  this.accounts = new AccountManager(this);
1292
1349
  this.apps = new AppManager(this);
1350
+ this.devices = new DeviceManager(this);
1293
1351
  this.prefs = new PreferencesManager(this);
1294
1352
  this.user = new UserManager(this);
1295
1353
  }