hhromic / e131-node

Node.js client/server library for the E1.31 (sACN) protocol
Apache License 2.0
28 stars 12 forks source link

Error with Buffer #1

Closed dehimer closed 8 years ago

dehimer commented 8 years ago

I trying to use library with electron.io and got an error: TypeError: undefined is not a function at Object. (/home/dehimer/projects/jumperclient/node_modules/e131/lib/e131/rootlayer.js:63:20)

I only required library: var e131 = require('e131');

dehimer commented 8 years ago

May be need to change "Buffer.new" with "Buffer" ?

hhromic commented 8 years ago

Hi, thanks for reporting this issue.

You are right in that I don't need to use new before Buffer.from() in Line 63 of rootlayer.js. My mistake there.

However I believe your error is related to your Node.js version. The Buffer.from() function was introduced since Node.js 5.1. Are you using a recent enough version? This is because using new Buffer(array) was deprecated in favour of using the more clear Buffer.from() static function. Can you make sure you are using a recent version of Node.js and let me know? More information can be found here.

In case you can't upgrade your Node.js, can you change:

RootLayer.ACN_ID = new Buffer.from(
  [0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00]);

to:

RootLayer.ACN_ID = new Buffer(
  [0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00]);

If the above makes it work for you, then definitively is because of using an older Node.js version. My recommendation for you is to use a recent version. I will update the library to remove the unnecessary newoperator before Buffer.from() anyway.

Looking forward for your answer! Hugo.

dehimer commented 8 years ago

Hmm, it is strange, becouse I tryed 6 and 5 versions of nodejs..

dehimer commented 8 years ago

Oh, sorry. I dont know why, but I added console.log(process.version) before line with error and got v2.3.1. It is funny) You are right, I have problem with version.

dehimer commented 8 years ago

Thank you! I updated my electron to last version and all works!

hhromic commented 8 years ago

I'm glad it worked for you. Make sure you update the e131 library using npm update as I changed the unnecessary new call as well. I'm closing this issue now, thanks for reporting! Hugo.