0.1.0-20230606201310.commit-c67acc9 • Published 3 years ago

@dcl/quests-client v0.1.0-20230606201310.commit-c67acc9

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

Quests Client for SDK7 is a RPC Client which interacts with the Quests Server to track quests states and send events to make progress.

Setup

Start by installing NPM dependecies:

$ npm install

The project uses the Quests Service proto definition to generate the code required to compile, so before start the development, make sure you run:

$ make build

Usage

This library is intended to be used in a Decentraland Scene and uses SDK7 features like user authentication to initialize the client.

Install

Add dependency to your project

$ npm add @dcl/quests-client

Example

Create the Quests Client inside the executeTask and if the wallet based authentication is OK you will be ready to use the client to subscribe to updates or send new events that may make progress on a quest.

For this example we registered two observables to make use of the client from any other part of your code: questEventsObservable and questStartObservable

executeTask(async () => {
  // retrieve websocket url from env
  const ws = 'wss://quests-rpc.decentraland.zone'

  // create quests client
  try {
    const client = await createQuestsClient(ws)

    questEventsObservable.on('message', async (action) => {
      await client.sendEvent({ action })
    })

    questStartObservable.on('questId', async (questId) => {
      await client.startQuest({ questId })
    })

    client.onStarted((quest) => {
      // update your state here or react to the quest started event
    })

    client.onUpdate((quest) => {
      // update your state here or react to the quest updates
    })

    // retrieve all quest instances and their state
    const instances = client.getInstances()
    ...
  } catch (e) {
    console.log(`[Your Scene] connection to ${ws} failed! ${e}`)
  }
})

Scene Example: Quests Tracking

In this repository you may find a scene that makes use of all the Quests Client features.