annotate resources/osc/node_modules/osc-min/examples/oscbundle_heartbeat.coffee @ 271:fb9c28a4676b prerelease

Added osc example project and node script for testing
author Liam Donovan <l.b.donovan@qmul.ac.uk>
date Tue, 17 May 2016 16:01:06 +0100
parents
children
rev   line source
l@271 1 # Same thing as the oscheartbeat example but with oscbundles.
l@271 2
l@271 3 osc = require 'osc-min'
l@271 4 dgram = require "dgram"
l@271 5
l@271 6 udp = dgram.createSocket "udp4"
l@271 7
l@271 8 if process.argv[2]?
l@271 9 outport = parseInt process.argv[2]
l@271 10 else
l@271 11 outport = 41234
l@271 12
l@271 13 # Get the unix timestamp in seconds
l@271 14 now = -> (new Date()).getTime() / 1000;
l@271 15
l@271 16 sendHeartbeat = () ->
l@271 17 buf = osc.toBuffer(
l@271 18 timetag : now() + 0.05 # 0.05 seconds from now
l@271 19 elements : [
l@271 20 {
l@271 21 address : "/p1"
l@271 22 args : new Buffer "beat"
l@271 23 }
l@271 24 {
l@271 25 address : "/p2"
l@271 26 args : "string"
l@271 27 }
l@271 28 {
l@271 29 timetag: now() + 1 # 1 second from now
l@271 30 elements : [
l@271 31 {
l@271 32 address : "/p3"
l@271 33 args : 12
l@271 34 }
l@271 35 ]
l@271 36 }
l@271 37 ]
l@271 38 )
l@271 39
l@271 40 udp.send buf, 0, buf.length, outport, "localhost"
l@271 41
l@271 42 setInterval sendHeartbeat, 2000
l@271 43
l@271 44 console.log "sending heartbeat messages to http://localhost:" + outport