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

    piesocket-js

    1.0.15 • Public • Published

    PieSocket JavaScript Client

    Setting up demo

    • Clone the repo git clone git@github.com:piesocket/piesocket-js.git
    • Run npm install
    • Run npm start
    • Open http://localhost:8080/examples/

    Now you can interactively test the SDK and find sample codes.

    Installation

    Yarn

    yarn add piesocket-js
    

    NPM

    npm i piesocket-js
    

    CDN

    <script src="https://unpkg.com/piesocket-js"></script>

    Importing

    Import module:

    const PieSocket = require('piesocket-js');

    With ES6:

    import PieSocket from 'piesocket-js';

    With CDN/Browser:

    Use the PieSocket global variable

    Usage

    1. Initialize the PieSocket class:
    var piesocket = new PieSocket({
        clusterId: 'YOUR_CLUSTER_ID',
        apiKey: 'YOUR_API_KEY'
    });

    Reference: Complete list of configuration options

    1. Subscribe to a channel:
    var channel = piesocket.subscribe(channelId); 
    1. Listen to message event:
    channel.on('message', function(msg){
        console.log(msg);
    });

    Following are the supported events:

    • open
    • message
    • error
    • close

    Listen to any event:

    channel.on(event, callbackFunction);

    Supported Methods

    List of available methods on the PieSocket object

    Method Description Returns
    subscribe(channelId) Subscribe to a channel Channel Object
    unsubscribe(channelId) Un-subscribe from a channel Boolean
    getConnections() Get list of all active connections/channels for this client Object

    Configuration

    Complete list of allowed configuration options

    Option Description Default
    apiKey Your PieSocket API key Demo key
    clusterId Your API key's cluster ID demo
    consoleLogs Logs useful connection info if set to true false
    notifySelf Receive messages sent by self true

    Documentation: PieSocket WebSocket docs

    Install

    npm i piesocket-js

    DownloadsWeekly Downloads

    35

    Version

    1.0.15

    License

    MIT

    Unpacked Size

    16.4 kB

    Total Files

    11

    Last publish

    Collaborators

    • avatar