@bbc/storyplayer

1.0.11 • Public • Published

StoryPlayer

StoryPlayer is R&D's Object-based Media Player. It is designed to read stories that are expressed using our object-based media schema and render the experience within an HTML <div> element, responding to audience interactions as and when.

Installing the library

To install the library npm install @bbc/storyplayer --save

Using the library

You'll notice the term "romper" appears frequently in the code, rather than StoryPlayer. This is historical - the player was initially called Romper, an acronym for R&D Object based Media PlayER. The name was changed to better fit with the naming conventions of the StoryKit suite of tools, but romper remains in many places in the code.

storyplayer.js exports an init() function that is used to initiate StoryPlayer and returns an instance of StoryPlayer. It takes one argument, defining the Player settings, which has the following attributes:

  • target - An HTML element for the player to live in.
  • fetchers - functions that take a UUID and return an Object describing an instance of the data model for the given experience.
  • mediaFetcher - A function that takes a URI for some media and returns a URL that can be given, for example, as a src attribute for a <video> element
  • staticImageBaseUrl - The location of some static assets used by the player (specifically image assets to used if not defined in the story)
  • analyticsLogger (optional, defaults to logging on the browser console) - A function that processes analytics data Objects; see docs/analytics.md. For example, the function might save the information into a database
  • dataResolver (optional, defaults to creating one) - contains get and set functions to get and set the values of the variables that determine the flow of logic of the story (see the built-in DataResolver). This can be used to hook the player into an external data store
  • privacyNotice (optional, defaults to null) - A string rendered alongside the start button and start image designed to present a privacy warning to users
  • saveSession (optional, defaults to false) - A boolean to say whether or not the player should save state and offer to resume when restarted
  • handleKeys (optional, defaults to true) - A boolean to say whether keyboard events should be handled by the player

For example, in a React application import the player:

import Storyplayer, { VARIABLE_EVENTS,  REASONER_EVENTS } from '@bbc/storyplayer';

Initiate it using an Object with the attributes described above:

    const playerSettingsObject = {
        // an Object including the above attributes
    }
    this.storyplayer = Storyplayer.init(playerSettingsObject);

The returned instance will fire events that can be listened for and handled. For example:

    // whenever a variable is changed
    this.storyplayer.on(VARIABLE_EVENTS.VARIABLE_CHANGED, this.handleVariableChange);

    // whenever the user changes to a new Narrative Element
    this.storyplayer.on(REASONER_EVENTS.NARRATIVE_ELEMENT_CHANGED,
        this.handleNarrativeElementChange);

    // whenever the Controller calculates what elements can come next
    this.storyplayer.on(REASONER_EVENTS.NEXT_ELEMENTS, this.handleUpcomingChange);

    // the story has started
    this.storyplayer.on(REASONER_EVENTS.ROMPER_STORY_STARTED, this.handleStoryStart);

    // the story has ended
    this.storyplayer.on(REASONER_EVENTS.STORY_END, this.handleStoryEnd)

The demo index page here shows how this might work in a static HTML context, with simple fetchers all reading from the same single pre-loaded JSON file for the story.

Building the library from the repo

We use Yarn for dependency management and building.
We have an ESLint file based on airbnb-base, with our own tweaks.
We have used Flow for type checking, but this is not consistent throughout the code base.

  • First, clone the repo and cd into the new directory.
  • Run yarn to pull down and build all the dependencies, and the library.
  • yarn build will do a single build of the library
  • yarn test will do a single run of the tests (ESLint, jest and sass-lint)
  • yarn dev will continuously build and test the library on changes

Running the examples in the repo

To check everything is installed correctly, run python3 -m http.server in the root of the project, and visit http://localhost:8000/examples. Select a demo using the left hand tab. Use the middle tabs to inspect the demo's JSON representation. Use the right hand tab to play the selected story.

