1# MissionCallback (System API) 2<!--Kit: Ability Kit--> 3<!--Subsystem: Ability--> 4<!--Owner: @hobbycao--> 5<!--Designer: @gsxiaowen--> 6<!--Tester: @hanjiawei--> 7<!--Adviser: @huipeizi--> 8 9The module defines the callbacks invoked after synchronization starts. These callbacks can be used as input parameters in [registerMissionListener](js-apis-distributedMissionManager-sys.md#distributedmissionmanagerregistermissionlistener). 10 11> **NOTE** 12> 13> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 14> The APIs provided by this module are system APIs. 15 16## Modules to Import 17 18```ts 19import { distributedMissionManager } from '@kit.AbilityKit'; 20``` 21 22## MissionCallback.notifyMissionsChanged 23 24notifyMissionsChanged(deviceId: string): void 25 26Called to notify that the list of missions has changed. 27 28**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 29 30**System API**: This is a system API. 31 32**Parameters** 33 34| Name| Template| Mandatory| Description| 35| -------- | -------- | -------- | -------- | 36| deviceId | string | Yes| Device ID in the callback that notifies a mission change.| 37 38**Example** 39 40```ts 41import { distributedMissionManager } from '@kit.AbilityKit'; 42 43distributedMissionManager.registerMissionListener( 44 { 45 deviceId: '123456' 46 }, 47 { 48 notifyMissionsChanged: (deviceId: string) => { 49 console.log(`notifyMissionsChanged deviceId: ${JSON.stringify(deviceId)}`); 50 }, 51 notifySnapshot: (deviceId: string, mission: number) => { 52 console.log(`notifySnapshot deviceId: ${JSON.stringify(deviceId)}`); 53 console.log(`notifySnapshot mission: ${JSON.stringify(mission)}`); 54 }, 55 notifyNetDisconnect: (deviceId: string, state: number) => { 56 console.log(`notifyNetDisconnect deviceId: ${JSON.stringify(deviceId)}`); 57 console.log(`notifyNetDisconnect state: ${JSON.stringify(state)}`); 58 } 59 } 60); 61``` 62 63## MissionCallback.notifySnapshot 64 65notifySnapshot(deviceId: string, mission: number): void 66 67Called to notify that the snapshot has changed. 68 69**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 70 71**System API**: This is a system API. 72 73**Parameters** 74 75| Name| Template| Mandatory| Description| 76| -------- | -------- | -------- | -------- | 77| deviceId | string | Yes| Device ID in the callback that notifies a snapshot change.| 78| mission | number | Yes| Mission ID in the callback that notifies a snapshot change.| 79 80**Example** 81```ts 82import { distributedMissionManager } from '@kit.AbilityKit'; 83 84distributedMissionManager.registerMissionListener( 85 { 86 deviceId: '123456' 87 }, 88 { 89 notifyMissionsChanged: (deviceId: string) => { 90 console.log(`notifyMissionsChanged deviceId: ${JSON.stringify(deviceId)}`); 91 }, 92 notifySnapshot: (deviceId: string, mission: number) => { 93 console.log(`notifySnapshot deviceId: ${JSON.stringify(deviceId)}`); 94 console.log(`notifySnapshot mission: ${JSON.stringify(mission)}`); 95 }, 96 notifyNetDisconnect: (deviceId: string, state: number) => { 97 console.log(`notifyNetDisconnect deviceId: ${JSON.stringify(deviceId)}`); 98 console.log(`notifyNetDisconnect state: ${JSON.stringify(state)}`); 99 } 100 } 101); 102``` 103 104## MissionCallback.notifyNetDisconnect 105 106notifyNetDisconnect(deviceId: string, state: number): void 107 108Called to notify that the network connection is interrupted. 109 110**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 111 112**System API**: This is a system API. 113 114**Parameters** 115 116| Name| Template| Mandatory| Description| 117| -------- | -------- | -------- | -------- | 118| deviceId | string | Yes| Device ID in the callback that notifies disconnection.| 119| state | number | Yes| Network status in the callback that notifies disconnection. The fixed value **0** is returned, indicating network disconnection.| 120 121**Example** 122 123```ts 124import { distributedMissionManager } from '@kit.AbilityKit'; 125 126distributedMissionManager.registerMissionListener( 127 { 128 deviceId: '123456' 129 }, 130 { 131 notifyMissionsChanged: (deviceId: string) => { 132 console.log(`notifyMissionsChanged deviceId: ${JSON.stringify(deviceId)}`); 133 }, 134 notifySnapshot: (deviceId: string, mission: number) => { 135 console.log(`notifySnapshot deviceId: ${JSON.stringify(deviceId)}`); 136 console.log(`notifySnapshot mission: ${JSON.stringify(mission)}`); 137 }, 138 notifyNetDisconnect: (deviceId: string, state: number) => { 139 console.log(`notifyNetDisconnect deviceId: ${JSON.stringify(deviceId)}`); 140 console.log(`notifyNetDisconnect state: ${JSON.stringify(state)}`); 141 } 142 } 143); 144``` 145