Assigning roles\u2026
"}},data:{role:{type:a.ParameterType.STRING},role_map:{type:a.ParameterType.OBJECT},assigned_self:{type:a.ParameterType.BOOL},timed_out:{type:a.ParameterType.BOOL},group:{type:a.ParameterType.OBJECT}},citations:{apa:"Tsukamoto, H. (n.d.). jsPsychMultiplayerRole (0.0.1). ",bibtex:"@misc{TsukamotojsPsychMultiplayerRole, author = {Tsukamoto, Hannah}, title = {jsPsychMultiplayerRole}, } "}};class f{constructor(e){this.jsPsych=e}trial(e,t,i){var p,o,n,l,s,u,d;const y=$(this.jsPsych),m=y.participantId;if(m==null)throw new Error("plugin-multiplayer-role: no participantId \u2014 the multiplayer adapter must be connected (await jsPsych.multiplayer.connect(adapter)) before this trial runs.");if(typeof t.strategy=="function"&&t.ready==null)throw new Error("plugin-multiplayer-role: a custom `strategy` function requires an explicit `ready` predicate (the readiness gate cannot be derived from an opaque strategy).");t.group_size==null&&t.ready==null&&console.warn("plugin-multiplayer-role: no `group_size` and no custom `ready` \u2014 readiness can resolve as soon as this client has pushed, assigning over a partial group. Set `group_size` (the exact count) or supply a `ready` predicate unless an upstream barrier guarantees all peers have already pushed into this session.");const b=(p=y.get(m))!=null?p:{},ee=A(P({},b),{joinedAt:(o=b.joinedAt)!=null?o:Date.now(),rounds:A(P({},(n=b.rounds)!=null?n:{}),{[t.round]:t.push_data})});e.innerHTML=t.message,i==null||i();const re=G({groupSize:t.group_size,strategy:t.strategy,rankBy:(l=t.rank_by)!=null?l:void 0,roleFrom:(s=t.role_from)!=null?s:void 0,ready:(u=t.ready)!=null?u:void 0,round:t.round,seed:(d=t.seed)!=null?d:void 0});return y.push(ee).then(()=>{var c;return y.wait(re,(c=t.timeout)!=null?c:void 0)}).then(c=>{var E,I,N,B,S;const w=O(c,{roles:t.roles,strategy:t.strategy,seed:(E=t.seed)!=null?E:void 0,round:t.round,balanced:t.balanced,rankBy:(I=t.rank_by)!=null?I:void 0,roleFrom:(N=t.role_from)!=null?N:void 0,overflowRole:(B=t.overflow_role)!=null?B:void 0}),v=w[m];M(v,w),this.jsPsych.finishTrial(P({role:(S=v==null?void 0:v.role)!=null?S:null,role_map:w,assigned_self:v!=null,timed_out:!1},t.save_group?{group:c}:{}))},c=>{if(!L(c))throw c;return this.handleTimeout(t)})}handleTimeout(e){M(void 0);try{e.on_timeout&&e.on_timeout(this.jsPsych)}catch(t){console.error("plugin-multiplayer-role: on_timeout hook threw",t)}this.jsPsych.finishTrial({role:null,role_map:null,assigned_self:!1,timed_out:!0})}}return f.info=Z,f.assignRoles=O,f.getMyRole=H,f.getMyAssignment=q,f.getRoleMap=D,f.participantsByRole=Y,f}(jsPsychModule); +//# sourceMappingURL=index.browser.min.js.map diff --git a/vendor/plugin-multiplayer-sync.js b/vendor/plugin-multiplayer-sync.js new file mode 100644 index 0000000..604f7ca --- /dev/null +++ b/vendor/plugin-multiplayer-sync.js @@ -0,0 +1,2 @@ +var jsPsychMultiplayerSync=function(r){"use strict";var f="0.1.0";const d="MultiplayerTimeoutError";function T(n){return n instanceof Error&&n.name===d}function P(n){var i;const e=n,u=(i=e.multiplayer)!=null?i:e.pluginAPI;if(!u||typeof u.getAll!="function")throw new Error("No multiplayer API found on the jsPsych instance. This plugin needs jsPsych core with multiplayer support (jsPsych#3694); see https://multiplayer.jspsych.org.");return u}var c=(n,i,e)=>new Promise((u,l)=>{var p=a=>{try{o(e.next(a))}catch(s){l(s)}},y=a=>{try{o(e.throw(a))}catch(s){l(s)}},o=a=>a.done?u(a.value):Promise.resolve(a.value).then(p,y);o((e=e.apply(n,i)).next())});const w={name:"multiplayer-sync",version:f,parameters:{wait_for:{type:r.ParameterType.FUNCTION,default:void 0},push_data:{type:r.ParameterType.OBJECT,default:null},message:{type:r.ParameterType.HTML_STRING,default:"Waiting for other players\u2026
"},timeout:{type:r.ParameterType.INT,default:null},on_timeout:{type:r.ParameterType.FUNCTION,default:null},minimum_wait:{type:r.ParameterType.INT,default:0}},data:{group:{type:r.ParameterType.OBJECT,default:void 0},wait_time:{type:r.ParameterType.INT,default:void 0},timed_out:{type:r.ParameterType.BOOL,default:!1},wait_error:{type:r.ParameterType.STRING,default:null}},citations:{apa:"Tsukamoto, H. (n.d.). jsPsychMultiplayerSync (0.0.1). https://github.com/jspsych/jspsych-multiplayer/tree/main/packages/plugin-multiplayer-sync ",bibtex:"@misc{TsukamotojsPsychMultiplayerSync, author = {Tsukamoto, Hannah}, title = {jsPsychMultiplayerSync}, url = {https://github.com/jspsych/jspsych-multiplayer/tree/main/packages/plugin-multiplayer-sync}, howpublished = {https://github.com/jspsych/jspsych-multiplayer/tree/main/packages/plugin-multiplayer-sync}, } "}};class h{constructor(i){this.jsPsych=i}trial(i,e,u){return c(this,null,function*(){const l=P(this.jsPsych);if(typeof e.wait_for!="function")throw new Error("multiplayer-sync: the `wait_for` parameter is required and must be a function (a predicate over the group session).");i.innerHTML=`