BackgroundService🧪
为后台网页平台功能定义事件。
EN
Defines events for background web platform features.
✅️️ Methods
🔨BackgroundService.clearEvents
清除该服务的所有存储数据。
EN
Clears all stored data for the service.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| service | ✔️ | ServiceName |
🔨BackgroundService.setRecording
为服务设置录制状态。
EN
Set the recording state for the service.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| shouldRecord | ✔️ | boolean | |||
| service | ✔️ | ServiceName |
🔨BackgroundService.startObserving
启用服务的''事件更新''。
EN
Enables event updates for the service.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| service | ✔️ | ServiceName |
🔨BackgroundService.stopObserving
禁用该服务的事件更新。
EN
Disables event updates for the service.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| service | ✔️ | ServiceName |
✅️️ Events
👋BackgroundService.backgroundServiceEventReceived
启用后,将调用所有现有的backgroundServiceEvents,如果启用并处于录制状态,之后所有新事件也会被调用。
EN
Called with all existing backgroundServiceEvents when enabled, and all new events afterwards if enabled and recording.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| backgroundServiceEvent | ✔️ | BackgroundServiceEvent |
👋BackgroundService.recordingStateChanged
当服务的录制状态被更新时调用。
EN
Called when the recording state for the service has been updated.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| isRecording | ✔️ | boolean | |||
| service | ✔️ | ServiceName |
✅️️ Types
📌BackgroundService.BackgroundServiceEvent
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| timestamp | ✔️ | Network.TimeSinceEpoch | 事件的时间戳(以秒为单位)。 | ENTimestamp of the event (in seconds). | |
| origin | ✔️ | string | 该事件所属的源。 | ENThe origin this event belongs to. | |
| serviceWorkerRegistrationId | ✔️ | ServiceWorker.RegistrationID | 发起该事件的 Service Worker ID。 | ENThe Service Worker ID that initiated the event. | |
| service | ✔️ | ServiceName | 此事件所属的后台服务。 | ENThe Background Service this event belongs to. | |
| eventName | ✔️ | string | 事件的描述。 | ENA description of the event. | |
| instanceId | ✔️ | string | 一个标识符,用于将相关事件''和``分组在一起。 | ENAn identifier that groups related events together. | |
| eventMetadata | ✔️ | array[EventMetadata] | 事件特定信息的列表。 | ENA list of event-specific information. | |
| storageKey | ✔️ | string | 此事件所属的存 储密钥。 | ENStorage key this event belongs to. |
📌BackgroundService.EventMetadata
一个键值对,用于传递额外的''事件''信息。
EN
A key-value pair for additional event information to pass along.
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| key | ✔️ | string | |||
| value | ✔️ | string |
📌BackgroundService.ServiceName
该后台服务将与命令/事件相关联。每个后台服务独立运行,但它们共享相同的API。
允许值:backgroundFetch、backgroundSync、pushMessaging、notifications、paymentHandler、periodicBackgroundSync
EN
The Background Service that will be associated with the commands/events. Every Background Service operates independently, but they share the same API.
Allowed Values:
Allowed Values:
backgroundFetch, backgroundSync, pushMessaging, notifications, paymentHandler, periodicBackgroundSync返回类型:string