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

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.d.mts CHANGED
@@ -12,6 +12,37 @@ type RunningAppInstance = {
12
12
  isInBackground: boolean;
13
13
  };
14
14
 
15
+ /** A registered Second Life device */
16
+ interface SLDevice {
17
+ id: string;
18
+ objectKey: string;
19
+ objectName: string;
20
+ regionName?: string;
21
+ isOnline: boolean;
22
+ lastHeartbeatAt: Date;
23
+ registeredAt: Date;
24
+ metadata?: Record<string, unknown>;
25
+ }
26
+ /** A message received from a Second Life device */
27
+ interface DeviceMessage {
28
+ deviceId: string;
29
+ objectKey: string;
30
+ objectName: string;
31
+ type: string;
32
+ payload: Record<string, unknown>;
33
+ timestamp: Date;
34
+ }
35
+ /** Result of sending a message to a device */
36
+ interface SendMessageResult {
37
+ success: boolean;
38
+ error?: string;
39
+ deviceOffline?: boolean;
40
+ }
41
+ /** Callback for receiving device messages */
42
+ type DeviceMessageCallback = (message: DeviceMessage) => void;
43
+ /** Function to unsubscribe from device messages */
44
+ type Unsubscribe = () => void;
45
+
15
46
  /**
16
47
  * Value types supported for preferences.
17
48
  * Stored as JSONB in the database.
@@ -69,6 +100,11 @@ type OperatingSystemAPI = {
69
100
  accounts_getLinkedSecondLifeAccounts: () => Promise<SecondLifeAccount[]>;
70
101
  accounts_unlinkSecondLifeAccount: (avatarUuid: string) => Promise<void>;
71
102
  accounts_generateLinkingCode: () => Promise<LinkingCode>;
103
+ devices_getRegistered: () => Promise<SLDevice[]>;
104
+ devices_sendMessage: (deviceId: string, type: string, payload: Record<string, unknown>) => Promise<SendMessageResult>;
105
+ devices_unregister: (deviceId: string) => Promise<void>;
106
+ devices_subscribe: (callback: (message: DeviceMessage) => void) => Promise<void>;
107
+ devices_unsubscribe: () => Promise<void>;
72
108
  };
73
109
 
74
110
  declare class AccountManager {
@@ -91,6 +127,25 @@ declare class AppManager {
91
127
  requestAppUninstall(app: AppDefinition): Promise<void>;
92
128
  }
93
129
 
130
+ declare class DeviceManager {
131
+ private os;
132
+ private messageCallbacks;
133
+ private subscribed;
134
+ constructor(os: OS);
135
+ /** Get all registered Second Life devices for the current user */
136
+ getRegisteredDevices(): Promise<SLDevice[]>;
137
+ /** Send a message to a registered device */
138
+ sendMessage(deviceId: string, type: string, payload?: Record<string, unknown>): Promise<SendMessageResult>;
139
+ /** Unregister a device */
140
+ unregisterDevice(deviceId: string): Promise<void>;
141
+ /** Subscribe to messages from all registered devices */
142
+ subscribeToMessages(deviceId: string, callback: DeviceMessageCallback): Unsubscribe;
143
+ /** Internal: Start the message subscription via RPC */
144
+ private startSubscription;
145
+ /** Internal: Stop the message subscription */
146
+ private stopSubscription;
147
+ }
148
+
94
149
  /**
95
150
  * Manages user preferences for apps.
96
151
  *
@@ -143,6 +198,7 @@ type OSConfig = {
143
198
  declare class OS {
144
199
  accounts: AccountManager;
145
200
  apps: AppManager;
201
+ devices: DeviceManager;
146
202
  prefs: PreferencesManager;
147
203
  user: UserManager;
148
204
  private config;
@@ -153,4 +209,4 @@ declare class OS {
153
209
 
154
210
  declare const VERSION = "1.0.0";
155
211
 
156
- export { type AppBundleId, type AppDefinition, type AppLaunchResult, type LinkingCode, OS, type OSConfig, type OperatingSystemAPI, type PhotonUser, type PreferenceValue, type RunningAppInstance, type SecondLifeAccount, VERSION };
212
+ export { type AppBundleId, type AppDefinition, type AppLaunchResult, type DeviceMessage, type DeviceMessageCallback, type LinkingCode, OS, type OSConfig, type OperatingSystemAPI, type PhotonUser, type PreferenceValue, type RunningAppInstance, type SLDevice, type SecondLifeAccount, type SendMessageResult, type Unsubscribe, VERSION };
package/dist/index.d.ts CHANGED
@@ -12,6 +12,37 @@ type RunningAppInstance = {
12
12
  isInBackground: boolean;
13
13
  };
14
14
 
15
+ /** A registered Second Life device */
16
+ interface SLDevice {
17
+ id: string;
18
+ objectKey: string;
19
+ objectName: string;
20
+ regionName?: string;
21
+ isOnline: boolean;
22
+ lastHeartbeatAt: Date;
23
+ registeredAt: Date;
24
+ metadata?: Record<string, unknown>;
25
+ }
26
+ /** A message received from a Second Life device */
27
+ interface DeviceMessage {
28
+ deviceId: string;
29
+ objectKey: string;
30
+ objectName: string;
31
+ type: string;
32
+ payload: Record<string, unknown>;
33
+ timestamp: Date;
34
+ }
35
+ /** Result of sending a message to a device */
36
+ interface SendMessageResult {
37
+ success: boolean;
38
+ error?: string;
39
+ deviceOffline?: boolean;
40
+ }
41
+ /** Callback for receiving device messages */
42
+ type DeviceMessageCallback = (message: DeviceMessage) => void;
43
+ /** Function to unsubscribe from device messages */
44
+ type Unsubscribe = () => void;
45
+
15
46
  /**
16
47
  * Value types supported for preferences.
17
48
  * Stored as JSONB in the database.
@@ -69,6 +100,11 @@ type OperatingSystemAPI = {
69
100
  accounts_getLinkedSecondLifeAccounts: () => Promise<SecondLifeAccount[]>;
70
101
  accounts_unlinkSecondLifeAccount: (avatarUuid: string) => Promise<void>;
71
102
  accounts_generateLinkingCode: () => Promise<LinkingCode>;
103
+ devices_getRegistered: () => Promise<SLDevice[]>;
104
+ devices_sendMessage: (deviceId: string, type: string, payload: Record<string, unknown>) => Promise<SendMessageResult>;
105
+ devices_unregister: (deviceId: string) => Promise<void>;
106
+ devices_subscribe: (callback: (message: DeviceMessage) => void) => Promise<void>;
107
+ devices_unsubscribe: () => Promise<void>;
72
108
  };
73
109
 
74
110
  declare class AccountManager {
@@ -91,6 +127,25 @@ declare class AppManager {
91
127
  requestAppUninstall(app: AppDefinition): Promise<void>;
92
128
  }
93
129
 
130
+ declare class DeviceManager {
131
+ private os;
132
+ private messageCallbacks;
133
+ private subscribed;
134
+ constructor(os: OS);
135
+ /** Get all registered Second Life devices for the current user */
136
+ getRegisteredDevices(): Promise<SLDevice[]>;
137
+ /** Send a message to a registered device */
138
+ sendMessage(deviceId: string, type: string, payload?: Record<string, unknown>): Promise<SendMessageResult>;
139
+ /** Unregister a device */
140
+ unregisterDevice(deviceId: string): Promise<void>;
141
+ /** Subscribe to messages from all registered devices */
142
+ subscribeToMessages(deviceId: string, callback: DeviceMessageCallback): Unsubscribe;
143
+ /** Internal: Start the message subscription via RPC */
144
+ private startSubscription;
145
+ /** Internal: Stop the message subscription */
146
+ private stopSubscription;
147
+ }
148
+
94
149
  /**
95
150
  * Manages user preferences for apps.
96
151
  *
@@ -143,6 +198,7 @@ type OSConfig = {
143
198
  declare class OS {
144
199
  accounts: AccountManager;
145
200
  apps: AppManager;
201
+ devices: DeviceManager;
146
202
  prefs: PreferencesManager;
147
203
  user: UserManager;
148
204
  private config;
@@ -153,4 +209,4 @@ declare class OS {
153
209
 
154
210
  declare const VERSION = "1.0.0";
155
211
 
156
- export { type AppBundleId, type AppDefinition, type AppLaunchResult, type LinkingCode, OS, type OSConfig, type OperatingSystemAPI, type PhotonUser, type PreferenceValue, type RunningAppInstance, type SecondLifeAccount, VERSION };
212
+ export { type AppBundleId, type AppDefinition, type AppLaunchResult, type DeviceMessage, type DeviceMessageCallback, type LinkingCode, OS, type OSConfig, type OperatingSystemAPI, type PhotonUser, type PreferenceValue, type RunningAppInstance, type SLDevice, type SecondLifeAccount, type SendMessageResult, type Unsubscribe, VERSION };
package/dist/index.js CHANGED
@@ -1233,6 +1233,71 @@ var AppManager = class {
1233
1233
  }
1234
1234
  };
1235
1235
 
1236
+ // src/framework/DeviceManager.ts
1237
+ var DeviceManager = class {
1238
+ constructor(os) {
1239
+ this.messageCallbacks = {};
1240
+ this.subscribed = false;
1241
+ this.os = os;
1242
+ }
1243
+ /** Get all registered Second Life devices for the current user */
1244
+ async getRegisteredDevices() {
1245
+ const api2 = await this.os.getRPCAPI();
1246
+ return await api2.devices_getRegistered();
1247
+ }
1248
+ /** Send a message to a registered device */
1249
+ async sendMessage(deviceId, type, payload = {}) {
1250
+ const api2 = await this.os.getRPCAPI();
1251
+ return await api2.devices_sendMessage(deviceId, type, payload);
1252
+ }
1253
+ /** Unregister a device */
1254
+ async unregisterDevice(deviceId) {
1255
+ const api2 = await this.os.getRPCAPI();
1256
+ await api2.devices_unregister(deviceId);
1257
+ }
1258
+ /** Subscribe to messages from all registered devices */
1259
+ subscribeToMessages(deviceId, callback) {
1260
+ this.messageCallbacks[deviceId] = this.messageCallbacks[deviceId] ?? [];
1261
+ this.messageCallbacks[deviceId].add(callback);
1262
+ if (!this.subscribed) {
1263
+ this.startSubscription();
1264
+ }
1265
+ return () => {
1266
+ if (this.messageCallbacks[deviceId]) {
1267
+ this.messageCallbacks[deviceId].delete(callback);
1268
+ }
1269
+ const totalSubscriptions = Object.values(this.messageCallbacks).reduce(
1270
+ (acc, cv) => acc + cv.size,
1271
+ 0
1272
+ );
1273
+ if (totalSubscriptions === 0 && this.subscribed) {
1274
+ this.stopSubscription();
1275
+ }
1276
+ };
1277
+ }
1278
+ /** Internal: Start the message subscription via RPC */
1279
+ async startSubscription() {
1280
+ const api2 = await this.os.getRPCAPI();
1281
+ await api2.devices_subscribe((message) => {
1282
+ const callbacks = this.messageCallbacks[message.deviceId] ?? [];
1283
+ for (const callback of callbacks) {
1284
+ try {
1285
+ callback(message);
1286
+ } catch (error) {
1287
+ console.error("Error in device message callback:", error);
1288
+ }
1289
+ }
1290
+ });
1291
+ this.subscribed = true;
1292
+ }
1293
+ /** Internal: Stop the message subscription */
1294
+ async stopSubscription() {
1295
+ const api2 = await this.os.getRPCAPI();
1296
+ await api2.devices_unsubscribe();
1297
+ this.subscribed = false;
1298
+ }
1299
+ };
1300
+
1236
1301
  // src/framework/PreferencesManager.ts
1237
1302
  var PreferencesManager = class {
1238
1303
  constructor(os) {
@@ -1304,6 +1369,7 @@ var OS = class {
1304
1369
  this.config = config;
1305
1370
  this.accounts = new AccountManager(this);
1306
1371
  this.apps = new AppManager(this);
1372
+ this.devices = new DeviceManager(this);
1307
1373
  this.prefs = new PreferencesManager(this);
1308
1374
  this.user = new UserManager(this);
1309
1375
  }