Get unlimited public & private packages + team-based management with npm Teams.Learn more »

coffeekraken-remote-stack

1.0.5 • Public • Published

Coffeekraken Remote Stack

Provide a nice and simple way to handle remote connections from any devices (phones, tablets, etc...)

Table of content

  1. Install
  2. Get Started
  3. Client API
  4. Room API
  5. App API
  6. Server
  7. CLI
  8. Contribute
  9. Who are Coffeekraken?
  10. Licence

Install

npm install coffeekraken-remote-stack --save-dev

Get Started

This package expose multiple entry points to cover each parts of a remote client/app structure. Here's the list of entries that you will have access to:

  1. API
    1. Client : The client js api that helps you connect, announce and send instructions to the app
    2. App : The app js api that helps you to announce your app into a specific room and receive the clients instructions
    3. Room : The room js api that let you send data to the room app or clients
  2. Server : The nodejs that is responsible for:
    1. Connect the client and the app
    2. Expose some rooms to connect to
    3. Handle room's clients queue and picking strategy

Client API

Here's how to start with the client api:

import remoteStack from 'coffeekraken-remote-stack'
const myClient = new remoteStack.Client({
    username : 'John'
});
myClient.announce().then(() => {
    return myClient.join('cool-room');
}).then((room) => {
    // the client has joiend the room.
    // use now the passed "room" instance to send data to app, etc...
    room.sendToApp({
        someValue : 'Somehting...'
    });
});
// listen for some events
myClient.on('joined', (room) => {
    // do something here...
})
myClient.on('picked', (room) => {
    // do something here...
})

App API

Here's how to start with the app api:

import remoteStack from 'coffeekraken-remote-stack'
const myApp = new remoteStack.App({
    name : 'My cool app'
});
myApp.announce('cool-room').then(() => {
    // the app has been annouced in the "cool-room"
});
// listen for some events
myApp.on('client.joined', (client) => {
    // handle new client...
})
myApp.on('client.left', (client) => {
    // handle the left client...
})
myApp.on('client.data', (data, client) => {
    // client has sent the data...
})

Server

For the server, you will need a remote-stack-server.config.js file at the root of your project.

See the remote-stack-server.config.js file reference

module.exports = {
    // server port
    port : 3030,
 
    // debug
    debug : true,
 
    // max rooms that can be created (-1 = no limit)
    maxRooms : -1,
 
    // allow new rooms or not
    allowNewRooms : true,
 
    // allow of not to override some of the default room settings
    // when create one from the front app side
    allowSettingsOverride : ['sessionDuration'],
 
    // specify a room id pattern to follow (optional)
    newRoomIdPattern : null,
 
    // default room settings
    defaultNewRoomSettings : {
        maxClients : 10,
        pickedTimeout : 10000,
        sessionDuration : 10000,
        endSessionNotificationTimeout : 5000,
        averageSessionDuration : -1
    },
 
    // rooms
    rooms : [{
        id : 'cool-room',
        name : 'My cool room',
        simultaneous : 2,
        pickedTimeout : 10000,
        averageSessionDuration : 20000
    }],
 
    // ssl certificate
    // {
    //  key : path-to-key
    //  cert : path-to-cert
    //  passphrase : 'something'
    // }
    sslCertificate : false
}

Then, add a script into your package.json file like so:

{
    "scripts": {
        "server": "coffeekraken-remote-stack-server"
    }
}

And finaly, launch your server like so:

npm run server

CLI

This package expose a simple CLI that you can use to start the server.

coffeekraken-remote-stack-server [options]

Arguments

  • -p --port : The port on which the server will run. Default 3030
  • -c --config : A path to a config file to load. Default ./remote-stack-server.config.js

Contribute

This is an open source project and will ever be! You are more that welcomed to contribute to his development and make it more awesome every day. To do so, you have several possibilities:

  1. Share the love ❤️
  2. Declare issues
  3. Fix issues
  4. Add features
  5. Build web component

Who are Coffeekraken

We try to be some cool guys that build some cool tools to make our (and yours hopefully) every day life better.

More on who we are

License

The code is available under the MIT license. This mean that you can use, modify, or do whatever you want with it. This mean also that it is shipped to you for free, so don't be a hater and if you find some issues, etc... feel free to contribute instead of sharing your frustrations on social networks like an asshole...

Install

npm i coffeekraken-remote-stack

DownloadsWeekly Downloads

1

Version

1.0.5

License

MIT

Last publish

Collaborators

  • avatar