/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited * This file autogenerated for jsapi */ #include #include #include "amp_config.h" #include "addons/libjs.h" #ifdef JSE_HIGHLEVEL_JSAPI libjs_entry_t LIBJS_ENTRIES[] = { #ifdef JSE_HW_ADDON_ADC {"adc", "'use strict';var _createClass=function(){function a(a,b){for(var c,d=0;db&&this.emit('error')}},{key:'upgrade',value:function c(a,b){__native.APPOTA.otaUpgrade(a,b)}}]),b}(EventEmitter);function open(a){return new UTILS_APPOTA(a)}module.exports={open:open};"}, #endif #ifdef JSE_CORE_ADDON_AT {"at", "'use strict';module.exports=__native.AT;"}, #endif #ifdef JSE_ADVANCED_ADDON_AUDIOPLAYER {"audioplayer", "'use strict';var _createClass=function(){function a(a,b){for(var c,d=0;da)throw new Error('invalid params');return __native.audioplayer.seekto(a)}},{key:'getPosition',value:function a(){return __native.audioplayer.getPosition()}},{key:'getDuration',value:function a(){return __native.audioplayer.getDuration()}},{key:'getState',value:function a(){return __native.audioplayer.getState()}},{key:'_onState',value:function a(){__native.audioplayer.onState(function(a){this.emit('stateChange',a)}.bind(this))}},{key:'listPlay',value:function c(a,b){if(!a||!b)throw new Error('invalid params');return __native.audioplayer.listPlay(a,b)}},{key:'listPlayStop',value:function a(){return __native.audioplayer.listPlayStop()}},{key:'setVolume',value:function b(a){if(0>a)throw new Error('invalid params');return __native.audioplayer.setVolume(a)}},{key:'getVolume',value:function a(){return __native.audioplayer.getVolume()}}]),b}(EventEmitter));"}, #endif #ifdef JSE_CORE_ADDON_BATTERY {"battery", "'use strict';var _createClass=function(){function a(a,b){for(var c,d=0;da||Number.isNaN(a))throw new Error('defaultMaxListeners:a non-negative number');defaultMaxListeners=a}}),EventEmitter.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},EventEmitter.prototype.setMaxListeners=function(a){if('number'!=typeof a||0>a||Number.isNaN(a))throw new Error('a non-negative number');this._maxListeners=a;var b=this;return b};function _getMaxListeners(a){return void 0===a._maxListeners?EventEmitter.defaultMaxListeners:a._maxListeners}EventEmitter.prototype.getMaxListeners=function(){return _getMaxListeners(this)};function longestSeqContainedIn(c,a){for(var b=c.length;3<=b;--b)for(var d=0;de)return h;0===e?c.shift():(void 0===spliceOne&&(spliceOne=require('internal/util').spliceOne),spliceOne(c,e)),1===c.length&&(d[a]=c[0]),void 0!==d.removeListener&&this.emit('removeListener',a,g||b)}return h},EventEmitter.prototype.off=EventEmitter.prototype.removeListener,EventEmitter.prototype.removeAllListeners=function(a){var b,c,d,e=this;if(c=this._events,void 0===c)return e;if(void 0===c.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==c[a]&&(0==--this._eventsCount?this._events=Object.create(null):delete c[a]),e;if(0===arguments.length){var f,g=Object.keys(c);for(d=0;dc)throw new Error('subscribe topic error',a.topic);return c}},{key:'unsubscribe',value:function d(a,b){var c=__native.AIOT_DEVICE.unsubscribe(this.IoTDeviceInstance,a,b||function(){});if(0>c)throw new Error('unsubscribe topic error',a);return c}},{key:'publish',value:function d(a,b){var c=__native.AIOT_DEVICE.publish(this.IoTDeviceInstance,a,b||function(){});if(0>c)throw new Error('publish topic info error',a.topic);return c}},{key:'postProps',value:function d(a,b){var c=__native.AIOT_DEVICE.postProps(this.IoTDeviceInstance,a,b||function(){});if(0>c)throw new Error('post props error');return c}},{key:'onProps',value:function c(a){var b=__native.AIOT_DEVICE.onProps(this.IoTDeviceInstance,a);if(0>b)throw new Error('on props error');return b}},{key:'postEvent',value:function d(a,b){var c=__native.AIOT_DEVICE.postEvent(this.IoTDeviceInstance,a,b||function(){});if(0>c)throw new Error('post event error');return c}},{key:'onService',value:function c(a){var b=__native.AIOT_DEVICE.onService(this.IoTDeviceInstance,a);if(0>b)throw new Error('on service error');return b}},{key:'end',value:function c(a){var b=__native.AIOT_DEVICE.close(this.IoTDeviceInstance,a||function(){});if(0>b)throw new Error('end iot client error');return b}}]),b}(EventEmitter),IotGatewayClient=function(a){function b(a){_classCallCheck(this,b);var c=_possibleConstructorReturn(this,(b.__proto__||Object.getPrototypeOf(b)).call(this));if(!a||!a.productKey||!a.deviceName||!a.deviceSecret)throw new Error('device info error');return c.options={productKey:a.productKey,deviceName:a.deviceName,deviceSecret:a.deviceSecret,keepaliveSec:a.keepaliveSec||60,region:a.region||'cn-shanghai'},c._on(),c._connect(),c}return _inherits(b,a),_createClass(b,[{key:'_connect',value:function a(){__native.AIOT_GATEWAY.gateway(this.options,function(a){a.handle&&0==a.code&&(this.IoTGatewayInstance=a.handle,this.emit('connect'))}.bind(this))}},{key:'_on',value:function a(){__native.AIOT_GATEWAY.onMqttMessage(function(a){switch(a.code){case 1:this.emit('reconnect');break;case 2:this.emit('disconnect');break;case 3:this.emit('message',a);break;default:}}.bind(this))}},{key:'addTopo',value:function d(a,b){var c=__native.AIOT_GATEWAY.addTopo(this.IoTGatewayInstance,a,b||function(){});if(0>c)throw new Error('add topo error');return c}},{key:'getTopo',value:function c(a){var b=__native.AIOT_GATEWAY.getTopo(this.IoTGatewayInstance,a||function(){});if(0>b)throw new Error('get topo error');return b}},{key:'removeTopo',value:function d(a,b){var c=__native.AIOT_GATEWAY.removeTopo(this.IoTGatewayInstance,a,b||function(){});if(0>c)throw new Error('remove topo error');return c}},{key:'login',value:function d(a,b){var c=__native.AIOT_GATEWAY.login(this.IoTGatewayInstance,a,b||function(){});if(0>c)throw new Error('aiot subdev login error');return c}},{key:'logout',value:function d(a,b){var c=__native.AIOT_GATEWAY.logout(this.IoTGatewayInstance,a,b||function(){});if(0>c)throw new Error('aiot subdev logout error');return c}},{key:'registerSubDevice',value:function d(a,b){var c=__native.AIOT_GATEWAY.registerSubDevice(this.IoTGatewayInstance,a,b||function(){});if(0>c)throw new Error('aiot register subdev error');return c}},{key:'subscribe',value:function d(a,b){var c=__native.AIOT_GATEWAY.subscribe(this.IoTGatewayInstance,a,b||function(){});if(0>c)throw new Error('subscribe topic error',options.topic);return c}},{key:'unsubscribe',value:function d(a,b){var c=__native.AIOT_GATEWAY.unsubscribe(this.IoTGatewayInstance,a,b||function(){});if(0>c)throw new Error('unsubscribe topic error',a);return c}},{key:'publish',value:function d(a,b){var c=__native.AIOT_GATEWAY.publish(this.IoTGatewayInstance,a,b||function(){});if(0>c)throw new Error('publish topic info error',a.topic);return c}}]),b}(EventEmitter);function dynreg(a,b){var c=__native.AIOT_DEVICE.register(a,b);if(0>c)throw new Error('dynmic register error');return c}function device(a){return new IotDeviceClient(a)}function gateway(a){return new IotGatewayClient(a)}module.exports={device:device,gateway:gateway,dynreg:dynreg};"}, #endif #ifdef JSE_ADVANCED_ADDON_KEYPAD {"keypad", "'use strict';var _createClass=function(){function a(a,b){for(var c,d=0;db?('function'==typeof a.fail&&a.fail(),this.emit('error','subscribe error')):'function'==typeof a.success&&a.success()}},{key:'unsubscribe',value:function c(a){if(!this.mqttInstance||!a||!a.topic)throw new Error('mqtt not init or mqtt topic is invalid');if(!1===this.connected)return void this.emit('error','unsubscribe fail: not connected');var b=__native.MQTT.unsubscribe(this.mqttInstance,a.topic,function(){}.bind(this));return 0>b?('function'==typeof a.fail&&a.fail(),void this.emit('error','unsubscribe error')):void('function'==typeof a.success&&a.success())}},{key:'publish',value:function b(a){if(!this.mqttInstance||!a||!a.topic||!a.message)throw new Error('mqtt not init or options invalid');return!1===this.connected?void this.emit('error','publish fail: not connected'):void __native.MQTT.publish(this.mqttInstance,a.topic,a.message,a.qos||0,function(b){return 0>b?('function'==typeof a.fail&&a.fail(),void this.emit('error',a.topic)):void('function'==typeof a.success&&a.success())}.bind(this))}},{key:'close',value:function a(){if(!this.mqttInstance)throw new Error('mqtt not init');__native.MQTT.close(this.mqttInstance,function(a){return 0==a?void this.emit('close'):void this.emit('error','mqtt client close error')}.bind(this))}}]),b}(EventEmitter);function createClient(a){return new MQTTClient(a)}module.exports={createClient:createClient};"}, #endif {"netmgr", "'use strict';var _createClass=function(){function a(a,b){for(var c,d=0;dthis.payboxInstance?void this.fail():void(this.opened=!0,this.success())}},{key:'_on',value:function a(){if(0>this.payboxInstance)throw new Error('PAYBOX not init');__native.PAYBOX.on(this.payboxInstance,function(a,b){this.emit(a,b)}.bind(this))}},{key:'close',value:function b(){if(0>this.payboxInstance)throw new Error('device not init...');var a=__native.PAYBOX.close(this.payboxInstance);return 0==a?void(this.opened=!1,this.emit('close')):void this.emit('error','paybox client close falied')}}]),b}(EventEmitter);function open(a){return new PayboxClient(a)}module.exports={open:open};"}, #endif #ifdef JSE_CORE_ADDON_PM {"pm", "'use strict';var _createClass=function(){function a(a,b){for(var c,d=0;db)return void this.emit('error',b)}},{key:'getAutosleepMode',value:function b(){var a=__native.PM.getAutosleepMode();if(0>a)return void this.emit('error',a)}},{key:'sleep',value:function b(){var a=__native.PM.sleep();if(0>a)return void this.emit('error',a)}},{key:'powerReset',value:function b(){var a=__native.PM.powerReset();if(0>a)return void this.emit('error',a)}},{key:'powerDown',value:function b(){var a=__native.PM.powerDown();if(0>a)return void this.emit('error',a)}},{key:'wakelockLock',value:function b(){var a=__native.PM.wakelockLock();if(0>a)return void this.emit('error',a)}},{key:'wakelockUnlock',value:function b(){var a=__native.PM.wakelockUnlock();if(0>a)return void this.emit('error',a)}},{key:'wakelockTimedlock',value:function c(a){var b=__native.PM.wakelockTimedlock(a);if(0>b)return void this.emit('error',b)}}]),b}(EventEmitter));"}, #endif #ifdef JSE_HW_ADDON_PWM {"pwm", "\"use strict\";var _createClass=function(){function a(a,b){for(var c,d=0;d>=8;while(b);d=d.concat(c.reverse())}return d}var TCPClient=function(a){function b(a){_classCallCheck(this,b);var c=_possibleConstructorReturn(this,(b.__proto__||Object.getPrototypeOf(b)).call(this));if(!a||!a.host||!a.port)throw new Error('invalid params');return c.options={host:a.host,port:a.port},c.success=a.success||function(){},c.fail=a.fail||function(){},c._connect(),c}return _inherits(b,a),_createClass(b,[{key:'_connect',value:function a(){this.connected=!1;0>__native.TCP.createSocket(this.options,function b(a){return 0>a?(this.fail(),void this.emit('error','tcp connect error')):void(this.tcpClientInstance=a,this.connected=!0,this.success(),this.emit('connect'),this._onListening())}.bind(this))&&(this.fail(),this.emit('error','tcp connect error'))}},{key:'send',value:function b(a){if(a.message instanceof Array||(a.message=stringToBytesArray(a.message)),!1===this.connected)throw new Error('tcp not connected');__native.TCP.send(this.tcpClientInstance,a.message,function(b){return 0>b?(this.emit('error','tcp send error'),void(a.fail&&a.fail())):void(this.emit('send','tcp send success'),a.success&&a.success())}.bind(this))}},{key:'_onListening',value:function a(){if(!this.tcpClientInstance)throw new Error('tcpserver not init');__native.TCP.recv(this.tcpClientInstance,function(a,b){return-2===a?(this.connected=!1,void this.emit('error','tcp receive message error')):-1===a?(this.connected=!1,void this.emit('disconnect')):void(0>=8;while(b);d=d.concat(c.reverse())}return d}var UDPClient=function(a){function b(){_classCallCheck(this,b);var a=_possibleConstructorReturn(this,(b.__proto__||Object.getPrototypeOf(b)).call(this));return a.udpClientInstance=__native.UDP.createSocket(),a.localPort=0,a}return _inherits(b,a),_createClass(b,[{key:'bind',value:function b(a){if(this.localPort=a||0,0>__native.UDP.bind(this.udpClientInstance,this.localPort))throw new Error('bind error');this._onListening()}},{key:'send',value:function b(a){a.message instanceof Array||(a.message=stringToBytesArray(a.message)),__native.UDP.sendto(this.udpClientInstance,a,function(b){return 0>b?(this.emit('error','udp send error'),void(a.fail&&a.fail())):void(this.emit('send','udp send success'),a.success&&a.success())}.bind(this))}},{key:'close',value:function b(){var a=__native.UDP.close(this.udpClientInstance);return 0>a?void console.log('close udp socket faild'):void this.emit('close','udp client close')}},{key:'_onListening',value:function a(){__native.UDP.recvfrom(this.udpClientInstance,function(a,b,c){return-4===c?void this.emit('error','udp client receive data error'):void(0