@@ -18,7 +18,8 @@ import type {
1818 PongCallback ,
1919 ModuleSettingCallback ,
2020} from './types' ;
21- import { SINRICPRO_SERVER_URL } from './types' ;
21+ import { SINRICPRO_SERVER_URL , EVENT_LIMIT_STATE , PHYSICAL_INTERACTION } from './types' ;
22+ import { EventLimiter } from './EventLimiter' ;
2223
2324// Internal config type with serverUrl
2425interface InternalConfig extends Required < SinricProConfig > {
@@ -37,6 +38,7 @@ export class SinricPro extends EventEmitter implements ISinricPro {
3738 private isInitialized : boolean = false ;
3839 private processingInterval : NodeJS . Timeout | null = null ;
3940 private moduleSettingCallback : ModuleSettingCallback | null = null ;
41+ private settingEventLimiter : EventLimiter = new EventLimiter ( EVENT_LIMIT_STATE ) ;
4042
4143 private constructor ( ) {
4244 super ( ) ;
@@ -216,6 +218,67 @@ export class SinricPro extends EventEmitter implements ISinricPro {
216218 this . moduleSettingCallback = callback ;
217219 }
218220
221+ /**
222+ * Send a module-level setting event to SinricPro server
223+ *
224+ * Module settings are configuration values for the module (dev board) itself.
225+ * Use this to report setting changes like WiFi configuration, logging level,
226+ * or other module-wide settings.
227+ *
228+ * @param settingId - The setting identifier
229+ * @param value - The setting value (can be any JSON-serializable type)
230+ * @param cause - (optional) Reason for the event (default: 'PHYSICAL_INTERACTION')
231+ * @returns Promise<boolean> - true if event was sent, false if rate limited
232+ * @example
233+ * ```typescript
234+ * await SinricPro.sendSettingEvent('wifi_retry_count', 5);
235+ * await SinricPro.sendSettingEvent('debug_mode', true);
236+ * ```
237+ */
238+ async sendSettingEvent (
239+ settingId : string ,
240+ value : unknown ,
241+ cause : string = PHYSICAL_INTERACTION
242+ ) : Promise < boolean > {
243+ if ( this . settingEventLimiter . isLimited ( ) ) {
244+ return false ;
245+ }
246+
247+ if ( ! this . isConnected ( ) ) {
248+ SinricProSdkLogger . error ( 'Cannot send setting event: Not connected to SinricPro' ) ;
249+ return false ;
250+ }
251+
252+ const eventMessage : SinricProMessage = {
253+ header : {
254+ payloadVersion : 2 ,
255+ signatureVersion : 1 ,
256+ } ,
257+ payload : {
258+ action : 'setSetting' ,
259+ replyToken : this . generateMessageId ( ) ,
260+ type : 'event' as MessageType ,
261+ createdAt : this . getTimestamp ( ) ,
262+ cause : { type : cause } ,
263+ scope : 'module' ,
264+ value : { id : settingId , value } ,
265+ } ,
266+ } ;
267+
268+ try {
269+ await this . sendMessage ( eventMessage ) ;
270+ SinricProSdkLogger . debug ( `Module setting event sent: ${ settingId } ` , value ) ;
271+ return true ;
272+ } catch ( error ) {
273+ SinricProSdkLogger . error ( `Failed to send module setting event ${ settingId } :` , error ) ;
274+ return false ;
275+ }
276+ }
277+
278+ private generateMessageId ( ) : string {
279+ return `${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 11 ) } ` ;
280+ }
281+
219282 /**
220283 * Stop the SinricPro SDK and disconnect from the server
221284 * @example
0 commit comments