UNPKG

@theopenweb/js-sensor

Version:

JavaScript sensor library for native input sensors.

1,360 lines 1.38 MB
{ "type": "File", "start": 0, "end": 10211, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 356, "column": 31 } }, "program": { "type": "Program", "start": 0, "end": 10211, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 356, "column": 31 } }, "sourceType": "module", "body": [ { "type": "VariableDeclaration", "start": 0, "end": 65, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 65 } }, "declarations": [ { "type": "VariableDeclarator", "start": 6, "end": 64, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 64 } }, "id": { "type": "Identifier", "start": 6, "end": 26, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 26 }, "identifierName": "BrowserSensorWatcher" }, "name": "BrowserSensorWatcher" }, "init": { "type": "CallExpression", "start": 29, "end": 64, "loc": { "start": { "line": 1, "column": 29 }, "end": { "line": 1, "column": 64 } }, "callee": { "type": "Identifier", "start": 29, "end": 36, "loc": { "start": { "line": 1, "column": 29 }, "end": { "line": 1, "column": 36 }, "identifierName": "require" }, "name": "require" }, "arguments": [ { "type": "StringLiteral", "start": 37, "end": 63, "loc": { "start": { "line": 1, "column": 37 }, "end": { "line": 1, "column": 63 } }, "extra": { "rawValue": "./browser-sensor-watcher", "raw": "'./browser-sensor-watcher'" }, "value": "./browser-sensor-watcher" } ] } } ], "kind": "const" }, { "type": "VariableDeclaration", "start": 67, "end": 88, "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 21 } }, "declarations": [ { "type": "VariableDeclarator", "start": 71, "end": 87, "loc": { "start": { "line": 2, "column": 4 }, "end": { "line": 2, "column": 20 } }, "id": { "type": "Identifier", "start": 71, "end": 87, "loc": { "start": { "line": 2, "column": 4 }, "end": { "line": 2, "column": 20 }, "identifierName": "rawSensorWatcher" }, "name": "rawSensorWatcher" }, "init": null } ], "kind": "let", "trailingComments": [ { "type": "CommentBlock", "value": "*\r\n * Main class for handling sensors.\r\n * This class allows get, watch, etc. of sensors.\r\n ", "start": 92, "end": 188, "loc": { "start": { "line": 4, "column": 0 }, "end": { "line": 7, "column": 3 } } } ] }, { "type": "ClassDeclaration", "start": 190, "end": 10176, "loc": { "start": { "line": 8, "column": 0 }, "end": { "line": 354, "column": 1 } }, "id": { "type": "Identifier", "start": 196, "end": 209, "loc": { "start": { "line": 8, "column": 6 }, "end": { "line": 8, "column": 19 }, "identifierName": "SensorHandler" }, "name": "SensorHandler", "leadingComments": null }, "superClass": null, "body": { "type": "ClassBody", "start": 210, "end": 10176, "loc": { "start": { "line": 8, "column": 20 }, "end": { "line": 354, "column": 1 } }, "body": [ { "type": "ClassMethod", "start": 219, "end": 724, "loc": { "start": { "line": 10, "column": 4 }, "end": { "line": 26, "column": 5 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 219, "end": 230, "loc": { "start": { "line": 10, "column": 4 }, "end": { "line": 10, "column": 15 }, "identifierName": "constructor" }, "name": "constructor" }, "kind": "constructor", "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "AssignmentPattern", "start": 231, "end": 244, "loc": { "start": { "line": 10, "column": 16 }, "end": { "line": 10, "column": 29 } }, "left": { "type": "Identifier", "start": 231, "end": 234, "loc": { "start": { "line": 10, "column": 16 }, "end": { "line": 10, "column": 19 }, "identifierName": "env" }, "name": "env" }, "right": { "type": "StringLiteral", "start": 235, "end": 244, "loc": { "start": { "line": 10, "column": 20 }, "end": { "line": 10, "column": 29 } }, "extra": { "rawValue": "browser", "raw": "'browser'" }, "value": "browser" } } ], "body": { "type": "BlockStatement", "start": 245, "end": 724, "loc": { "start": { "line": 10, "column": 30 }, "end": { "line": 26, "column": 5 } }, "body": [ { "type": "IfStatement", "start": 305, "end": 422, "loc": { "start": { "line": 13, "column": 8 }, "end": { "line": 15, "column": 9 } }, "test": { "type": "BinaryExpression", "start": 308, "end": 325, "loc": { "start": { "line": 13, "column": 11 }, "end": { "line": 13, "column": 28 } }, "left": { "type": "Identifier", "start": 308, "end": 311, "loc": { "start": { "line": 13, "column": 11 }, "end": { "line": 13, "column": 14 }, "identifierName": "env" }, "name": "env", "leadingComments": null }, "operator": "===", "right": { "type": "StringLiteral", "start": 316, "end": 325, "loc": { "start": { "line": 13, "column": 19 }, "end": { "line": 13, "column": 28 } }, "extra": { "rawValue": "browser", "raw": "'browser'" }, "value": "browser" }, "leadingComments": null }, "consequent": { "type": "BlockStatement", "start": 326, "end": 422, "loc": { "start": { "line": 13, "column": 29 }, "end": { "line": 15, "column": 9 } }, "body": [ { "type": "ExpressionStatement", "start": 341, "end": 411, "loc": { "start": { "line": 14, "column": 12 }, "end": { "line": 14, "column": 82 } }, "expression": { "type": "AssignmentExpression", "start": 341, "end": 410, "loc": { "start": { "line": 14, "column": 12 }, "end": { "line": 14, "column": 81 } }, "operator": "=", "left": { "type": "Identifier", "start": 341, "end": 357, "loc": { "start": { "line": 14, "column": 12 }, "end": { "line": 14, "column": 28 }, "identifierName": "rawSensorWatcher" }, "name": "rawSensorWatcher" }, "right": { "type": "AssignmentExpression", "start": 360, "end": 410, "loc": { "start": { "line": 14, "column": 31 }, "end": { "line": 14, "column": 81 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 360, "end": 381, "loc": { "start": { "line": 14, "column": 31 }, "end": { "line": 14, "column": 52 } }, "object": { "type": "ThisExpression", "start": 360, "end": 364, "loc": { "start": { "line": 14, "column": 31 }, "end": { "line": 14, "column": 35 } } }, "property": { "type": "Identifier", "start": 365, "end": 381, "loc": { "start": { "line": 14, "column": 36 }, "end": { "line": 14, "column": 52 }, "identifierName": "rawSensorWatcher" }, "name": "rawSensorWatcher" }, "computed": false }, "right": { "type": "NewExpression", "start": 384, "end": 410, "loc": { "start": { "line": 14, "column": 55 }, "end": { "line": 14, "column": 81 } }, "callee": { "type": "Identifier", "start": 388, "end": 408, "loc": { "start": { "line": 14, "column": 59 }, "end": { "line": 14, "column": 79 }, "identifierName": "BrowserSensorWatcher" }, "name": "BrowserSensorWatcher" }, "arguments": [] } } } } ], "directives": [], "trailingComments": null }, "alternate": null, "leadingComments": [ { "type": "CommentLine", "value": "Override with updateSensorListeners", "start": 258, "end": 295, "loc": { "start": { "line": 12, "column": 8 }, "end": { "line": 12, "column": 45 } } } ], "trailingComments": [ { "type": "CommentLine", "value": "SensorState mapped by sensor name", "start": 434, "end": 469, "loc": { "start": { "line": 17, "column": 8 }, "end": { "line": 17, "column": 43 } } } ] }, { "type": "ExpressionStatement", "start": 479, "end": 523, "loc": { "start": { "line": 18, "column": 8 }, "end": { "line": 20, "column": 10 } }, "expression": { "type": "AssignmentExpression", "start": 479, "end": 522, "loc": { "start": { "line": 18, "column": 8 }, "end": { "line": 20, "column": 9 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 479, "end": 491, "loc": { "start": { "line": 18, "column": 8 }, "end": { "line": 18, "column": 20 } }, "object": { "type": "ThisExpression", "start": 479, "end": 483, "loc": { "start": { "line": 18, "column": 8 }, "end": { "line": 18, "column": 12 } }, "leadingComments": null }, "property": { "type": "Identifier", "start": 484, "end": 491, "loc": { "start": { "line": 18, "column": 13 }, "end": { "line": 18, "column": 20 }, "identifierName": "sensors" }, "name": "sensors" }, "computed": false, "leadingComments": null }, "right": { "type": "ObjectExpression", "start": 494, "end": 522, "loc": { "start": { "line": 18, "column": 23 }, "end": { "line": 20, "column": 9 } }, "properties": [], "leadingComments": null, "innerComments": [ { "type": "CommentLine", "value": "", "start": 509, "end": 511, "loc": { "start": { "line": 19, "column": 12 }, "end": { "line": 19, "column": 14 } } } ] }, "leadingComments": null }, "leadingComments": [ { "type": "CommentLine", "value": "SensorState mapped by sensor name", "start": 434, "end": 469, "loc": { "start": { "line": 17, "column": 8 }, "end": { "line": 17, "column": 43 } } } ], "trailingComments": [ { "type": "CommentLine", "value": "Sensor counts stored accross start and stop watching to make sure async starting and stopping doesn't cause bugs.", "start": 535, "end": 650, "loc": { "start": { "line": 22, "column": 8 }, "end": { "line": 22, "column": 123 } } } ] }, { "type": "ExpressionStatement", "start": 660, "end": 717, "loc": { "start": { "line": 23, "column": 8 }, "end": { "line": 25, "column": 10 } }, "expression": { "type": "AssignmentExpression", "start": 660, "end": 716, "loc": { "start": { "line": 23, "column": 8 }, "end": { "line": 25, "column": 9 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 660, "end": 685, "loc": { "start": { "line": 23, "column": 8 }, "end": { "line": 23, "column": 33 } }, "object": { "type": "ThisExpression", "start": 660, "end": 664, "loc": { "start": { "line": 23, "column": 8 }, "end": { "line": 23, "column": 12 } }, "leadingComments": null }, "property": { "type": "Identifier", "start": 665, "end": 685, "loc": { "start": { "line": 23, "column": 13 }, "end": { "line": 23, "column": 33 }, "identifierName": "sensorCreationCounts" }, "name": "sensorCreationCounts" }, "computed": false, "leadingComments": null }, "right": { "type": "ObjectExpression", "start": 688, "end": 716, "loc": { "start": { "line": 23, "column": 36 }, "end": { "line": 25, "column": 9 } }, "properties": [], "leadingComments": null, "innerComments": [ { "type": "CommentLine", "value": " ", "start": 702, "end": 705, "loc": { "start": { "line": 24, "column": 11 }, "end": { "line": 24, "column": 14 } } } ] }, "leadingComments": null }, "leadingComments": [ { "type": "CommentLine", "value": "Sensor counts stored accross start and stop watching to make sure async starting and stopping doesn't cause bugs.", "start": 535, "end": 650, "loc": { "start": { "line": 22, "column": 8 }, "end": { "line": 22, "column": 123 } } } ] } ], "directives": [], "trailingComments": null }, "trailingComments": [ { "type": "CommentBlock", "value": "*\r\n * Get sensor once. Should stop watching sensor if newly made.\r\n * \r\n * @param {string} sensorName \r\n ", "start": 732, "end": 857, "loc": { "start": { "line": 28, "column": 4 }, "end": { "line": 32, "column": 7 } } } ] }, { "type": "ClassMethod", "start": 863, "end": 1655, "loc": { "start": { "line": 33, "column": 4 }, "end": { "line": 56, "column": 5 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 863, "end": 866, "loc": { "start": { "line": 33, "column": 4 }, "end": { "line": 33, "column": 7 }, "identifierName": "get" }, "name": "get", "leadingComments": null }, "kind": "method", "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 867, "end": 877, "loc": { "start": { "line": 33, "column": 8 }, "end": { "line": 33, "column": 18 }, "identifierName": "sensorName" }, "name": "sensorName" } ], "body": { "type": "BlockStatement", "start": 878, "end": 1655, "loc": { "start": { "line": 33, "column": 19 }, "end": { "line": 56, "column": 5 } }, "body": [ { "type": "VariableDeclaration", "start": 889, "end": 905, "loc": { "start": { "line": 34, "column": 8 }, "end": { "line": 34, "column": 24 } }, "declarations": [ { "type": "VariableDeclarator", "start": 893, "end": 904, "loc": { "start": { "line": 34, "column": 12 }, "end": { "line": 34, "column": 23 } }, "id": { "type": "Identifier", "start": 893, "end": 897, "loc": { "start": { "line": 34, "column": 12 }, "end": { "line": 34, "column": 16 }, "identifierName": "self" }, "name": "self" }, "init": { "type": "ThisExpression", "start": 900, "end": 904, "loc": { "start": { "line": 34, "column": 19 }, "end": { "line": 34, "column": 23 } } } } ], "kind": "let" }, { "type": "ReturnStatement", "start": 915, "end": 1648, "loc": { "start": { "line": 35, "column": 8 }, "end": { "line": 55, "column": 11 } }, "argument": { "type": "NewExpression", "start": 922, "end": 1647, "loc": { "start": { "line": 35, "column": 15 }, "end": { "line": 55, "column": 10 } }, "callee": { "type": "Identifier", "start": 926, "end": 933, "loc": { "start": { "line": 35, "column": 19 }, "end": { "line": 35, "column": 26 }, "identifierName": "Promise" }, "name": "Promise" }, "arguments": [ { "type": "ArrowFunctionExpression", "start": 934, "end": 1646, "loc": { "start": { "line": 35, "column": 27 }, "end": { "line": 55, "column": 9 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 935, "end": 942, "loc": { "start": { "line": 35, "column": 28 }, "end": { "line": 35, "column": 35 }, "identifierName": "resolve" }, "name": "resolve" }, { "type": "Identifier", "start": 944, "end": 950, "loc": { "start": { "line": 35, "column": 37 }, "end": { "line": 35, "column": 43 }, "identifierName": "reject" }, "name": "reject" } ], "body": { "type": "BlockStatement", "start": 953, "end": 1646, "loc": { "start": { "line": 35, "column": 46 }, "end": { "line": 55, "column": 9 } }, "body": [ { "type": "VariableDeclaration", "start": 968, "end": 1029, "loc": { "start": { "line": 36, "column": 12 }, "end": { "line": 36, "column": 73 } }, "declarations": [ { "type": "VariableDeclarator", "start": 972, "end": 1028, "loc": { "start": { "line": 36, "column": 16 }, "end": { "line": 36, "column": 72 } }, "id": { "type": "Identifier", "start": 972, "end": 991, "loc": { "start": { "line": 36, "column": 16 }, "end": { "line": 36, "column": 35 }, "identifierName": "sensorCreationCount" }, "name": "sensorCreationCount" }, "init": { "type": "BinaryExpression", "start": 994, "end": 1028, "loc": { "start": { "line": 36, "column": 38 }, "end": { "line": 36, "column": 72 } }, "left": { "type": "CallExpression", "start": 994, "end": 1024, "loc": { "start": { "line": 36, "column": 38 }, "end": { "line": 36, "column": 68 } }, "callee": { "type": "MemberExpression", "start": 994, "end": 1022, "loc": { "start": { "line": 36, "column": 38 }, "end": { "line": 36, "column": 66 } }, "object": { "type": "Identifier", "start": 994, "end": 998, "loc": { "start": { "line": 36, "column": 38 }, "end": { "line": 36, "column": 42 }, "identifierName": "self" }, "name": "self" }, "property": { "type": "Identifier", "start": 999, "end": 1022, "loc": { "start": { "line": 36, "column": 43 }, "end": { "line": 36, "column": 66 }, "identifierName": "_getSensorCreationCount" }, "name": "_getSensorCreationCount" }, "computed": false }, "arguments": [] }, "operator": "+", "right": { "type": "NumericLiteral", "start": 1027, "end": 1028, "loc": { "start": { "line": 36, "column": 71 }, "end": { "line": 36, "column": 72 } }, "extra": { "rawValue": 1, "raw": "1" }, "value": 1 } } } ], "kind": "let" }, { "type": "VariableDeclaration", "start": 1043, "end": 1500, "loc": { "start": { "line": 37, "column": 12 }, "end": { "line": 49, "column": 14 } }, "declarations": [