soundworks
plugin for assigning a ticket (unique index) to the client among the available ones. The number of available tickets can be limited and tickets can be associated with additional data.
npm install @soundworks/plugin-checkin --save
A working example can be found in the https://github.com/collective-soundworks/soundworks-examples repository.
// index.js
import { Server } from '@soundworks/core/server';
import pluginCheckinFactory from '@soundworks/plugin-checkin/server';
const server = new Server();
server.pluginManager.register('checkin', pluginCheckinFactory, {
// order in which the tickets are assigned
// defaults to 'ascending'
order: 'random',
// optionnal number of tickets that can be delivered,
// must be defined if order is set to random
capacity: 4,
// optionnal data associated to each delivered index,
// if capacity is not defined or data.length < capacity,
// capacity is set to data.length
data: ['a', 'b', 'c', 'd'],
}, []);
// MyExperience.js
import { AbstractExperience } from '@soundworks/core/server';
class MyExperience extends AbstractExperience {
constructor(server, clientType) {
super(server, clientType);
// require plugin in the experience
this.checkin = this.require('checkin');
}
}
// index.js
import { Client } from '@soundworks/core/client';
import pluginCheckinFactory from '@soundworks/plugin-checkin/client';
const client = new Client();
client.pluginManager.register('checkin', pluginCheckinFactory, {}, []);
// MyExperience.js
import { Experience } from '@soundworks/core/client';
class MyExperience extends Experience {
constructor(client) {
super(client);
// require plugin in the experience
this.checkin = this.require('checkin');
}
}
The following API is only available client-side
const { index, data } = this.checkin.getValues();
// or individually
const index = this.checkin.get('index');
const data = this.checkin.get('data');
The code has been initiated in the framework of the WAVE and CoSiMa research projects, funded by the French National Research Agency (ANR).
BSD-3-Clause