Nefariously Pushing Master


    1.2.5 • Public • Published


    npm version npm downloads npm license

    dependencies Build Status GitKraken

    A simple Promise-based, non-blocking client for retrieving information from servers with NodeJS. Supports async/await, then/catch, and callbacks.

    Designed to work with sync 3.7+. The version used by cytube-client must match the version used by the sync server exactly.

    This package is tested against Node LTS and Latest (at time of release), but should be compatible with all Node versions > 6.0.


    npm install cytube-client


    yarn add cytube-client


    With Promises

    let cyClient;
    try {
        cyClient = await require('cytube-client').connect('channel');
    } catch(err) {
        // Handle client connection errors.
    await cyClient.getCurrentMedia();
    // ...
    cyClient.on('changeMedia', data => {
        // ...
    / ...

    With Callbacks

    var cytube = require('cytube-client');
    cytube.connect('channel', (err, client) => {
        if(err) {
            // Handle client connect errors.
        client.getCurrentMedia((err, data) => {
            if(err) {
                // Handle timeout or disconnect.
            else {
        client.on('changeMedia', (data) => {
        // Later ...

    Sync allows clients to join channels that do not already exist. The server will begin sending events if they are created, but will not prevent the connection.

    Please ensure your channel names are accurate if requests are timing out.

    Connection Options

    var options = {
        // This is REQUIRED. Sync will not acknowledge connections without a specified channel.
        channel: 'channel',
        // If the channel requires a password, it must be provided here.
        password: 'password',
        // If true, retrieves data over SSL from the socket server. Default true.
        secure: true,
        // If true, attempts to reconnect indefinitely if disconnected. Default true.
        reconnect: true,
        // If set, connects to the specified url instead of searching for a channel on
        socketServer: 'https://your.sync.server:3000',
        // Timeout for requests to the sync server in ms. Default 10000ms (10s).
        // Set to 0 to disable.
        timeout: 15000
    var cytube = require('cytube-client');
    cytube.connect(options).then(connection => {
        // ...

    Retrieving Channel Information

    Cytube-client provides some basic Promise-based functions for retrieving channel state information, since sync no longer has a built-in REST API.

    These functions can also be used with callbacks.

    client.getCurrentMedia();   // Resolves to a JSON representation of the currently playing media.
    client.getPlaylist();       // Resolves to a JSON array of queued media.
    client.getUserlist();       // Resolves to a JSON array of users connected to the channel.

    Event Listeners

    The client is exposed at client.socket and can be used to attach event listeners. See the documentation for more information.

    client.on('event', callback);   // Shorthand for client.socket.on
    client.once('event', callback); // Shorthand for client.socket.once'event');            // Shorthand for

    For a full list of emitted events, see the sync documentation. Basic events include:

    changeMedia     // Fired once when listener is attached and on subsequent media changes.
    queue           // Fired when a new media item is queued.
    chatMsg         // Fired on new chat message.
    addUser         // Fired on a user joining the channel
    userLeave       // Fired on a user leaving the channel.


    Contributions and pull requests are always welcome. Please be sure your code passes all existing tests and linting.

    Pull requests with full code coverage are strongly encouraged.

    An integration test is provided for testing connections to itself. Because channels are ephemeral by nature, this test is not run automatically as part of the normal npm test suite.

    To run the integration test, use CYTUBE_TEST_CHANNEL="your-channel-here" npm run testIntegration. You can also set* or DEBUG=engine,* to receive debug output from the websocket when running this test.




    npm i cytube-client

    DownloadsWeekly Downloads






    Unpacked Size

    17.1 kB

    Total Files


    Last publish


    • carriejv