Running StoryPlayer against local stories and media

  • Run python3 -m http.server in the root of the project.

  • The media can be placed in the /examples/ folder. It can be put directly in, or organised into subfolders.

  • The story json can be placed in the /examples/ folder. The json must conform with the schema; there are stories in the examples folder there can provide some guidance or be edited manually for testing and exploration. The Asset Collection source values can use a relative path to the local folder containing the media. For example, if you are editing my_story.json in the /examples/ folder, and wish to use the video /examples/my_project/my_nice_vid.mp4, then the asset collection should have:

    "assets": {
        "av_src": "./my_project/my_nice_vid.mp4"
    }
  • Stories can be played by visiting localhost:8000/examples/ (the server prefix may vary depending on your local web server - this should work if you have used python, as above); there you will see a list of the example stories provided in the repository. Select a story in the "Select story" tab then visit the "Render" tab to play.

  • Other stories can be viewed by providing the filename in the URL, e.g., localhost:8000/examples/index.html?storyjson=my_story.json.

StoryPlayer Implementation details

Information regarding the implementation of StoryPlayer is detailed here, and includes:

StoryPlayer Analytics

StoryPlayer features a highly granular analytics solution that can be used to record user behaviour. For full details, head here.

How to contribute

Please read our CONTRIBUTING.md and our CODE_OF_CONDUCT.md if you are interested in making contributions.

Licence

