GithubHelp home page GithubHelp logo

muzikie / streamer-archived Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 0.0 421 KB

๐ŸŽ™ Audio streamer API application

Home Page: https://muzikie.com

License: Apache License 2.0

JavaScript 100.00%
api blockchain javascript lisk music muzikie nodejs

streamer-archived's People

Contributors

haghighatcs avatar reyraa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

streamer-archived's Issues

Add collection discovery endpoints

We need to add the following endpoints to retrieve collections stored.

  • Collection
    • /:id - GET - Get a single collection.
    • /:id - DELETE - Remove/delete a single collection.
    • /:id - PATCH - Update a single collection.
    • / - GET - Get an all collections.
    • / - POST - Create a single collection.

Stream songs by ID

We should be able to stream songs using their ID.
Before starting the stream, we should validate the user subscription as explained in #3 . We should also validate the API call as explained in #2 .
We won't implement the stream transaction validation as explained in #5 , this feature is postponed to v0.2.0.

Implement discovery endpoints

Streamer should enable the player applications to access indexed data of the blockchain. Meaning, it should expose expose endpoints to store values and returned the list of entities. We'll replace this functionality with Lisk Service once it's stable enough.
Therefore the following endpoints are required:

  • Collection
    • getAll
      • Method: GET
      • Params: limit, offset.
      • Description: List of all collections in the system including the details of their Audios.
    • getByAddress
      • Method: GET
      • Params: address, limit, offset.
      • Description: List of all collections of a given account including the details of their Audios.
  • Subscription
    • getTypes
      • Method: GET
      • Params: none.
      • Description: List of all subscriptions types and 10 available IDs for each type

Event manager should handle none-NFT relevant transactions

The event manager must be able to update the NFT values according to the new transactions in the blockchain. At the moment it fails when encountered with unsupported transactions.
Since we're going to adapt Lisk Service, this could be a temporary solution.

Add Collection detail to audio

Each audio should include collection details to display in client. At the moment we only return collection ID. We should add an object that includes collection details.
The response of the audio endpoints should include the corresponding collection information. And the response of the collections endpoints, should include the list of audios as audio objects.

Here is a sample response of the audios endpoints:

{
  "status": "success",
  "data": [
    {
      "genre": [
        22
      ],
      "createdAt": "2023-01-24T00:11:31.796Z",
      "_id": "63cf23365a766d197410519c",
      "name": "La Bella",
      "releaseYear": 2023,
      "fit": [],
      "collectionID": "477569746172697374614d7220536d697468",
      "collection": {
        // "audios": [], // Remember, this should not be returned
        "createdAt": "2023-01-23T23:30:25.201Z",
        "_id": "63cf1bcb6b4ee3104c53b1c3",
        "name": "Guitarista",
        "releaseYear": 2022,
        "collectionType": 1,
        "coverSignature": "0775fac6aab1aa04047e48dda43953238dd8fb97ccd9cdda63517d0a145abfa6a5306bf22157d4e9189222d82162fbf5cbf72e06f615a276bf1ceee4efe44505",
        "coverHash": "9b93181a4ee02d618c1e1861fa2acfad",
        "creatorAddress": "lskhqy429nwm2tew3j5j29ef6pguyynf6jxcmgrh2",
        "collectionID": "477569746172697374614d7220536d697468",
        "__v": 0
      },
      "audioSignature": "84ad10615c485b4eeac51761e9040f2e867cd47be98758b121ec12cc3e70521c7060e3f83ad8e638935e8ff2fc67342f038872f1f37fa98473f6dd477b3c8604",
      "audioHash": "431d7f2536d7d3fa5cc6507227a444b5",
      "creatorAddress": "lskhqy429nwm2tew3j5j29ef6pguyynf6jxcmgrh2",
      "audioID": "4c612042656c6c614d7220536d697468",
      "__v": 0
    }
  ]
}

Sample response of the collections endpoint:

{
  "status": "success",
  "data": [
    {
      "audios": [{
        "genre": [
          22
        ],
        "createdAt": "2023-01-24T00:11:31.796Z",
        "_id": "63cf23365a766d197410519c",
        "name": "La Bella",
        "releaseYear": 2023,
        "fit": [],
        "audioSignature": "84ad10615c485b4eeac51761e9040f2e867cd47be98758b121ec12cc3e70521c7060e3f83ad8e638935e8ff2fc67342f038872f1f37fa98473f6dd477b3c8604",
        "audioHash": "431d7f2536d7d3fa5cc6507227a444b5",
        "creatorAddress": "lskhqy429nwm2tew3j5j29ef6pguyynf6jxcmgrh2",
        "audioID": "4c612042656c6c614d7220536d697468",
        "__v": 0
      }],
      "createdAt": "2023-01-23T23:30:25.201Z",
      "_id": "63cf1bcb6b4ee3104c53b1c3",
      "name": "Guitarista",
      "releaseYear": 2022,
      "collectionType": 1,
      "coverSignature": "0775fac6aab1aa04047e48dda43953238dd8fb97ccd9cdda63517d0a145abfa6a5306bf22157d4e9189222d82162fbf5cbf72e06f615a276bf1ceee4efe44505",
      "coverHash": "9b93181a4ee02d618c1e1861fa2acfad",
      "creatorAddress": "lskhqy429nwm2tew3j5j29ef6pguyynf6jxcmgrh2",
      "collectionID": "477569746172697374614d7220536d697468",
      "__v": 0
    }
  ]
}

