Class: Session

Session(jt, id)

A session is a collection of apps and players.

Constructor

new Session(jt, id)

Create a Session.

CALLED FROM:

  • Session#load
  • Data#constructor
  • Data#createSession
Parameters:
Name Type Description
jt Object

Server object.

id type

The id of the new session.

Source:

Members

addingQueues

The queues being added, innermost last, see Session#addQueue.

Source:

allowAdminClientsToPlay

Whether or not admin windows can play.
Generally, during testing this can be test

Source:

allowNewParts

Whether or not clients can create a participant that does not exist yet.

Source:

apps :Array

The apps in this session.

Type:
  • Array
Source:

clients :Array

A list of the clients connected to this session.

Type:
  • Array
Source:

currency :string

The currency payments are in, e.g. 'EUR', for showing them.

Type:
  • string
Source:

exchangeRate :number

Money per point, for apps that do not set app.exchangeRate. Default from settings.json's
session.exchangeRate.

Type:
  • number
Source:

mode

Whose rules apply where the engines differ, for this session: 'jtree', 'ztree' or
'otree'; null for the server's (settings.mode). See Session#engineMode.

Source:

optionValues :Object

The option values of this app.

Type:
  • Object
Default Value:
  • {}
Source:

options :Array

The options of this app.

Type:
  • Array
Default Value:
  • []
Source:

outputHide :Array

A list of fields to hide from output.

Type:
  • Array
Source:

participants :Object

A list of participants in this session.

Type:
  • Object
Source:

showUpFee :number

Money every participant is paid for taking part (z-Tree's ShowUpFee, oTree's
participation_fee). Default from settings.json's session.showUpFee.

Type:
  • number
Source:

timeStarted :number

The time at which this session was last started.

Type:
  • number
Source:

Methods

addApp(appId)

Add the app with the given ID to this session.

FUNCTIONALITY:

  • load the given app Session#loadApp
  • add app to this session's apps field.
  • copy app source files Utils#copyFiles.
  • save app and its stages App#saveSelfAndChildren.
  • emit 'sessionAddApp' message.
Parameters:
Name Type Description
appId string

The ID of the app to add to this session.

Source:

addClient(socket, participantId)

Connect a web socket client to a participant of this session.

  • Listen for disconnect and goto-next-stage messages.
  • Load participant.
  • Socket listens to its own channel.

CALLED FROM

  • SocketServer#addParticipantClient
Parameters:
Name Type Description
socket Object

The web socket.

participantId string

The id of the participant.

Source:

addParticipants(num)

Adds a particular number of participants to this session.

Parameters:
Name Type Description
num number

The number of participants to add.

Source:

addQueue()

Add the apps of the queue at queuePath to this session, by running its script against this
session. A queue's options are session options, so they are set on this session first.
Called from Session#addApp.

Source:

advanceSlowest()

Move slowest participants to their next stage. See Participant#moveToNextStage.

Source:

allApps()

The session's apps, each followed by the apps within its stages (see App#runs).

Source:

appAt(address) → {App}

The app at address (see App#address): one of the session's apps, or an app within one
of their stages, made if it is not there yet (as when a session is loaded).

Parameters:
Name Type Description
address Array.<number>
Source:
Returns:
Type
App

appFollowing({@link)

Returns the App in the session app sequence that follows a reference App.

Parameters:
Name Type Description
{@link

App} app The reference app.

Source:
Returns:

App The app in the session app sequence that follows the reference app.

clientRemove(socket) → {type}

clientRemove - description

Parameters:
Name Type Description
socket type

description

Source:
Returns:

description

Type
type

copyAppFiles(app)

Copies the files of the apps added as stages of app (see App#addApp) to the session's
copy of app, where they are in relation to app's file, so that the copy loads them
(see App.load). Those outside the session's folder are not copied.

Parameters:
Name Type Description
app App
Source:

deleteApp(d)

this - description

Parameters:
Name Type Description
d type

description

Source:

emit(name, d)

Sends a message to all clients of this session.

Parameters:
Name Type Description
name string

The name of the message.

d Object

The data of the message.

Source:

engineMode()

Whose rules apply where z-Tree, oTree and jtree differ: the session's mode, else the server's.

Source:

getApp(participant)

Return the next app in the session for this participant, null if there are no more apps for this participant.

Parameters:
Name Type Description
participant Participant
Source:

messageCallback()

// * Process a message from the queue.
//

Source:

objectByRoomId()

The app, period, group or player of this session whose roomId() is id; or null.

Source:

outputFields() → {type}

this - description

Source:
Returns:

description

Type
type

participant(participantId) → {type}

participant - description

Parameters:
Name Type Description
participantId type

description

Source:
Returns:

description

Type
type

participantCreate(pId) → {type}

participantCreate - description

Parameters:
Name Type Description
pId type

description

Source:
Returns:

description

Type
type

participantEnd(participant) → {type}

Overwrite to add custom functionality.

Parameters:
Name Type Description
participant type

description

Source:
Returns:

description

Type
type

participantForLabel()

The participant with label (e.g. a room participant's, see Room#sendToSession): the one
with it already, or the first without one, which gets it; null if none is left.

Source:

participantMoveToNextApp(participant) → {type}

participantMoveToNextApp - description

CALLED FROM:

Parameters:
Name Type Description
participant type

description

Source:
Returns:

description

Type
type

payments()

What each participant is paid (see Participant#payment), by participant id.

Source:

(async) playWithBots()

Plays the session to its end with bots (admin v2's "Play with bots"): oTree apps by their
own bots (tests.py), and the generic bot where an app has none; z-Tree treatments by the
generic z-Tree bot. Starts the session if it is not. Tells admins how it goes
('sessionBots': {sId, state: 'running' | 'done' | 'failed', message}). Resolves once done.

Source:

playerRefresh(p) → {type}

Updates client with latest stage information.

Parameters:
Name Type Description
p type

description

Source:
Returns:

description

Type
type

pushMessage(obj, da, funcName)

Pushes a message to the end of the message queue.

Parameters:
Name Type Description
obj type

The client from whom the message was received.

da type

The data received from the client.

funcName string

The name of the function to evaluate on the client object.

Source:

removeParticipants(num)

Remove a particular number of participants from this session.

Parameters:
Name Type Description
num number

The number of participants to remove.

Source:

save() → {type}

this - description

Source:
Returns:

description

Type
type

sendParticipantPage(req, res)

Sends a page to a client (via the given HTTPResponse object).

Parameters:
Name Type Description
req HTTPRequest

description

res HTTPResponse

description

Source:

setMode()

Sets the session's mode ('jtree', 'ztree', 'otree'), or null for the server's.

Source:

setNumParticipants(num)

Sets the number of participants in this session.

Parameters:
Name Type Description
num number

The number of participants to have.

Source:

shell() → {type}

shell - description

Source:
Returns:

description

Type
type

shellWithChildren() → {type}

Creates a top-down shell of this Session. This includes all fields given by Session.outputFields, the participants, the apps and the clients.

CALLED FROM:

  • Msgs#openSession.
Source:
Returns:

The shell of this session.

Type
type

tryToEnd() → {type}

tryToEnd - description

CALLED FROM:

  • Participant.endSession()
Source:
Returns:

description

Type
type

(static) parseDataLine()

One line of a session's .gsf file (see Session#saveDataFS). Files written
by jtree 0.9.0 and earlier separate the type from the rest with the CSV delimiter (';' by default),
which is not JSON; read those too.

Source: