1.0.11 • Published 3 years ago

@bbc/storyplayer v1.0.11

Weekly downloads
528
License
GPL-3.0-only
Repository
github
Last release
3 years ago

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.

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.21.0

3 years ago

0.20.13

3 years ago

0.20.12

3 years ago

0.20.11

3 years ago

0.20.10

3 years ago

0.20.9

3 years ago

0.20.7

3 years ago

0.20.6

3 years ago

0.20.4

3 years ago

0.20.3

3 years ago

0.20.2

3 years ago

0.20.1

3 years ago

0.20.0

3 years ago

0.19.6

3 years ago

0.19.5

3 years ago

0.19.4

3 years ago

0.19.3

3 years ago

0.19.2

3 years ago

0.19.1

3 years ago

0.19.0

3 years ago

0.18.30

3 years ago

0.18.29

3 years ago

0.18.28

3 years ago

0.18.27

3 years ago

0.18.26

4 years ago

0.18.25

4 years ago

0.18.24

4 years ago

0.18.23

4 years ago

0.18.22

4 years ago

0.18.21

4 years ago

0.18.20

4 years ago

0.18.19

4 years ago

0.18.18

4 years ago

0.18.17

4 years ago

0.18.16

4 years ago

0.18.15

4 years ago

0.18.14

4 years ago

0.18.13

4 years ago

0.18.12

4 years ago

0.18.11

4 years ago

0.18.10

4 years ago

0.18.9

4 years ago

0.18.8

4 years ago

0.18.7

4 years ago

0.18.6

4 years ago

0.18.5

4 years ago

0.18.4

4 years ago

0.18.3

4 years ago

0.18.2

4 years ago

0.18.1

4 years ago

0.18.0

4 years ago

0.17.15

4 years ago

0.17.14

4 years ago

0.17.13

4 years ago

0.17.12

4 years ago

0.17.11

4 years ago

0.17.10

4 years ago

0.17.9

4 years ago

0.17.8

4 years ago

0.17.7

4 years ago

0.17.5

4 years ago

0.17.4

4 years ago

0.17.3

4 years ago

0.17.2

4 years ago

0.17.1

4 years ago

0.17.0

4 years ago

0.16.9

4 years ago

0.16.8

4 years ago

0.16.7

4 years ago

0.16.6

4 years ago

0.16.5

4 years ago

0.16.4

4 years ago

0.16.3

4 years ago

0.16.2

4 years ago

0.16.1

4 years ago

0.16.0

4 years ago

0.15.0

4 years ago

0.14.13

4 years ago

0.14.12

4 years ago

0.14.11

4 years ago

0.14.10

4 years ago

0.14.9

4 years ago

0.14.8

4 years ago

0.14.7

4 years ago

0.14.5

4 years ago

0.14.3

4 years ago

0.14.1

4 years ago

0.14.0

4 years ago

0.12.40

4 years ago

0.12.38

4 years ago

0.12.36

4 years ago

0.12.35

4 years ago

0.12.34

4 years ago

0.12.33

4 years ago

0.12.32

4 years ago

0.12.31

4 years ago

0.12.30

4 years ago

0.12.29

4 years ago

0.12.28

4 years ago

0.12.27

4 years ago

0.12.26

4 years ago

0.12.25

4 years ago

0.12.24

4 years ago

0.12.23

4 years ago

0.12.22

4 years ago

0.12.21

4 years ago

0.12.20

4 years ago

0.12.19

4 years ago

0.12.18

4 years ago

0.12.17

4 years ago

0.12.16

4 years ago

0.12.15

4 years ago

0.12.14

4 years ago

0.12.13

4 years ago

0.12.12

4 years ago

0.12.11

4 years ago

0.12.10

4 years ago

0.12.9

4 years ago

0.12.8

4 years ago

0.12.7

4 years ago

0.12.6

4 years ago

0.12.5

4 years ago

0.12.4

4 years ago

0.12.3

4 years ago

0.12.2

4 years ago

0.12.1

4 years ago

0.12.0

4 years ago

0.11.49

4 years ago

0.11.47

4 years ago

0.11.46

4 years ago

0.11.45

4 years ago

0.11.44

4 years ago

0.11.43

4 years ago

0.11.41

4 years ago

0.11.39

4 years ago

0.11.37

4 years ago

0.11.36

4 years ago

0.11.35

4 years ago

0.11.34

4 years ago

0.11.33

4 years ago

0.11.32

4 years ago

0.11.31

4 years ago

0.11.29

4 years ago

0.11.28

4 years ago

0.11.27

4 years ago

0.11.26

4 years ago

0.11.25

4 years ago

0.11.24

4 years ago

0.11.23

4 years ago

0.11.22

4 years ago

0.11.21

4 years ago

0.11.20

4 years ago

0.11.19

4 years ago

0.11.18

4 years ago

0.11.17

4 years ago

0.11.16

4 years ago

0.11.15

4 years ago

0.11.14

4 years ago

0.11.13

4 years ago

0.11.12

4 years ago

0.11.11

4 years ago

0.11.10

4 years ago

0.11.9

4 years ago

