varxyValue=[0,0]module.exports={oscInFilter:function(data){var{address,args,host,port}=data// splitif(address==='/some_xy_address'){vararg1=args[0].value,arg2=args[1].valuereceive('/fader_1',arg1)receive('/fader_2',arg2)return// bypass original message}return{address,args,host,port}},oscOutFilter:function(data){var{address,args,host,port,clientId}=data// mergeif(address==='/fader_1'){xyValue[0]=args[0].valuesend(host,port,'/some_xy_address',...xyValue)return// bypass original message}elseif(address==='/fader_2'){xyValue[1]=args[1].valuesend(host,port,'/some_xy_address',...xyValue)return// bypass original message}return{address,args,host,port}}}
module.exports={oscInFilter:function(data){var{address,args,host,port}=dataif(address==='/knock_knock'){send(host,port,'/who_is_there')return// bypass original message}return{address,args,host,port}},}
// keep track of connected clientsvarclients=[]app.on('open',(data,client)=>{if(!clients.includes(client.id))clients.push(client.id)})app.on('close',(data,client)=>{if(clients.includes(client.id))clients.splice(clients.indexOf(client.id))})module.exports={oscInFilter:function(data){var{address,args,host,port}=dataif(address==='/some_osc_address'){// simulate user input on the first client in the arrayreceive('/SET','widget_id',1,{clientId:clients[0]})return// bypass original message}return{address,args,host,port}}}
// store state in a variablevarstate={}// keep track of connected clientsvarclients=[]app.on('sessionOpened',(data,client)=>{// client connected (and in a session)if(!clients.includes(client.id))clients.push(client.id)// when a client opens a session, send the state// but only if it's the only connected client (otherwise, let the regular sync happen)if(clients.length===1){receive('/STATE/SET',state,{clientId:clients[0]})}})app.on('close',(data,client)=>{// client disconnectedif(clients.includes(client.id))clients.splice(clients.indexOf(client.id))})// request 1st client's state every 10 secondssetInterval(()=>{if(clients.length>0){receive('/STATE/GET','127.0.0.1:8888',{clientId:clients[0]})}},10000)module.exports={oscOutFilter:function(data){if(data.address==='/STATE/GET'){// update state variable when the client respondsstate=data.args[0].value// bypass the osc messagereturn}returndata}}
varrouting={// midi cc vs widget id60:'fader_1',61:'fader_2',// etc}module.exports={oscInFilter:function(data){// Filter incoming osc messagesvar{address,args,host,port}=dataif(host==='midi'){// MIDI routing !if(address==='/control'){// assign args to variablesvar[channel,ctrl,value]=args.map(arg=>arg.value)// simple conditionsif(ctrl===80)receive('/SET','widget_id',value/127)// simple routing table (midi cc vs widget id)if(routing[ctrl])receive('/SET',routing[ctrl],value/127)// note: /SET simulates a user interaction and makes the widget send its osc message// but it adds some delay (we wait for the UI to respond)// AND it may trigger multiple replies if more than one client are connected.// Alternatively, we could do this:// send('/osc_address', value / 127)// receive('/osc_address', value / 127)// Or, to send /SET to a single client:// receive('/SET', '/osc_address', value / 127, {clientId: ID})}return// bypass original message}// return data if you want the message to be processedreturn{address,args,host,port}}}
varfs=nativeRequire('fs')module.exports={oscOutFilter:function(data){// Filter outgoing osc messagesvar{address,args,host,port}=dataif(address==='/file'){fs.readFile(args[0].value,'utf8',(err,data)=>{if(err){console.error(err)return}receive('/html',data)})return// bypass original message}// return data if you want the message to be processedreturn{address,args,host,port}}}
// requires ffmpeg installed on the system// and rtsp-ffmpeg installed in the custom module's folder (by running npm install rtsp-ffmpeg)// see https://github.com/agsh/rtsp-ffmpeg#ffmpeg for available optionsvarrtsp=nativeRequire('rtsp-ffmpeg')varstream=newrtsp.FFMpeg({input:'rtsp://freja.hiof.no:1935/rtplive/_definst_/hessdalen03.stream',})stream.on('data',(data)=>{// send frame to image widget with address set to "/stream"receive('/stream','data:image/jpeg;base64,'+data.toString('base64'))})module.exports={unload:()=>{stream.stop()}}