Wondering what’s next for npm?Check out our public roadmap! »

    @scrbbl/scribblelive-toolkit-core

    1.1.4 • Public • Published

    Scribblelive Toolkit Core

    This package allows developers to easily integrate with Scribblelive streams.

    Installation

    To install the package run npm i @scrbbl/scribblelive-toolkit-core

    If you would like a compiled ES5 version of the library, you can include the SLToolkit.js file located under ./lib folder in your web project

    Prerequisites

    • Scribblelive authentication token

    Load Stream Example

    This example assumes the use of npm and a module bundler such as webpack.

    const SLToolkit = require('@scrbbl/scribblelive-toolkit-core');
     
    const token = 'my-token';
    const streamId = 123456;
    const options = {};
     
    /* by default, we collect metrics to then display stats about how much your audience engaged with your content
       you can disable this tracking via the following
     
        options.tracking = false;
     
     // or keep it enabled but specify a custom source type  ex:
     
        options.tracking = { source: 'native-ios' };
     
     // to specify custom log level: 
     
        options.logging = { logLevel: 4 };
    */
     
     
     
    // initialize the core module
    const Core = new SLToolkit({token, options});
     
    // load stream content
    Core.Stream.load(streamId, (err, data) => {
      // load function takes a callback function
     
      if (err){
        // handle error
        return;
      }
     
      console.log('Loaded Stream: ', data);
    });
     
    // start polling
    Core.Stream.poll(streamId, (err, data) => {
      if (err){
        // handle error
        return;
      }
     
      console.log('Polling Stream: ', data);
    });
     
    // get 10th page
    Core.Stream.page(streamId, options.paging.pageSize, 10, (err, data) => {
      if (err){
        // handle error
        return;
      }
      
      console.log('Paging Stream: ', data);
    });
     
    // stops all polling
    setTimeout(function() {
      Core.Stream.killAllPolls();
    }, 20000);

    Loading Stream Example (non-npm)

    index.html

    <html>
      <head></head>
      <body>
        <!-- order is important, the core must be loaded first -->
        <script src="SLToolkit.js"></script> 
        <script src="my-app.js"></script> 
        </body>
    </html>

    my-app.js

    var token = 'my-token';
    var streamId = 123456;
    const options = {};
     
    // initialize the core module
    var Core = new SLToolkit({ token, options });
     
    // load stream content
    Core.Stream.load(streamId, function (err, data) {
      // load function takes a callback function
     
      if (err) {
        // handle error
        console.log(err);
        return;
      }
     
      console.log(data);
    });
     
    // start polling
    Core.Stream.poll(streamId, (err, data) => {
       if (err) {
           // handle error
            console.log(err);
            return;
        }
        // render data into DOM
        console.log(data);
    });
     
    // stops all polling
    setTimeout(function() {
        Core.Stream.killAllPolls();
    }, 10000);

    Stream Methods

    Promise load(int streamId, callback)

    Loads the first page of the specified stream ID. The callback function is invoked after the data has been loaded successfully. A promise is returned when load is invoked. The Promise can be used instead of the callback function.

    Promise page(int streamId, int pageSize, int pageNumber, callback)

    Loads the pageSize'th page of the pageSize for the specified stream ID. The callback function is invoked after the data has been loaded successfully. A promise is returned when load is invoked. The Promise can be used instead of the callback function.

    int poll(int streamId, callback)

    Polls the server for updates to the specified stream. If updates are present, the callback function will be invoked. The poll ID is returned when poll is called.

    boolean killPoll(int pollId)

    Terminates polling for the specified poll ID (returned from calling the poll function). If successful, the function will return true.

    boolean killAllPolls()

    Terminates all polls that have been initiated. The function will return a boolean to indicate if it was successful.

    Array getAllPolls()

    Returns a list of all the poll IDs that are currently registered in the Toolkit.

    Modules

    Modules are packages that can be added to a project and used through the Core. This allows for a single object to be created that will hold all functionality.

    To install a module you simply have to install it using npm within the project that the Core already resides: Example for the Likes Module: npm i @scrbbl/scribblelive-toolkit-likes

    Module Purpose
    Poll Post Types This module gives full functionality to the poll post types, allowing users to vote on options and have them automatically update independant of the Stream
    Collections This module allows for easy functionality with the collections-api through the Core
    Likes This module gives functinoality for liking posts using the Core

    Made with ❤️ at ScribbleLive

    Keywords

    none

    Install

    npm i @scrbbl/scribblelive-toolkit-core

    DownloadsWeekly Downloads

    535

    Version

    1.1.4

    License

    ISC

    Unpacked Size

    685 kB

    Total Files

    45

    Last publish

    Collaborators

    • avatar