StoryPlayer is available to everyone under the terms of the GNU General Public Licence v3.0. Take a look at the licence file and COPYING in the repo for further details.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.115latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.115
1.0.101
1.0.92
1.0.81
1.0.71
1.0.51
1.0.41
1.0.31
1.0.21
1.0.11
1.0.01
0.21.01
0.20.131
0.20.121
0.20.111
0.20.101
0.20.91
0.20.71
0.20.61
0.20.41
0.20.31
0.20.21
0.20.11
0.20.01
0.19.61
0.19.51
0.19.41
0.19.31
0.19.21
0.19.11
0.19.01
0.18.301
0.18.291
0.18.281
0.18.271
0.18.261
0.18.251
0.18.241
0.18.231
0.18.221
0.18.211
0.18.201
0.18.191
0.18.181
0.18.171
0.18.161
0.18.151
0.18.141
0.18.131
0.18.121
0.18.111
0.18.101
0.18.91
0.18.81
0.18.71
0.18.61
0.18.51
0.18.41
0.18.31
0.18.21
0.18.11
0.18.01
0.17.151
0.17.141
0.17.131
0.17.121
0.17.111
0.17.101
0.17.91
0.17.81
0.17.71
0.17.51
0.17.41
0.17.31
0.17.21
0.17.11
0.17.01
0.16.91
0.16.81
0.16.71
0.16.61
0.16.51
0.16.41
0.16.31
0.16.21
0.16.11
0.16.01
0.15.01
0.14.131
0.14.121
0.14.111
0.14.101
0.14.91
0.14.81
0.14.71
0.14.51
0.14.31
0.14.11
0.14.01
0.12.401
0.12.381
0.12.361
0.12.351
0.12.341
0.12.331
0.12.321
0.12.311
0.12.301
0.12.291
0.12.281
0.12.271
0.12.261
0.12.251
0.12.241
0.12.231
0.12.221
0.12.211
0.12.201
0.12.191
0.12.181
0.12.171
0.12.161
0.12.151
0.12.141
0.12.131
0.12.121
0.12.111
0.12.101
0.12.91
0.12.81
0.12.71
0.12.61
0.12.51
0.12.41
0.12.31
0.12.21
0.12.11
0.12.01
0.11.491
0.11.471
0.11.461
0.11.451
0.11.441
0.11.431
0.11.411
0.11.391
0.11.371
0.11.361
0.11.351
0.11.341
0.11.331
0.11.321
0.11.311
0.11.291
0.11.281
0.11.271
0.11.261
0.11.251
0.11.241
0.11.231
0.11.221
0.11.211
0.11.201
0.11.191
0.11.181
0.11.171
0.11.161
0.11.151
0.11.141
0.11.131
0.11.121
0.11.111
0.11.101
0.11.91
0.11.81
0.11.71
0.11.61
0.11.51
0.11.41
0.11.31
0.11.21
0.11.11
0.11.01
0.10.171
0.10.161
0.10.151
0.10.141
0.10.131
0.10.121
0.10.111
0.10.101
0.10.91
0.10.81
0.10.71
0.10.61
0.10.51
0.10.41
0.10.31
0.10.21
0.10.11
0.10.01
0.9.301
0.9.281
0.9.271
0.9.251
0.9.241
0.9.231
0.9.221
0.9.211
0.9.201
0.9.191
0.9.181
0.9.171
0.9.161
0.9.151
0.9.141
0.9.131
0.9.121
0.9.111
0.9.101
0.9.91
0.9.81
0.9.71
0.9.61
0.9.51
0.9.41
0.9.31
0.9.21
0.9.11
0.9.01
0.8.91
0.8.81
0.8.71
0.8.61
0.8.51
0.8.41
0.8.31
0.8.21
0.8.11
0.8.01
0.7.11
0.7.01
0.6.121
0.6.111
0.6.101
0.6.91
0.6.81
0.6.71
0.6.61
0.6.51
0.6.41
0.6.31
0.6.21
0.6.11
0.6.01
0.5.61
0.5.51
0.5.41
0.5.31
0.5.21
0.5.11
0.5.01
0.4.311
0.4.301
0.4.291
0.4.281
0.4.271
0.4.261
0.4.251
0.4.241
0.4.231
0.4.221
0.4.211
0.4.201
0.4.191
0.4.181
0.4.171
0.4.161
0.4.151
0.4.141
0.4.131
0.4.121
0.4.111
0.4.101
0.4.91
0.4.81
0.4.71
0.4.61
0.4.51
0.4.41
0.4.31
0.4.21
0.4.11
0.4.01
0.3.721
0.3.711
0.3.701
0.3.691
0.3.681
0.3.671
0.3.661
0.3.651
0.3.641
0.3.631
0.3.621
0.3.611
0.3.601
0.3.591
0.3.581
0.3.571
0.3.561
0.3.551
0.3.541
0.3.531
0.3.521
0.3.511
0.3.501
0.3.491
0.3.481
0.3.471
0.3.461
0.3.441
0.3.431
0.3.421
0.3.411
0.3.401
0.3.391
0.3.381
0.3.371
0.3.361
0.3.351
0.3.341
0.3.331
0.3.321
0.3.311
0.3.301
0.3.291
0.3.281
0.3.271
0.3.261
0.3.251
0.3.241
0.3.231
0.3.221
0.3.211
0.3.201
0.3.191
0.3.171
0.3.161
0.3.141
0.3.121
0.3.111
0.3.91
0.3.81
0.3.72
0.3.61
0.3.51
0.3.41
0.3.31
0.3.11
0.3.01
0.2.701
0.2.691
0.2.681
0.2.671
0.2.661
0.2.651
0.2.641
0.2.631
0.2.621
0.2.611
0.2.601
0.2.591
0.2.581
0.2.571
0.2.561
0.2.551
0.2.541
0.2.531
0.2.521
0.2.511
0.2.501
0.2.491
0.2.481
0.2.471
0.2.461
0.2.452
0.2.441
0.2.431
0.2.421
0.2.411
0.2.401
0.2.391
0.2.381

Package Sidebar

Install

npm i @bbc/storyplayer

Weekly Downloads

401

Version

1.0.11

License

GPL-3.0-only

Unpacked Size

7.26 MB

Total Files

37

Last publish

Collaborators

  • mathieuloutre
  • craigjwright
  • dannymeloy
  • chrisn-bbc
  • bbcrd
  • cisnky
  • lawrencep_bbcrd
  • kamara.bennett
  • kevin.mackay
  • thomaspreecebbc