1# Developing a JS Widget 2 3 4The following describes how to develop JS widgets based on the web-like development paradigm. 5 6 7## Working Principles 8 9Below shows the working principles of the widget framework. 10 11**Figure 1** Widget framework working principles in the stage model 12 13 14 15The widget host consists of the following modules: 16 17- Widget usage: provides operations such as creating, deleting, or updating a widget. 18 19- Communication adapter: provided by the SDK for communication with the Widget Manager. It sends widget-related operations to the Widget Manager. 20 21The Widget Manager consists of the following modules: 22 23- Periodic updater: starts a scheduled task based on the update policy to periodically update a widget after it is added to the Widget Manager. 24 25- Cache manager: caches view information of a widget after it is added to the Widget Manager. This enables the cached data to be directly returned when the widget is obtained next time, greatly reducing the latency. 26 27- Lifecycle manager: suspends update when a widget is switched to the background or is blocked, and updates and/or clears widget data during upgrade and deletion. 28 29- Object manager: manages RPC objects of the widget host. It is used to verify requests from the widget host and process callbacks after the widget update. 30 31- Communication adapter: communicates with the widget host and provider through RPCs. 32 33The widget provider consists of the following modules: 34 35- Widget service: implemented by the widget provider developer to process requests on widget creation, update, and deletion, and to provide corresponding widget services. 36 37- Instance manager: implemented by the widget provider developer for persistent management of widget instances allocated by the Widget Manager. 38 39- Communication adapter: provided by the SDK for communication with the Widget Manager. It pushes update data to the Widget Manager. 40 41> **NOTE** 42> 43> You only need to develop the widget provider. The system automatically handles the work of the widget host and Widget Manager. 44 45 46## Available APIs 47 48The **FormExtensionAbility** class has the following APIs. For details, see [FormExtensionAbility](../reference/apis/js-apis-app-form-formExtensionAbility.md). 49 50| Name| Description| 51| -------- | -------- | 52| onAddForm(want: Want): formBindingData.FormBindingData | Called to notify the widget provider that a widget is being created.| 53| onCastToNormalForm(formId: string): void | Called to notify the widget provider that a temporary widget is being converted to a normal one.| 54| onUpdateForm(formId: string): void | Called to notify the widget provider that a widget is being updated.| 55| onChangeFormVisibility(newStatus: { [key: string]: number }): void | Called to notify the widget provider that the widget visibility status is being changed.| 56| onFormEvent(formId: string, message: string): void | Called to instruct the widget provider to process a widget event.| 57| onRemoveForm(formId: string): void | Called to notify the widget provider that a widget is being destroyed.| 58| onConfigurationUpdate(config: Configuration): void | Called when the configuration of the environment where the widget is running is being updated.| 59| onShareForm?(formId: string): { [key: string]: Object } | Called to notify the widget provider that the widget host is sharing the widget data.| 60 61The **FormProvider** class has the following APIs. For details, see [FormProvider](../reference/apis/js-apis-app-form-formProvider.md). 62 63| Name| Description| 64| -------- | -------- | 65| setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback<void>): void; | Sets the next refresh time for a widget. This API uses an asynchronous callback to return the result.| 66| setFormNextRefreshTime(formId: string, minute: number): Promise<void>; | Sets the next refresh time for a widget. This API uses a promise to return the result.| 67| updateForm(formId: string, formBindingData: FormBindingData, callback: AsyncCallback<void>): void; | Updates a widget. This API uses an asynchronous callback to return the result.| 68| updateForm(formId: string, formBindingData: FormBindingData): Promise<void>; | Updates a widget. This API uses a promise to return the result.| 69 70The **FormBindingData** class has the following APIs. For details, see [FormBindingData](../reference/apis/js-apis-app-form-formBindingData.md). 71 72| Name| Description| 73| -------- | -------- | 74| createFormBindingData(obj?: Object \| string): FormBindingData | Creates a **FormBindingData** object.| 75 76 77## How to Develop 78 79The widget provider development based on the [stage model](stage-model-development-overview.md) involves the following key steps: 80 81- [Creating a FormExtensionAbility Instance](#creating-a-formextensionability-instance): Develop the lifecycle callback functions of FormExtensionAbility. 82 83- [Configuring the Widget Configuration Files](#configuring-the-widget-configuration-files): Configure the application configuration file **module.json5** and profile configuration file. 84 85- [Persistently Storing Widget Data](#persistently-storing-widget-data): Manage widget data persistence. 86 87- [Updating Widget Data](#updating-widget-data): Call **updateForm()** to update the information displayed in a widget. 88 89- [Developing the Widget UI Page](#developing-the-widget-ui-page): Use HML+CSS+JSON to develop a JS widget UI page. 90 91- [Developing Widget Events](#developing-widget-events): Add the router and message events for a widget. 92 93 94### Creating a FormExtensionAbility Instance 95 96To create a widget in the stage model, you need to implement the lifecycle callbacks of FormExtensionAbility. Generate a widget template and then perform the following: 97 981. Import related modules to **EntryFormAbility.ets**. 99 100 101 ```ts 102 import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; 103 import formBindingData from '@ohos.app.form.formBindingData'; 104 import formInfo from '@ohos.app.form.formInfo'; 105 import formProvider from '@ohos.app.form.formProvider'; 106 import dataPreferences from '@ohos.data.preferences'; 107 import Want from '@ohos.app.ability.Want'; 108 import Base from '@ohos.base'; 109 ``` 110 1112. Implement the FormExtension lifecycle callbacks in **EntryFormAbility.ets**. 112 113 114 ```ts 115 export default class EntryFormAbility extends FormExtensionAbility { 116 onAddForm(want: Want) { 117 console.info('[EntryFormAbility] onAddForm'); 118 // Called when the widget is created. The widget provider should return the widget data binding class. 119 let obj: Record<string, string> = { 120 "title": "titleOnCreate", 121 "detail": "detailOnCreate" 122 }; 123 let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); 124 return formData; 125 } 126 onCastToNormalForm(formId: string) { 127 // Called when a temporary widget is being converted into a normal one. The widget provider should respond to the conversion. 128 console.info('[EntryFormAbility] onCastToNormalForm'); 129 } 130 onUpdateForm(formId: string) { 131 // Override this method to support scheduled updates, periodic updates, or updates requested by the widget host. 132 console.info('[EntryFormAbility] onUpdateForm'); 133 let obj: Record<string, string> = { 134 "title": "titleOnUpdate", 135 "detail": "detailOnUpdate" 136 }; 137 let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); 138 formProvider.updateForm(formId, formData).catch((error: Base.BusinessError) => { 139 console.info('[EntryFormAbility] updateForm, error:' + JSON.stringify(error)); 140 }); 141 } 142 onChangeFormVisibility(newStatus: Record<string, number>) { 143 // Called when the widget host initiates an event about visibility changes. The widget provider should do something to respond to the notification. This callback takes effect only for system applications. 144 console.info('[EntryFormAbility] onChangeFormVisibility'); 145 } 146 onFormEvent(formId: string, message: string) { 147 // If the widget supports event triggering, override this method and implement the trigger. 148 console.info('[EntryFormAbility] onFormEvent'); 149 } 150 onRemoveForm(formId: string) { 151 // Delete widget data. 152 console.info('[EntryFormAbility] onRemoveForm'); 153 } 154 onAcquireFormState(want: Want) { 155 return formInfo.FormState.READY; 156 } 157 } 158 ``` 159 160> **NOTE** 161> FormExtensionAbility cannot reside in the background. Therefore, continuous tasks cannot be processed in the widget lifecycle callbacks. 162 163 164### Configuring the Widget Configuration Files 165 1661. Configure ExtensionAbility information under **extensionAbilities** in the [module.json5 file](../quick-start/module-configuration-file.md). For a FormExtensionAbility, you must specify **metadata**. Specifically, set **name** to **ohos.extension.form** (fixed), and set **resource** to the index of the widget configuration information. 167 Example configuration: 168 169 170 ```json 171 { 172 "module": { 173 ... 174 "extensionAbilities": [ 175 { 176 "name": "EntryFormAbility", 177 "srcEntry": "./ets/entryformability/EntryFormAbility.ets", 178 "label": "$string:EntryFormAbility_label", 179 "description": "$string:EntryFormAbility_desc", 180 "type": "form", 181 "metadata": [ 182 { 183 "name": "ohos.extension.form", 184 "resource": "$profile:form_config" 185 } 186 ] 187 } 188 ] 189 } 190 } 191 ``` 192 1932. Configure the widget configuration information. In the **metadata** configuration item of FormExtensionAbility, you can specify the resource index of specific configuration information of the widget. For example, if **resource** is set to **$profile:form_config**, **form_config.json** in the **resources/base/profile/** directory of the development view is used as the profile configuration file of the widget. The following table describes the internal structure of the profile configuration file. 194 195 **Table 1** Widget profile configuration file 196 197 | Field| Description| Data Type| Default Value Allowed| 198 | -------- | -------- | -------- | -------- | 199 | name | Class name of the widget. The value is a string with a maximum of 127 bytes.| String| No| 200 | description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.| String| Yes (initial value: left empty)| 201 | src | Full path of the UI code corresponding to the widget.| String| No| 202 | window | Window-related configurations.| Object| Yes| 203 | isDefault | Whether the widget is a default one. Each UIAbility has only one default widget.<br>- **true**: The widget is the default one.<br>- **false**: The widget is not the default one.| Boolean| No| 204 | colorMode | Color mode of the widget.<br>- **auto**: auto-adaptive color mode<br>- **dark**: dark color mode<br>- **light**: light color mode| String| Yes (initial value: **auto**)| 205 | supportDimensions | Grid styles supported by the widget.<br>- **1 * 2**: indicates a grid with one row and two columns.<br>- **2 * 2**: indicates a grid with two rows and two columns.<br>- **2 * 4**: indicates a grid with two rows and four columns.<br>- **4 * 4**: indicates a grid with four rows and four columns.| String array| No| 206 | defaultDimension | Default grid style of the widget. The value must be available in the **supportDimensions** array of the widget.| String| No| 207 | updateEnabled | Whether the widget can be updated periodically.<br>- **true**: The widget can be updated at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). **updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.<br>- **false**: The widget cannot be updated periodically.| Boolean| No| 208 | scheduledUpdateTime | Scheduled time to update the widget. The value is in 24-hour format and accurate to minute.<br>**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.| String| Yes (initial value: **0:0**)| 209 | updateDuration | Interval to update the widget. The value is a natural number, in the unit of 30 minutes.<br>If the value is **0**, this field does not take effect.<br>If the value is a positive integer *N*, the interval is calculated by multiplying *N* and 30 minutes.<br>**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.| Number| Yes (initial value: **0**)| 210 | formConfigAbility | Link to a specific page of the application. The value is a URI.| String| Yes (initial value: left empty)| 211 | formVisibleNotify | Whether the widget is allowed to use the widget visibility notification.| String| Yes (initial value: left empty)| 212 | metaData | Metadata of the widget. This field contains the array of the **customizeData** field.| Object| Yes (initial value: left empty)| 213 214 Example configuration: 215 216 217 ```json 218 { 219 "forms": [ 220 { 221 "name": "widget", 222 "description": "This is a service widget.", 223 "src": "./js/widget/pages/index/index", 224 "window": { 225 "designWidth": 720, 226 "autoDesignWidth": true 227 }, 228 "colorMode": "auto", 229 "isDefault": true, 230 "updateEnabled": true, 231 "scheduledUpdateTime": "10:30", 232 "updateDuration": 1, 233 "defaultDimension": "2*2", 234 "supportDimensions": [ 235 "2*2" 236 ] 237 } 238 ] 239 } 240 ``` 241 242 243### Persistently Storing Widget Data 244 245A widget provider is usually started when it is needed to provide information about a widget. The Widget Manager supports multi-instance management and uses the widget ID to identify an instance. If the widget provider supports widget data modification, it must persistently store the data based on the widget ID, so that it can access the data of the target widget when obtaining, updating, or starting a widget. 246 247 248```ts 249import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; 250import formBindingData from '@ohos.app.form.formBindingData'; 251import dataPreferences from '@ohos.data.preferences'; 252import Want from '@ohos.app.ability.Want'; 253import Base from '@ohos.base'; 254import common from '@ohos.app.ability.common' 255 256 257const DATA_STORAGE_PATH: string = "/data/storage/el2/base/haps/form_store"; 258let storeFormInfo = async (formId: string, formName: string, tempFlag: boolean, context: common.FormExtensionContext): Promise<void> => { 259 // Only the widget ID (formId), widget name (formName), and whether the widget is a temporary one (tempFlag) are persistently stored. 260 let formInfo: Record<string, string | boolean | number> = { 261 "formName": formName, 262 "tempFlag": tempFlag, 263 "updateCount": 0 264 }; 265 try { 266 const storage: dataPreferences.Preferences = await dataPreferences.getPreferences(context, DATA_STORAGE_PATH); 267 // put form info 268 await storage.put(formId, JSON.stringify(formInfo)); 269 console.info(`[EntryFormAbility] storeFormInfo, put form info successfully, formId: ${formId}`); 270 await storage.flush(); 271 } catch (err) { 272 console.error(`[EntryFormAbility] failed to storeFormInfo, err: ${JSON.stringify(err as Base.BusinessError)}`); 273 } 274} 275 276export default class EntryFormAbility extends FormExtensionAbility { 277 onAddForm(want: Want) { 278 console.info('[EntryFormAbility] onAddForm'); 279 280 if (want.parameters) { 281 let formId = JSON.stringify(want.parameters["ohos.extra.param.key.form_identity"]); 282 let formName = JSON.stringify(want.parameters["ohos.extra.param.key.form_name"]); 283 let tempFlag = want.parameters["ohos.extra.param.key.form_temporary"] as boolean; 284 // Persistently store widget data for subsequent use, such as instance acquisition and update. 285 // Implement this API based on project requirements. 286 storeFormInfo(formId, formName, tempFlag, this.context); 287 } 288 289 let obj: Record<string, string> = { 290 "title": "titleOnCreate", 291 "detail": "detailOnCreate" 292 }; 293 let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); 294 return formData; 295 } 296} 297``` 298 299You should override **onRemoveForm** to implement widget data deletion. 300 301 302```ts 303import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; 304import dataPreferences from '@ohos.data.preferences'; 305import Base from '@ohos.base'; 306import common from '@ohos.app.ability.common' 307 308const DATA_STORAGE_PATH: string = "/data/storage/el2/base/haps/form_store"; 309let deleteFormInfo = async (formId: string, context: common.FormExtensionContext): Promise<void> => { 310 try { 311 const storage: dataPreferences.Preferences = await dataPreferences.getPreferences(context, DATA_STORAGE_PATH); 312 // Delete the widget information. 313 await storage.delete(formId); 314 console.info(`[EntryFormAbility] deleteFormInfo, del form info successfully, formId: ${formId}`); 315 await storage.flush(); 316 } catch (err) { 317 console.error(`[EntryFormAbility] failed to deleteFormInfo, err: ${JSON.stringify(err as Base.BusinessError)}`); 318 } 319} 320 321export default class EntryFormAbility extends FormExtensionAbility { 322 onRemoveForm(formId: string) { 323 console.info('[EntryFormAbility] onRemoveForm'); 324 // Delete the persistent widget instance data. 325 // Implement this API based on project requirements. 326 deleteFormInfo(formId, this.context); 327 } 328} 329``` 330 331For details about how to implement persistent data storage, see [Application Data Persistence](../database/app-data-persistence-overview.md). 332 333The **Want** object passed in by the widget host to the widget provider contains a flag that specifies whether the requested widget is normal or temporary. 334 335- Normal widget: a widget persistently used by the widget host 336 337- Temporary widget: a widget temporarily used by the widget host 338 339Data of a temporary widget will be deleted on the Widget Manager if the widget framework is killed and restarted. The widget provider, however, is not notified of the deletion and still keeps the data. Therefore, the widget provider needs to clear the data of temporary widgets proactively if the data has been kept for a long period of time. If the widget host has converted a temporary widget into a normal one, the widget provider should change the widget data from temporary storage to persistent storage. Otherwise, the widget data may be deleted by mistake. 340 341 342### Updating Widget Data 343 344When an application initiates a scheduled or periodic update, the application obtains the latest data and calls **updateForm()** to update the widget. 345 346 347```ts 348import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; 349import formBindingData from '@ohos.app.form.formBindingData'; 350import formProvider from '@ohos.app.form.formProvider'; 351import Base from '@ohos.base'; 352 353export default class EntryFormAbility extends FormExtensionAbility { 354 onUpdateForm(formId: string) { 355 // Override this method to support scheduled updates, periodic updates, or updates requested by the widget host. 356 console.info('[EntryFormAbility] onUpdateForm'); 357 let obj: Record<string, string> = { 358 "title": "titleOnUpdate", 359 "detail": "detailOnUpdate" 360 }; 361 let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); 362 // Call the updateForm() method to update the widget. Only the data passed through the input parameter is updated. Other information remains unchanged. 363 formProvider.updateForm(formId, formData).catch((error: Base.BusinessError) => { 364 console.info('[EntryFormAbility] updateForm, error:' + JSON.stringify(error)); 365 }); 366 } 367} 368``` 369 370 371### Developing the Widget UI Page 372 373You can use the web-like paradigm (HML+CSS+JSON) to develop JS widget pages. This section describes how to develop a page shown below. 374 375 376 377- HML: uses web-like paradigm components to describe the widget page information. 378 379 380 ```html 381 <div class="container"> 382 <stack> 383 <div class="container-img"> 384 <image src="/common/widget.png" class="bg-img"></image> 385 </div> 386 <div class="container-inner"> 387 <text class="title">{{title}}</text> 388 <text class="detail_text" onclick="routerEvent">{{detail}}</text> 389 </div> 390 </stack> 391 </div> 392 ``` 393 394- CSS: defines style information about the web-like paradigm components in HML. 395 396 397 ```css 398 .container { 399 flex-direction: column; 400 justify-content: center; 401 align-items: center; 402 } 403 404 .bg-img { 405 flex-shrink: 0; 406 height: 100%; 407 } 408 409 .container-inner { 410 flex-direction: column; 411 justify-content: flex-end; 412 align-items: flex-start; 413 height: 100%; 414 width: 100%; 415 padding: 12px; 416 } 417 418 .title { 419 font-size: 19px; 420 font-weight: bold; 421 color: white; 422 text-overflow: ellipsis; 423 max-lines: 1; 424 } 425 426 .detail_text { 427 font-size: 16px; 428 color: white; 429 opacity: 0.66; 430 text-overflow: ellipsis; 431 max-lines: 1; 432 margin-top: 6px; 433 } 434 ``` 435 436- JSON: defines data and event interaction on the widget UI page. 437 438 439 ```json 440 { 441 "data": { 442 "title": "TitleDefault", 443 "detail": "TextDefault" 444 }, 445 "actions": { 446 "routerEvent": { 447 "action": "router", 448 "abilityName": "EntryAbility", 449 "params": { 450 "message": "add detail" 451 } 452 } 453 } 454 } 455 ``` 456 457 458### Developing Widget Events 459 460You can set router and message events for components on a widget. The router event applies to UIAbility redirection, and the message event applies to custom click events. 461 462The key steps are as follows: 463 4641. Set the **onclick** field in the HML file to **routerEvent** or **messageEvent**, depending on the **actions** settings in the JSON file. 465 4662. Set the router event. 467 468 - **action**: **"router"**, which indicates a router event. 469 - **abilityName**: name of the UIAbility to redirect to (PageAbility component in the FA model and UIAbility component in the stage model). For example, the default UIAbility name of the stage model created by DevEco Studio is EntryAbility. 470 - **params**: custom parameters passed to the target UIAbility. Set them as required. The value can be obtained from **parameters** in **want** used for starting the target UIAbility. For example, in the lifecycle function **onCreate** of the MainAbility in the stage model, you can obtain **want** and its **parameters** field. 471 4723. Set the message event. 473 474 - **action**: **"message"**, which indicates a message event. 475 - **params**: custom parameters of the message event. Set them as required. The value can be obtained from **message** in the widget lifecycle function **onFormEvent()**. 476 477The following are examples: 478 479- HML file: 480 481 482 ```html 483 <div class="container"> 484 <stack> 485 <div class="container-img"> 486 <image src="/common/widget.png" class="bg-img"></image> 487 </div> 488 <div class="container-inner"> 489 <text class="title" onclick="routerEvent">{{title}}</text> 490 <text class="detail_text" onclick="messageEvent">{{detail}}</text> 491 </div> 492 </stack> 493 </div> 494 ``` 495 496- CSS file: 497 498 499 ```css 500 .container { 501 flex-direction: column; 502 justify-content: center; 503 align-items: center; 504 } 505 506 .bg-img { 507 flex-shrink: 0; 508 height: 100%; 509 } 510 511 .container-inner { 512 flex-direction: column; 513 justify-content: flex-end; 514 align-items: flex-start; 515 height: 100%; 516 width: 100%; 517 padding: 12px; 518 } 519 520 .title { 521 font-size: 19px; 522 font-weight: bold; 523 color: white; 524 text-overflow: ellipsis; 525 max-lines: 1; 526 } 527 528 .detail_text { 529 font-size: 16px; 530 color: white; 531 opacity: 0.66; 532 text-overflow: ellipsis; 533 max-lines: 1; 534 margin-top: 6px; 535 } 536 ``` 537 538- JSON file: 539 540 541 ```json 542 { 543 "data": { 544 "title": "TitleDefault", 545 "detail": "TextDefault" 546 }, 547 "actions": { 548 "routerEvent": { 549 "action": "router", 550 "abilityName": "EntryAbility", 551 "params": { 552 "info": "router info", 553 "message": "router message" 554 } 555 }, 556 "messageEvent": { 557 "action": "message", 558 "params": { 559 "detail": "message detail" 560 } 561 } 562 } 563 } 564 ``` 565 566 Note: 567 568 **JSON Value** in **data** supports multi-level nested data. When updating data, ensure that complete data is carried. 569 570 Assume that a widget is displaying the course information of Mr. Zhang on July 18, as shown in the following code snippet. 571 ```ts 572 "data": { 573 "Day": "07.18", 574 "teacher": { 575 "name": "Mr.Zhang", 576 "course": "Math" 577 } 578 } 579 ``` 580 To update the widget content to the course information of Mr. Li on July 18, you must pass the complete data as follows, instead of only a single date item such as **name** or **course**: 581 ```ts 582 "teacher": { 583 "name": "Mr.Li", 584 "course": "English" 585 } 586 ``` 587 588 589- Receive the router event in UIAbility and obtain parameters. 590 591 592 ```ts 593 import UIAbility from '@ohos.app.ability.UIAbility'; 594 import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 595 import Want from '@ohos.app.ability.Want'; 596 597 export default class EntryAbility extends UIAbility { 598 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 599 if (want.parameters) { 600 let params: Record<string, Object> = JSON.parse(JSON.stringify(want.parameters.params)); 601 // Obtain the info parameter passed in the router event. 602 if (params.info === "router info") { 603 // do something 604 // console.info("router info:" + params.info) 605 } 606 // Obtain the message parameter passed in the router event. 607 if (params.message === "router message") { 608 // do something 609 // console.info("router message:" + params.message) 610 } 611 } 612 } 613 }; 614 ``` 615 616- Receive the message event in FormExtensionAbility and obtain parameters. 617 618 619 ```ts 620 import FormExtension from '@ohos.app.form.FormExtensionAbility'; 621 622 export default class FormAbility extends FormExtension { 623 onFormEvent(formId: string, message: string) { 624 // Obtain the detail parameter passed in the message event. 625 let msg: Record<string, string> = JSON.parse(message) 626 if (msg.detail === "message detail") { 627 // do something 628 // console.info("message info:" + msg.detail) 629 } 630 } 631 }; 632 ``` 633