# HeadlessTaskManager - `@amazon-devices/headless-task-manager`


## Use HeadlessTaskManager in your app

1. Update the following files in your app

__package.json__
```
    "dependencies": {
    "@amazon-devices/headless-task-manager": "^1.0.0",
    ...
```

2. Import HeadlessTaskManager to your app


```javascript
    import { HeadlessEntryPointRegistry } from "@amazon-devices/headless-task-manager"
```

3. Usage Example of __registerHeadlessEntryPoint__ :

```javascript
  // define entry point function
  function entryPointFunction(): Promise<void> {
    // TODO: Add task logic
    // if returns Promise.reject(), the task will be failed.
    // if returns Promise.resolve(), the task will be succeeded.
    return Promise.resolve();
  }

  // register task
  HeadlessEntryPointRegistry.registerHeadlessEntryPoint("entryPointKey", () => entryPointFunction);
```

4. Usage Example of __registerHeadlessEntryPoint2__ :

```javascript
  // define entry point function
  function entryPointFunction(param : IComponentInstance): Promise<void> {
    // TODO: Add task logic
    // if returns Promise.reject(), the task will be failed.
    // if returns Promise.resolve(), the task will be succeeded.
    return Promise.resolve();
  }

  // definition of ComponentType enum
  enum ComponentType {
    INTERACTIVE,
    SERVICE,
    TASK,
  }

  // definition of IComponentInstance interface
  interface IComponentInstance {
    name : string,
    type : ComponentType,
    id : string //This property is currently being initialized with a "NULL" string literal. This will be updated in the future.
  }

  // register task
  HeadlessEntryPointRegistry.registerHeadlessEntryPoint2("entryPointKey", () => entryPointFunction);
```

**NOTE:** If a user attempts to register the same task name multiple times through any API, only the first registration will be successful. Any subsequent attempts to register the same task name will fail.

**NOTE:** Current supported versions of react-native-kepler dependency are:
- 0.72