Create collections schema (albums)

Collections (or albums) are entities that store related audio files information and metadata.
This allows fast music discovery and search, statistics, etc.
Creating a schema for the collection here in streamer app allows us to quickly handle player app requests and then refer to blockchain app for transactions.
Collection schema is more likely to the collection type defined in blockchain project.
main fields are as below:
name
release Year
artist Name
co-artists
collection Type
audios
hash
meta
creator Address

Adapt data schemas according to the changes in blockchain

Based on the discussion in the blockchain project, we should adapt the streamer to the new data schema.
This means, we should

  • Remove the artist name from collection and audio
  • Remove coArtist from colleciotn
  • Add fit to audio
    Additionally we should incorporate reference data for ease of use in the client.

Get entities by blockchain ID instead of streamer ID

We should use a unique ID across projects and since blockchain should be the reference, we should use audioID and collectionID from blockchain to retrieve information of a single collection or audio via Streamer.

Index successful transactions of the chain

In order to achieve the following goals we need to index the successful transactions of the chain:

The goal is to subscribe to the relevant events from the chain, receive new transactions and determine their success / failure status.

For more context, we can subscribe to chain_newBlock event. And receive the transactions data using chain_getTransactionsByHeight endpoint. We'll also need to hit the chain_getEvents endpoint. We can use these vents to determine the status of each transaction.

This ticket doesn't aim to process the transactions. It only returns the list of successfully executed transactions.

Read address from cookies

Due to restrictions in the client app, we should change stream endpoint to read the address from cookies instead of headers.

Implement subscription validation

Users must have a valid subscription to stream a song. Any user with a valid subscription should be able to start streaming. They should be able to continue to stream content, and later submit the corresponding stream tx.

Validate Stream transaction presence

when a user start to listen to a song, streamer must send a transaction on blockchain within 40 seconds. otherwise it will stop stream to the user and show an appropriate message to inform user about the error.

Add validation for stream request

At the moment we do not validate the stream request parameters. We should ensure

  • The song exists
  • The ID is valid
  • The user public key is valid
  • The user has a valid subscription

Tickets

Implement meta info endpoint

Streamer should expose an endpoint to return meta information including:/

  • Storage path and extension of audio files
  • Storage path and extension of collection covers

The audio/stream endpoint works inconsistently

The appears that the repurposes of the stream endpoint is fragile and due to a miscommunication between Streamer and Web Player, the play buttons doesn't work from time to time./
We should review the stream endpoint and ensure that the Player is able to stream audios at all times.

Use Lisk32 address to retrieve data

Muzikie Blockchain endpoints return address in stringified buffer. Although we should use addresses in Lisk32 format in client. Since this is the recommended format.
Therefore we should store and retrieve account addresses in Lisk32 format in Streamer.
At the moment the blockchain endpoint convert buffer to string as

address.toString('hex')

The correct approach is

cryptography.address.getLisk32AddressFromAddress(Buffer.from(address, 'hex'))

Validate audioID and user publicKey

As a schema check,

  • audioID should be a hex string with length 64.
  • User publicKey should be a hex string with length 64.

If these criteria are not met, the API should return the following errors:

  • If the key is not one of the above:
{
  "error": true,
  "message": `Unknown input parameter(s): ${parameterName}`
}
  • If the value doesn't match the above criteria:
{
  "error": true,
  "message": `Specified key `${value} does not exist`
}

Add audio duration

We should store and return the duration of audio to be used by the client apps. The data should be returned as duration in seconds.

Do not expose unused endpoints

Only the following endpoints are used by the client as should refrain from exposing endpoints that not used:

  • Audio
    • get
    • getAll
    • stream
  • collection
    • get
    • getAll
  • profile
    • get
    • getAll
  • transaction
    • create

Create a model for Audio

We want to store the entities created on the blockchain in a dedicated indexed DB so we can retrieve lists of Audios and Collections as per client request. Said endpoints serve the purpose of returning rich set of information to the client applications and play a role of middleman between our player apps and the blockchain.

Add encryption strategy to streams

Streamer can easily be abused for pirating content, in particular copyrighted music.
a very basic, yet quite effective method is to encrypt the sensitive assets.
we can encrypt the mp3 contents server-side using some key, send it to the client, and let the client's js code decrypt and play it.
the client can still download the encrypted mp3 file, but without the proper decryption algorithm it's a useless file.

Update entities according to the succeeded transactions on the chain

Rationale
We should rely on the blockchain for updating entities. This helps in many ways:

  • The client should make less API calls, hence lower chance of failure.
  • There is only one source of validation, which is the blockchain.
  • The data is alway in sync with blockchain and there's less chance of failure and running out of sync.
  • The client doesn't have to wait for the transaction to go through before the process is marked successful.

Entities
We need a new entity called Transaction. This entity holds:

  • TransactionID
  • Files
  • module
  • command

The transaction entity should be created before the actual transaction is broadcasted to blockchain. This way we can make sure the indexer receives it on time.

Extend test base

We have created a basic test suit.To ensure maximum productivity, we should extend to the test suit and create a test guideline.

Store audio file and collection cover image

Audio and Collection NFT tokens include audio and images files respectively. We should upload the files and store them to be served per request.
Before storing the files, we should validate the hashes to ensure the genuine file was uploaded. We should also make sure the NFT is unique.

Improve README file

The README file must include

  • Prerequisites
  • Development scripts and their usages
  • Production scripts and their usages
  • Configurations files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.