@@ -203,68 +203,73 @@ export default class EventHandler {
203203 throw new Error ( 'OSC EventHandler can not be called without any argument' )
204204 }
205205
206- // check for incoming dispatchable OSC data
207- if ( args [ 0 ] instanceof Packet ) {
208- return this . dispatch ( args [ 0 ] , args [ 1 ] )
209- } else if ( args [ 0 ] instanceof Bundle || args [ 0 ] instanceof Message ) {
210- return this . dispatch ( new Packet ( args [ 0 ] ) , args [ 1 ] )
211- } else if ( ! isString ( args [ 0 ] ) ) {
212- const packet = new Packet ( )
213- packet . unpack ( dataView ( args [ 0 ] ) )
214- return this . dispatch ( packet , args [ 1 ] )
215- }
206+ try {
207+ // check for incoming dispatchable OSC data
208+ if ( args [ 0 ] instanceof Packet ) {
209+ return this . dispatch ( args [ 0 ] , args [ 1 ] )
210+ } else if ( args [ 0 ] instanceof Bundle || args [ 0 ] instanceof Message ) {
211+ return this . dispatch ( new Packet ( args [ 0 ] ) , args [ 1 ] )
212+ } else if ( ! isString ( args [ 0 ] ) ) {
213+ const packet = new Packet ( )
214+ packet . unpack ( dataView ( args [ 0 ] ) )
215+ return this . dispatch ( packet , args [ 1 ] )
216+ }
216217
217- const name = args [ 0 ]
218+ const name = args [ 0 ]
218219
219- // data argument
220- let data = null
220+ // data argument
221+ let data = null
221222
222- if ( args . length > 1 ) {
223- data = args [ 1 ]
224- }
223+ if ( args . length > 1 ) {
224+ data = args [ 1 ]
225+ }
225226
226- // timestamp argument
227- let timestamp = null
227+ // timestamp argument
228+ let timestamp = null
228229
229- if ( args . length > 2 ) {
230- if ( isInt ( args [ 2 ] ) ) {
231- timestamp = args [ 2 ]
232- } else if ( args [ 2 ] instanceof Date ) {
233- timestamp = args [ 2 ] . getTime ( )
234- } else {
235- throw new Error ( 'OSC EventHandler timestamp has to be a number or Date' )
230+ if ( args . length > 2 ) {
231+ if ( isInt ( args [ 2 ] ) ) {
232+ timestamp = args [ 2 ]
233+ } else if ( args [ 2 ] instanceof Date ) {
234+ timestamp = args [ 2 ] . getTime ( )
235+ } else {
236+ throw new Error ( 'OSC EventHandler timestamp has to be a number or Date' )
237+ }
236238 }
237- }
238239
239- // remote address info
240- let rinfo = null
240+ // remote address info
241+ let rinfo = null
241242
242- if ( args . length >= 3 ) {
243- rinfo = args [ 3 ]
244- }
243+ if ( args . length >= 3 ) {
244+ rinfo = args [ 3 ]
245+ }
245246
246- // notify now or later
247- if ( timestamp ) {
248- const now = Date . now ( )
247+ // notify now or later
248+ if ( timestamp ) {
249+ const now = Date . now ( )
249250
250- // is message outdated?
251- if ( now > timestamp ) {
252- if ( ! this . options . discardLateMessages ) {
253- return this . call ( name , data , rinfo )
251+ // is message outdated?
252+ if ( now > timestamp ) {
253+ if ( ! this . options . discardLateMessages ) {
254+ return this . call ( name , data , rinfo )
255+ }
254256 }
255- }
256257
257- // notify later
258- const that = this
258+ // notify later
259+ const that = this
259260
260- setTimeout ( ( ) => {
261- that . call ( name , data , rinfo )
262- } , timestamp - now )
261+ setTimeout ( ( ) => {
262+ that . call ( name , data , rinfo )
263+ } , timestamp - now )
263264
264- return true
265- }
265+ return true
266+ }
266267
267- return this . call ( name , data , rinfo )
268+ return this . call ( name , data , rinfo )
269+ } catch ( error ) {
270+ this . notify ( 'error' , error )
271+ return false
272+ }
268273 }
269274
270275 /**
0 commit comments