Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

💪 Streaming RESource Loader

NotificationsYou must be signed in to change notification settings

regl-project/resl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

resl (RESource Loader) is a tiny streaming asset loader intended for use with WebGL applications.

Example

// Here we call resl and tell it to start preloading resourcesrequire('resl')({// A call to resl takes a JSON object as configuration.// The configuration object must contain a manifest field which specifies// a list of all resources to load and their types.manifest:{// Each entry in the manifest represents an asset to be loaded'scores':{type:'text',// the type declares the type of the assetsrc:'data/scores.csv'// and src declares the URL of the asset},// You can also specify HTML elements as assets'an_image':{type:'image',src:'images/some-image.png'},// Assets can also be streamed as well'some_video':{type:'video',stream:true,// setting the streaming flag specifies that// the done() callback will fire as soon as the// asset has started loadingsrc:'videos/some-video.mp4'},// You can also specify custom parsers for your assets'json_data':{type:'text',src:'mydata.json',parser:JSON.parse// Here we call JSON.parse as soon as the asset has// finished loading}},// Once the assets are done loading, then we can use them within our// applicationonDone:(assets)=>{console.log(assets.scores)document.body.appendChild(assets.some_video)document.body.appendChild(assets.an_image)console.log(assets.json_data)},// As assets are preloaded the progress callback gets firedonProgress:(progress,message)=>{document.body.innerHTML='<b>'+(progress*100)+'% loaded</b>: '+message},onError:(err)=>{console.error(err)}})

Install

The easiest way to installresl is to use npm:

npm install resl

API

require('resl')(config)

resl takes a single configuration object as input. At minimum this object must specify a callback which is executed once asset loading is finished and a manifest of assets which must be loaded. Theconfig object accepts the following properties:

Config parameterInterpretation
manifest(Required) An object listing each resource to be loaded.For more details see below
onDone(assets)(Required) A callback which is executed once all assets have loaded. This is passed a dictionary of all assets.
onProgress(progress, message)A callback which is executed each time more assets are loaded. Gets passed two arguments: progress so far as a fraction of the total bundle and a message related to the most recent progress event.
onError(error)A callback which is executed if any errors are encountered during preloading. Gets passed the last error which occurred.

Manifest Entries

Each entry in the manifest is an object specifying the location (URL) of an asset, its type and some optional data related to parsing the asset. User definedparsers can be added to assets to help streamline loading resources.

Manifest parameterInterpretationDefault
src(Required) The URL of the assetN/A
typeThetype of the asset.'text'
parserAn optionalparser (see below)null
streamIf set to true, then the resource is streamed.false
credentialsIf set to true, then pass credentials to cross origin requestsfalse

Resource types

The following resource types are currently supported byresl:

Resource typeInterpretation
'text'A UTF string loaded via XHR
'binary'Binary array buffer loaded via XHR
'image'AnHTML image element
'video'AnHTML video element
'audio'An HTML audio element

Parser interface

A manifest entry may take an optional parser object as input which transforms the base asset into some other data type. There are two ways to specify a parser inresl:

  1. As a functionparser(data) which takes as input the data and returns the encoded object.
  2. As an object which implements the following interface:
CallbackEffect
onData(data)(Required) A callback which is fired each time new data is available in the stream
onDone()A callback which is fired once the stream is finished loading

License

(c) 2016 Mikola Lysenko. MIT License

About

💪 Streaming RESource Loader

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp