Skip to content
This repository was archived by the owner on Jan 12, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
engine-strict=true
engine-strict=true
@lickdltd:registry=https://npm.pkg.github.com
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
},
"devDependencies": {
"@dcl/eslint-config": "^1.0.1",
"decentraland-ecs": "latest"
"decentraland-ecs": "^6.11.11"
},
"engines": {
"node": ">=14.0.0",
"npm": ">=6.0.0",
"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"
]
}
54 changes: 12 additions & 42 deletions src/game.ts
Original file line number Diff line number Diff line change
@@ -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)
})
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down