0.11.8

4 years ago

0.11.7

4 years ago

0.11.6

4 years ago

0.11.5

4 years ago

0.11.4

4 years ago

0.11.3

4 years ago

0.11.2

4 years ago

0.11.1

4 years ago

0.11.0

4 years ago

0.10.17

4 years ago

0.10.16

4 years ago

0.10.15

4 years ago

0.10.14

4 years ago

0.10.13

4 years ago

0.10.12

4 years ago

0.10.11

4 years ago

0.10.10

4 years ago

0.10.9

4 years ago

0.10.8

4 years ago

0.10.7

4 years ago

0.10.6

4 years ago

0.10.5

4 years ago

0.10.4

4 years ago

0.10.3

4 years ago

0.10.2

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.30

4 years ago

0.9.28

4 years ago

0.9.27

4 years ago

0.9.25

4 years ago

0.9.24

4 years ago

0.9.23

4 years ago

0.9.22

4 years ago

0.9.21

4 years ago

0.9.20

4 years ago

0.9.19

4 years ago

0.9.18

4 years ago

0.9.17

4 years ago

0.9.16

4 years ago

0.9.15

4 years ago

0.9.14

4 years ago

0.9.13

5 years ago

0.9.12

5 years ago

0.9.11

5 years ago

0.9.10

5 years ago

0.9.9

5 years ago

0.9.8

5 years ago

0.9.7

5 years ago

0.9.6

5 years ago

0.9.5

5 years ago

0.9.4

5 years ago

0.9.3

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.9

5 years ago

0.8.8

5 years ago

0.8.7

5 years ago

0.8.6

5 years ago

0.8.5

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.12

5 years ago

0.6.11

5 years ago

0.6.10

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.31

5 years ago

0.4.30

5 years ago

0.4.29

5 years ago

0.4.28

5 years ago

0.4.27

5 years ago

0.4.26

5 years ago

0.4.25

5 years ago

0.4.24

5 years ago

0.4.23

5 years ago

0.4.22

5 years ago

0.4.21

5 years ago

0.4.20

5 years ago

0.4.19

5 years ago

0.4.18

5 years ago

0.4.17

5 years ago

0.4.16

5 years ago

0.4.15

5 years ago

0.4.14

5 years ago

0.4.13

5 years ago

0.4.12

5 years ago

0.4.11

5 years ago

0.4.10

5 years ago

0.4.9

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.72

5 years ago

0.3.71

5 years ago

0.3.70

5 years ago

0.3.69

5 years ago

0.3.68

5 years ago

0.3.67

5 years ago

0.3.66

5 years ago

0.3.65

5 years ago

0.3.64

5 years ago

0.3.63

5 years ago

0.3.62

5 years ago

0.3.61

5 years ago

0.3.60

5 years ago

0.3.59

5 years ago

0.3.58

5 years ago

0.3.57

5 years ago

0.3.56

5 years ago

0.3.55

5 years ago

0.3.54

5 years ago

0.3.53

5 years ago

0.3.52

5 years ago

0.3.51

5 years ago

0.3.50

5 years ago

0.3.49

5 years ago

0.3.48

5 years ago

0.3.47

5 years ago

0.3.46

5 years ago

0.3.44

5 years ago

0.3.43

5 years ago

0.3.42

5 years ago

0.3.41

5 years ago

0.3.40

5 years ago

0.3.39

5 years ago

0.3.38

5 years ago

0.3.37

5 years ago

0.3.36

5 years ago

0.3.35

5 years ago

0.3.34

5 years ago

0.3.33

5 years ago

0.3.32

5 years ago

0.3.31

5 years ago

0.3.30

5 years ago

0.3.29

5 years ago

0.3.28

5 years ago

0.3.27

5 years ago

0.3.26

5 years ago

0.3.25

5 years ago

0.3.24

5 years ago

0.3.23

5 years ago

0.3.22

5 years ago

0.3.21

5 years ago

0.3.20

5 years ago

0.3.19

5 years ago

0.3.17

5 years ago

0.3.16

5 years ago

0.3.14

5 years ago

0.3.12

5 years ago

0.3.11

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.70

5 years ago

0.2.69

5 years ago

0.2.68

5 years ago

0.2.67

5 years ago

0.2.66

5 years ago

0.2.65

5 years ago

0.2.64

5 years ago

0.2.63

5 years ago

0.2.62

5 years ago

0.2.61

5 years ago

0.2.60

5 years ago

0.2.59

5 years ago

0.2.58

5 years ago

0.2.57

5 years ago

0.2.56

5 years ago

0.2.55

5 years ago

0.2.54

5 years ago

0.2.53

5 years ago

0.2.52

5 years ago

0.2.51

5 years ago

0.2.50

5 years ago

0.2.49

5 years ago

0.2.48

5 years ago

0.2.47

5 years ago

0.2.46

5 years ago

0.2.45

5 years ago

0.2.44

5 years ago

0.2.43

5 years ago

0.2.42

5 years ago

0.2.41

5 years ago

0.2.40

5 years ago

0.2.39

5 years ago

0.2.38

5 years ago