1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-10 10:40:54 +00:00
psychojs/docs/module-core.ServerManager.html
2020-02-14 08:18:25 +01:00

2178 lines
28 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: ServerManager</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: ServerManager</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>
<span class="ancestors"><a href="module-core.html">core</a>.</span>ServerManager<span class="signature">(options)</span><span class="type-signature"></span></h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="ServerManager"><span class="type-signature"></span>new ServerManager<span class="signature">(options)</span><span class="type-signature"></span></h4>
<div class="description">
<p>This manager handles all communications between the experiment running in the participant's browser and the remote PsychoJS manager running on the <a href="http://pavlovia.org">pavlovia.org</a> server, <em>in an asynchronous manner</em>.</p>
<p>It is responsible for reading the configuration file of an experiment, for opening and closing a session, for listing and downloading resources, and for uploading results and log.</p>
<p>Note: The Server Manager uses <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promises</a> to deal with asynchronicity, is mostly called by <a href="PsychoJS.html">PsychoJS</a>, and is not exposed to the experiment code.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>psychoJS</code></td>
<td class="type">
<span class="param-type"><a href="module-core.PsychoJS.html">module:core.PsychoJS</a></span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">the PsychoJS instance</td>
</tr>
<tr>
<td class="name"><code>autoLog</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
false
</td>
<td class="description last">whether or not to log</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line20">line 20</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Extends</h3>
<ul>
<li>PsychObject</li>
</ul>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="Event"><span class="type-signature">(readonly) </span>Event<span class="type-signature"> :Symbol</span></h4>
<div class="description">
Server event
<p>A server event is emitted by the manager to inform its listeners of either a change of status, or of a resource related event (e.g. download started, download is completed).</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Symbol</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line685">line 685</a>
</li></ul></dd>
</dl>
<h4 class="name" id="SaveFormat"><span class="type-signature">(readonly) </span>SaveFormat<span class="type-signature"> :Symbol</span></h4>
<div class="description">
Experiment result format
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Symbol</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="data_ExperimentHandler.js.html">data/ExperimentHandler.js</a>, <a href="data_ExperimentHandler.js.html#line371">line 371</a>
</li></ul></dd>
</dl>
<h4 class="name" id="Status"><span class="type-signature">(readonly) </span>Status<span class="type-signature"> :Symbol</span></h4>
<div class="description">
Server status
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Symbol</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line724">line 724</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_downloadRegisteredResources"><span class="type-signature">(private) </span>_downloadRegisteredResources<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Download the resources previously registered.
<p>Note: we use the <a href="https://www.createjs.com/preloadjs">preloadjs library</a>.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line550">line 550</a>
</li></ul></dd>
</dl>
<h4 class="name" id="_listResources"><span class="type-signature">(private) </span>_listResources<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
List the resources available to the experiment.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line483">line 483</a>
</li></ul></dd>
</dl>
<h4 class="name" id="closeSession"><span class="type-signature"></span>closeSession<span class="signature">(isCompleted<span class="signature-attributes">opt</span>, sync<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="ServerManager.html#.CloseSessionPromise">ServerManager.CloseSessionPromise</a>>|void}</span></h4>
<div class="description">
Close the session for this experiment on the remote PsychoJS manager.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>isCompleted</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
false
</td>
<td class="description last">whether or not the experiment was completed</td>
</tr>
<tr>
<td class="name"><code>sync</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
false
</td>
<td class="description last">whether or not to communicate with the server in a synchronous manner</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line171">line 171</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
the response
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.&lt;<a href="ServerManager.html#.CloseSessionPromise">ServerManager.CloseSessionPromise</a>></span>
|
<span class="param-type">void</span>
</dd>
</dl>
<h4 class="name" id="downloadResources"><span class="type-signature"></span>downloadResources<span class="signature">(resources<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Asynchronously download resources for the experiment and register them with the server manager.
<ul>
<li>For an experiment running locally: the root directory for the specified resources is that of index.html
unless they are prepended with a protocol, such as http:// or https://.</li>
<li>For an experiment running on the server: if no resources are specified, all files in the resources directory
of the experiment are downloaded, otherwise we only download the specified resources. All resources are assumed
local to index.html unless they are prepended with a protocol.</li>
</ul>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>resources</code></td>
<td class="type">
<span class="param-type">Array.&lt;{name: string, path: string}></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
[]
</td>
<td class="description last">the list of resources</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line294">line 294</a>
</li></ul></dd>
</dl>
<h4 class="name" id="getConfiguration"><span class="type-signature"></span>getConfiguration<span class="signature">(configURL)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="ServerManager.html#.GetConfigurationPromise">ServerManager.GetConfigurationPromise</a>>}</span></h4>
<div class="description">
Read the configuration file for the experiment.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>configURL</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">the URL of the configuration file</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line59">line 59</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
the response
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.&lt;<a href="ServerManager.html#.GetConfigurationPromise">ServerManager.GetConfigurationPromise</a>></span>
</dd>
</dl>
<h4 class="name" id="getResource"><span class="type-signature"></span>getResource<span class="signature">(name)</span><span class="type-signature"> &rarr; {Object}</span></h4>
<div class="description">
Get the value of a resource.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">of the requested resource</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line231">line 231</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
exception if no resource with that name has previously been registered
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Object.&lt;string, *></span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
value of the resource
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="openSession"><span class="type-signature"></span>openSession<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="ServerManager.html#.OpenSessionPromise">ServerManager.OpenSessionPromise</a>>}</span></h4>
<div class="description">
Open a session for this experiment on the remote PsychoJS manager.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line99">line 99</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
the response
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.&lt;<a href="ServerManager.html#.OpenSessionPromise">ServerManager.OpenSessionPromise</a>></span>
</dd>
</dl>
<h4 class="name" id="resetStatus"><span class="type-signature"></span>resetStatus<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="ServerManager.Status.html#.READY">ServerManager.Status.READY</a>}</span></h4>
<div class="description">
Reset the resource manager status to ServerManager.Status.READY.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line281">line 281</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
the new status
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="ServerManager.Status.html#.READY">ServerManager.Status.READY</a></span>
</dd>
</dl>
<h4 class="name" id="setStatus"><span class="type-signature"></span>setStatus<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
Set the resource manager status.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line253">line 253</a>
</li></ul></dd>
</dl>
<h4 class="name" id="uploadData"><span class="type-signature"></span>uploadData<span class="signature">(key, value)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="ServerManager.html#.UploadDataPromise">ServerManager.UploadDataPromise</a>>}</span></h4>
<div class="description">
Asynchronously upload experiment data to the remote PsychoJS manager.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>key</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">the data key (e.g. the name of .csv file)</td>
</tr>
<tr>
<td class="name"><code>value</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">the data value (e.g. a string containing the .csv header and records)</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line365">line 365</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
the response
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.&lt;<a href="ServerManager.html#.UploadDataPromise">ServerManager.UploadDataPromise</a>></span>
</dd>
</dl>
<h4 class="name" id="uploadLog"><span class="type-signature"></span>uploadLog<span class="signature">(logs, compressed<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="ServerManager.html#.UploadDataPromise">ServerManager.UploadDataPromise</a>>}</span></h4>
<div class="description">
Asynchronously upload experiment logs to the remote PsychoJS manager.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>logs</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">the base64 encoded, compressed, formatted logs</td>
</tr>
<tr>
<td class="name"><code>compressed</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
false
</td>
<td class="description last">whether or not the logs are compressed</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="core_ServerManager.js.html">core/ServerManager.js</a>, <a href="core_ServerManager.js.html#line421">line 421</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
the response
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.&lt;<a href="ServerManager.html#.UploadDataPromise">ServerManager.UploadDataPromise</a>></span>
</dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-core.html">core</a></li><li><a href="module-data.html">data</a></li><li><a href="module-sound.html">sound</a></li><li><a href="module-util.html">util</a></li><li><a href="module-visual.html">visual</a></li></ul><h3>Classes</h3><ul><li><a href="module-core.BuilderKeyResponse.html">BuilderKeyResponse</a></li><li><a href="module-core.EventManager.html">EventManager</a></li><li><a href="module-core.GUI.html">GUI</a></li><li><a href="module-core.Keyboard.html">Keyboard</a></li><li><a href="module-core.KeyPress.html">KeyPress</a></li><li><a href="module-core.Logger.html">Logger</a></li><li><a href="module-core.MinimalStim.html">MinimalStim</a></li><li><a href="module-core.Mouse.html">Mouse</a></li><li><a href="module-core.PsychoJS.html">PsychoJS</a></li><li><a href="module-core.ServerManager.html">ServerManager</a></li><li><a href="module-core.Window.html">Window</a></li><li><a href="module-data.ExperimentHandler.html">ExperimentHandler</a></li><li><a href="module-data.TrialHandler.html">TrialHandler</a></li><li><a href="module-sound.Sound.html">Sound</a></li><li><a href="module-sound.TonePlayer.html">TonePlayer</a></li><li><a href="module-sound.TrackPlayer.html">TrackPlayer</a></li><li><a href="module-util.Clock.html">Clock</a></li><li><a href="module-util.Color.html">Color</a></li><li><a href="module-util.CountdownTimer.html">CountdownTimer</a></li><li><a href="module-util.EventEmitter.html">EventEmitter</a></li><li><a href="module-util.MixinBuilder.html">MixinBuilder</a></li><li><a href="module-util.MonotonicClock.html">MonotonicClock</a></li><li><a href="module-util.PsychObject.html">PsychObject</a></li><li><a href="module-util.Scheduler.html">Scheduler</a></li><li><a href="module-visual.ImageStim.html">ImageStim</a></li><li><a href="module-visual.MovieStim.html">MovieStim</a></li><li><a href="module-visual.Polygon.html">Polygon</a></li><li><a href="module-visual.Rect.html">Rect</a></li><li><a href="module-visual.ShapeStim.html">ShapeStim</a></li><li><a href="module-visual.Slider.html">Slider</a></li><li><a href="module-visual.TextStim.html">TextStim</a></li><li><a href="module-visual.VisualStim.html">VisualStim</a></li></ul><h3>Interfaces</h3><ul><li><a href="module-sound.SoundPlayer.html">SoundPlayer</a></li></ul><h3>Mixins</h3><ul><li><a href="module-core.WindowMixin.html">WindowMixin</a></li><li><a href="module-util.ColorMixin.html">ColorMixin</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Fri Feb 14 2020 08:15:34 GMT+0100 (Central European Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>