diff --git a/.github/settings.yml b/.github/settings.yml index 7188767..46ea225 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -30,7 +30,7 @@ branches: required_status_checks: strict: true contexts: - - lint-and-build + - test-build / Lint & build enforce_admins: false required_linear_history: true restrictions: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b371d86..94cc361 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,17 +6,25 @@ on: jobs: lint-and-build: + name: Lint & build runs-on: ubuntu-latest + permissions: + contents: read + packages: read steps: - uses: actions/checkout@v2 - name: Use Node.js 16.x uses: actions/setup-node@v1 with: node-version: 16.x + registry-url: https://npm.pkg.github.com + scope: '@lickdltd' - name: install decentraland run: npm i -g decentraland@latest - name: install dependencies run: npm i + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: lint run: npm run lint - name: build diff --git a/.npmrc b/.npmrc index 4fd0219..c866519 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ -engine-strict=true \ No newline at end of file +engine-strict=true +@lickdltd:registry=https://npm.pkg.github.com diff --git a/package.json b/package.json index 2eb4c86..bc9befc 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@dcl/eslint-config": "^1.0.1", - "decentraland-ecs": "latest" + "decentraland-ecs": "^6.11.11" }, "engines": { "node": ">=14.0.0", @@ -22,9 +22,11 @@ "yarn": "please use npm" }, "dependencies": { - "@dcl/ecs-scene-utils": "^1.7.5" + "@dcl/ecs-scene-utils": "^1.7.5", + "@lickdltd/chorus-dcl": "^0.2.0" }, "bundleDependencies": [ - "@dcl/ecs-scene-utils" + "@dcl/ecs-scene-utils", + "@lickdltd/chorus-dcl" ] } diff --git a/src/game.ts b/src/game.ts index 1d524c5..a498818 100644 --- a/src/game.ts +++ b/src/game.ts @@ -1,54 +1,24 @@ import { getUserData } from '@decentraland/Identity' -import { signedFetch } from '@decentraland/SignedFetch' -import * as utils from '@dcl/ecs-scene-utils' - -const stationURL = 'https://chorus.lickd.co' -const stream = '/lickd/test.mp3' +import * as chorus from '@lickdltd/chorus-dcl' void executeTask(async () => { + const chorusEntity = new Entity() + const chorusPlayer = new chorus.Player(chorusEntity, '/lickd/test.mp3') const me = await getUserData() + await chorusPlayer.start() + onEnterSceneObservable.add(async (player) => { if (player.userId === me?.userId) { - await radioStart() + await chorusPlayer.start() } }) -}) - -async function radioStart() { - try { - const response = await signedFetch(stationURL + '/api/session/create/dcl', { - headers: { 'Content-Type': 'application/json' }, - method: 'POST', - body: JSON.stringify({ stream }) - }) - - if (response.text) { - const json = await JSON.parse(response.text) - if (json.token) { - const streamSource = new Entity() - const audioStream = new AudioStream(stationURL + stream + '?token=' + json.token) - - streamSource.addComponent(audioStream) - streamSource.addComponent(new utils.Interval(60000, async () => await heartbeat(json.token))) - - engine.addEntity(streamSource) - } + onLeaveSceneObservable.add(async (player) => { + if (player.userId === me?.userId) { + await chorusPlayer.stop() } - } catch (e) { - log(e) - } -} + }) -async function heartbeat(token: string) { - try { - await signedFetch(stationURL + '/api/session/heartbeat/dcl', { - headers: { 'Content-Type': 'application/json' }, - method: 'POST', - body: JSON.stringify({ stream, token }) - }) - } catch (e) { - log(e) - } -} + engine.addEntity(chorusEntity) +}) diff --git a/tsconfig.json b/tsconfig.json index a38f9cf..6d9e25b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,12 +3,15 @@ "outFile": "./bin/game.js", "allowJs": true, "strict": true, + "baseUrl": ".", "paths": { + "@lickdltd/chorus-dcl": [ + "node_modules/@lickdltd/chorus-dcl/dist/index.d.ts" + ], "@dcl/ecs-scene-utils": [ "node_modules/@dcl/ecs-scene-utils/dist/index.d.ts" ] - }, - "baseUrl": "." + } }, "include": [ "src/**/*.ts"