1# MissionCallback (System API)
2
3The MissionCallback module defines the callbacks invoked after synchronization starts. These callbacks can be used as input parameters in [registerMissionListener](js-apis-distributedMissionManager-sys.md#distributedmissionmanagerregistermissionlistener).
4
5> **NOTE**
6>
7> 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.
8> The APIs provided by this module are system APIs.
9
10## Modules to Import
11
12```ts
13import { distributedMissionManager } from '@kit.AbilityKit';
14```
15
16## MissionCallback.notifyMissionsChanged
17
18**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
19
20**System API**: This is a system API.
21
22**Parameters**
23
24| Name | Template | Mandatory | Description |
25| -------- | -------- | -------- | -------- |
26| deviceId |  string | Yes | Device ID in the callback that notifies a mission change.|
27
28**Example**
29```ts
30import { distributedMissionManager } from '@kit.AbilityKit';
31
32distributedMissionManager.registerMissionListener(
33  {
34    deviceId: '123456'
35  },
36  {
37    notifyMissionsChanged: (deviceId: string) => {
38      console.log(`notifyMissionsChanged deviceId: ${JSON.stringify(deviceId)}`);
39    },
40    notifySnapshot: (deviceId: string, mission: number) => {
41      console.log(`notifySnapshot deviceId: ${JSON.stringify(deviceId)}`);
42      console.log(`notifySnapshot mission: ${JSON.stringify(mission)}`);
43    },
44    notifyNetDisconnect: (deviceId: string, state: number) => {
45      console.log(`notifyNetDisconnect deviceId: ${JSON.stringify(deviceId)}`);
46      console.log(`notifyNetDisconnect state: ${JSON.stringify(state)}`);
47    }
48  }
49);
50```
51
52## MissionCallback.notifySnapshot
53
54**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
55
56**System API**: This is a system API.
57
58**Parameters**
59
60| Name | Template | Mandatory | Description |
61| -------- | -------- | -------- | -------- |
62| deviceId |  string | Yes | Device ID in the callback that notifies a snapshot change. |
63| mission |  number | Yes | Mission ID in the callback that notifies a snapshot change. |
64
65**Example**
66```ts
67import { distributedMissionManager } from '@kit.AbilityKit';
68
69distributedMissionManager.registerMissionListener(
70  {
71    deviceId: '123456'
72  },
73  {
74    notifyMissionsChanged: (deviceId: string) => {
75      console.log(`notifyMissionsChanged deviceId: ${JSON.stringify(deviceId)}`);
76    },
77    notifySnapshot: (deviceId: string, mission: number) => {
78      console.log(`notifySnapshot deviceId: ${JSON.stringify(deviceId)}`);
79      console.log(`notifySnapshot mission: ${JSON.stringify(mission)}`);
80    },
81    notifyNetDisconnect: (deviceId: string, state: number) => {
82      console.log(`notifyNetDisconnect deviceId: ${JSON.stringify(deviceId)}`);
83      console.log(`notifyNetDisconnect state: ${JSON.stringify(state)}`);
84    }
85  }
86);
87```
88
89## MissionCallback.notifyNetDisconnect
90
91**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
92
93**System API**: This is a system API.
94
95**Parameters**
96
97| Name | Template | Mandatory | Description |
98| -------- | -------- | -------- | -------- |
99| deviceId |  string | Yes | Device ID in the callback that notifies disconnection. |
100| state |  number | Yes | Network status in the callback that notifies disconnection. |
101
102**Example**
103```ts
104import { distributedMissionManager } from '@kit.AbilityKit';
105
106distributedMissionManager.registerMissionListener(
107  {
108    deviceId: '123456'
109  },
110  {
111    notifyMissionsChanged: (deviceId: string) => {
112      console.log(`notifyMissionsChanged deviceId: ${JSON.stringify(deviceId)}`);
113    },
114    notifySnapshot: (deviceId: string, mission: number) => {
115      console.log(`notifySnapshot deviceId: ${JSON.stringify(deviceId)}`);
116      console.log(`notifySnapshot mission: ${JSON.stringify(mission)}`);
117    },
118    notifyNetDisconnect: (deviceId: string, state: number) => {
119      console.log(`notifyNetDisconnect deviceId: ${JSON.stringify(deviceId)}`);
120      console.log(`notifyNetDisconnect state: ${JSON.stringify(state)}`);
121    }
122  }
123);
124```
125