open-index/open-npm huggingface dataset:
npm package: @kylin-public/kylin-autosolve-client
Description: The client library of kylin autosolve
Author: Kylin Inc.
Latest version: 1.0.6

The client library of Kylin Autosolve
=

_by Kylin Inc._

This is a client library of Kylin Autosolve based on the WebSocket protocol.

Installation
==
```
npm install --save @kylin-public/kylin-autosolve-client
```

Usage
==

Initialize a client
===

```javascript
const { KylinAutosolveClient } = require('kylin-autosolve-client')
const client = new KylinAutosolveClient()
```

Connect to the autosolve service
===
```javascript
client.start('ACCESS_TOKEN', 'CLIENT_KEY')
```

Add a listener to receive result
===
```javascript
const TASK_RESULT = kylinAutoSolveProto.Notification.PayloadCase.TASK_RESULT

client.on('notification-' + TASK_RESULT, (evt) => {
  /** @type {proto.kylinautosolve.Notification} */
  const notification = evt.notification
  const taskResult = notification.getTaskResult()
  evt.handled++

  const response = taskResult.toObject()
  console.log('received task result:', response)

  callback(response)
})
```


Create a task to solve a challenge
===
```javascript
  const options = {
    siteKey: '6Lfv-q0ZAAAAADy0U9JUaCPCZI15U-7jhbAiYa0U',
    version: '3',
    action: 'login'
  }
  const createTaskMessage = client.makeCreateTaskMessage({
    challengeType: 'google',
    url: 'https://recaptcha-test.kylinbot.io/',
    timeout: options.timeout,
    options: JSON.stringify(options)
  })

  await client.whenReady()
  const createTaskResponse = await client.invoke(createTaskMessage)
  console.log('response:', createTaskResponse.toObject())
```

Poll the result of task
===
You don't have to poll the result usually, the autosolve server will notify client when it got the result from **Kylin One Click**, install a notification handler to receive result instead.
```javascript
await client.invoke(client.makeGetTaskResultMessage({
  taskId: createTaskResponse.getCreateTask().getTaskId()
}))
```

Cancel a request
===
```javascript
await client.invoke(client.makeCancelTaskMessage({
  taskId: createTaskResponse.getCreateTask().getTaskId()
}))
```

Cancel all requests
===
```javascript
await client.invoke(client.makeCancelTaskMessage({}))
```