51Degrees / Device-Detection

THE Fastest and most Accurate device detection for C / PHP / Perl / Python and Node.js - professionally maintained device data
https://51degrees.com/device-detection
Other
112 stars 46 forks source link

Cannot use hash trie data file on Node.js 8.9.3 using module version 3.2.18-dev #22

Closed prachaquanttech closed 6 years ago

prachaquanttech commented 6 years ago

using this config

const fiftyonedegreescoreConfig = {

  dataFile: 'static/51degrees/51Degrees-EnterpriseV3.4.trie',
  properties: [
    'HardwareVendor', 
    'HardwareModel', 
    'HardwareFamily', 
    'PriceBand', 
    'PlatformName', 
    'PlatformVersion', 
    'ScreenPixelsHeight', 
    'ScreenPixelsWidth',
    'ReleaseMonth',
    'ReleaseYear',
    'DeviceType',
    'HardwareModelVariants',
  ],
  cacheSize: 10000,
  poolSize: 20,
}
const provider = DeviceDetection.provider(fiftyonedegreescoreConfig) //Error was throw here
const match =  provider.getMatch(ctx.header['user-agent'])
match.close()

Error: Illegal arguments for construction of _exports_Provider Please help

prachaquanttech commented 6 years ago

Update if I remove properties, cacheSize and poolSize from the config, Code will run fine.

JoshGrew51D commented 6 years ago

Hi There

You should only need to remove poolSize as this is a Pattern only option. Hash Trie does not have a workset pool like Pattern. It's matches consist of Device offsets which are smaller than Pattern worksets. As a result they are calculated on the fly.

Let me know how you get on.

prachaquanttech commented 6 years ago

Thanks for the answer if add "properties" option back, It will throw "segmentation fault".

JoshGrew51D commented 6 years ago

Which version of the data file are you using currently?

prachaquanttech commented 6 years ago

51Degrees-EnterpriseV3.4.trie

JoshGrew51D commented 6 years ago

Of course, sorry ignore me.

I have modified the example above with some changes to the configuration. Properties are not stored as an array but as a comma separated string. The keys in the config are also surrounded by quotes.

Try this and let me know what you get back.

Would you also be able to send over the code where you reference the Device Detection module in: DeviceDetection.provider

const fiftyonedegreescoreConfig = {'dataFile' : 'static/51degrees/51Degrees-EnterpriseV3.4.trie',
    'properties' : 'HardwareVendor,HardwareModel,HardwareFamily,PriceBand,PlatformName,PlatformVersion,ScreenPixelsHeight,ScreenPixelsWidth,ReleaseMonth,ReleaseYear,DeviceType,HardwareModelVariants'}

const provider = DeviceDetection.provider(fiftyonedegreescoreConfig)
const match =  provider.getMatch(ctx.header['user-agent'])
match.close()
prachaquanttech commented 6 years ago

This code work

const fiftyonedegreescoreConfig = {'dataFile' : 'static/51degrees/51Degrees-EnterpriseV3.4.trie',
    'properties' : 'HardwareVendor,HardwareModel,HardwareFamily,PriceBand,PlatformName,PlatformVersion,ScreenPixelsHeight,ScreenPixelsWidth,ReleaseMonth,ReleaseYear,DeviceType,HardwareModelVariants'}

const provider = DeviceDetection.provider(fiftyonedegreescoreConfig)
const match =  provider.getMatch(ctx.header['user-agent'])
match.close()

BTW we use module this in Koa.js. Can I write provider.getMatch(ctx.request) like in Express.js?

Thanks a lot