Module: server/token

server/token

Collects some helper functions for generating random tokens that can be used for identifying sessions. You can configure the kind of token your session should use with the SessionOptions.

If you would like to use your own token function you can add it to this module before initializing the rest of the framework:
Source:

Example

// load module and add your function
var tokenModule = require('./multi/server/token');
tokenModule.myToken = function (prefix) {
  return prefix + Math.floor(Math.random() * 100);
};

// work with multi
var multi = multiModule.init(server);
multi.on('sessionCreated', onSessionCreated);


// on client side do this:
var sessionOptions = {
  token: {
    func: 'myToken',       // name of your function
    args: [ 'mySession' ]  // arguments for your function
  }
};
multi.createSession(sessionOptions);

Methods

<static> numeric(minLength, maxLength, digitCount, doubleDigits) → {string}

Generates a random string containing only numeric digits.
Parameters:
Name Type Argument Default Description
minLength integer <optional>
3 minimal number of digits
maxLength integer <optional>
3 maximal number of digits
digitCount integer <optional>
10 number of digits that should be used for generating the number. By default all 10 digits are used.
doubleDigits boolean <optional>
true when false, every digit of the random number will be unique inside the number
Source:
Returns:
random integer
Type
string

<static> staticToken(value) → {string}

Simply returns the given token string. Useful only when only one session with a known token should exist, p.e. when running multi as a terminal application.
Parameters:
Name Type Description
value string the token you want to be returned
Source:
Returns:
the token you passed in
Type
string

<static> symbolPattern(minSymbols, maxSymbols, symbolCount) → {string}

Generates a random numeric string which can be used for authentication via symbol pattern field (each symbol one digit, only unique digits).
Parameters:
Name Type Argument Default Description
minSymbols integer <optional>
1 minimal number of selected symbols
maxSymbols integer <optional>
4 maximal number of selected symbols
symbolCount integer <optional>
9 number of digits that should be used for generating the number. By default all 9 digits are used for using it with a 3x3 symbol field.
Source:
Returns:
random numeric string
Type
string

<inner> randomInt(min, max) → {integer}

Parameters:
Name Type Description
min integer smallest allowed number (inclusive)
max integer biggest allowed number (inclusive)
Source:
Returns:
number between min and max (inclusive).
Type
integer