Skip to content

Commit

Permalink
update scserver command middleware to new dryadic api
Browse files Browse the repository at this point in the history
  • Loading branch information
crucialfelix committed Apr 21, 2016
1 parent b44a995 commit 4e1b868
Showing 1 changed file with 33 additions and 40 deletions.
73 changes: 33 additions & 40 deletions src/dryads/middleware/scserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,52 +31,45 @@ import * as _ from 'underscore';
*
* Bundle time format
*/
export default function scserver(commands) {
let promises = [];
commands.forEach((commandContext) => {
let command = commandContext.command;
let context = commandContext.context;

if (command.scserver) {
if (command.scserver.msg) {
let m = callIfFn(command.scserver.msg, context);
context.scserver.send.bundle(0.03, [m]);
}
if (command.scserver.bundle) {
let b = callIfFn(command.scserver.bundle, context);
export default function scserver(command, context) {
if (command.scserver) {
if (command.scserver.msg) {
let m = callIfFn(command.scserver.msg, context);
context.scserver.send.bundle(0.03, [m]);
}
if (command.scserver.bundle) {
let b = callIfFn(command.scserver.bundle, context);
context.scserver.send.bundle(b.time, b.packets);
}
if (command.scserver.sched) {
// {time: packets}
// or
// [{time: packets}, ]
let b = callIfFn(command.scserver.sched, context);
if (_.isArray(b)) {
b.forEach((bb) => context.scserver.send.bundle(bb.time, bb.packets));
// tried to send them all in a single osc bundle
// but it seems to silently choke
// let bundle = {
// timeTag: 0.03,
// packets: []
// };
// b.forEach((subBundle) => {
// bundle.packets.push({
// timeTag: subBundle.time,
// packets: subBundle.packets
// });
// });
// context.scserver.send.bundle(bundle.timeTag, bundle.packets);
} else {
context.scserver.send.bundle(b.time, b.packets);
}
if (command.scserver.callAndResponse) {
let c = callIfFn(command.scserver.callAndResponse, context);
promises.push(context.scserver.callAndResponse(c));
}
if (command.scserver.sched) {
// {time: packets}
// or
// [{time: packets}, ]
let b = callIfFn(command.scserver.sched, context);
if (_.isArray(b)) {
b.forEach((bb) => context.scserver.send.bundle(bb.time, bb.packets));
// tried to send them all in a single osc bundle
// but it seems to silently choke
// let bundle = {
// timeTag: 0.03,
// packets: []
// };
// b.forEach((subBundle) => {
// bundle.packets.push({
// timeTag: subBundle.time,
// packets: subBundle.packets
// });
// });
// context.scserver.send.bundle(bundle.timeTag, bundle.packets);
} else {
context.scserver.send.bundle(b.time, b.packets);
}
return context.scserver.callAndResponse(c);
}
}
});
return Promise.all(promises);
}
}

/**
Expand Down

0 comments on commit 4e1b868

Please sign in to comment.