Socket
Socket
Sign inDemoInstall

aframe-webthing

Package Overview
Dependencies
81
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.0.2

CNAME

3

example/aframe/package.json

@@ -30,4 +30,3 @@ {

"homepage": "https://libraries.io/npm/aframe-webthing",
"dependencies": {
}
"dependencies": {}
}

@@ -15,6 +15,6 @@ // -*- mode: js; js-indent-level:2; -*-

level: { type: 'number', default: 0},
on: { type: 'boolean', value: true}
},
update: function(old) {
console.log('log: level.update');
var properties = this.data;

@@ -24,11 +24,12 @@ for (var property of Object.keys(properties)) {

case "level":
this.level = (properties[property] / 100 / 4) + .25 ;
this.data[property] = (properties[property]/100/.5)+.5 ;
break;
default:
break;
}
var el = document.getElementById(property);
if (!el || !el.object3D)
throw "Null: " + property;
el.object3D.scale.set(this.level, this.level, this.level);
}
this.el.object3D.scale.setScalar(this.data.level);
this.el.setAttribute('color',
this.data.on ? 'green' : 'red');
}
});

@@ -1,66 +0,47 @@

// -*- mode: js; js-indent-level:2; -*-
// SPDX-License-Identifier: MPL-2.0
var webthing;
/**
*
* Copyright 2019-present Samsung Electronics France SAS, and other contributors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/#
*/
var console = require('console'); // Disable logs here by editing to '!console.log'
var log = console.log || function () {};
var verbose = console.log || function () {};
var webthing = require('webthing-iotjs');
try {
webthing = require('../webthing');
} catch (err) {
webthing = require('webthing-iotjs');
}
var Property = webthing.Property;
var SingleThing = webthing.SingleThing;
var Thing = webthing.Thing;
var Value = webthing.Value;
var WebThingServer = webthing.WebThingServer;
function LevelProperty(thing, name, value, metadata, config) {
var that = this;
this.config = config || {};
webthing.Property.call(this, thing,
name || "Level",
new webthing.Value(Number(value)), {
title: metadata && metadata.title || "Level: ".concat(name),
type: 'number',
minimum: this.config.minimum || 0,
maximum: this.config.maximum || 100,
description: metadata && metadata.description || "Level"
});
{
this.config = config;
that.value.valueForwarder = function (value) {
verbose('forward: ' + value);
};
}
function makeThing() {
var thing = new Thing('urn:dev:ops:my-lamp-1234', 'My Lamp', ['OnOffSwitch', 'Light'], 'A web connected lamp');
thing.addProperty(new Property(thing, 'on', new Value(true), {
'@type': 'OnOffProperty',
title: 'On/Off',
type: 'boolean',
description: 'Whether the lamp is turned on'
}));
thing.addProperty(new Property(thing, 'level', new Value(50), {
'@type': 'BrightnessProperty',
title: 'Brightness',
type: 'integer',
description: 'The level of light from 0-100',
minimum: 0,
maximum: 100,
unit: 'percent'
}));
return thing;
}
function LevelThing(name, type, description) {
var that = this;
webthing.Thing.call(this,
name || 'Level',
type || [],
description || 'A web connected Level');
{
this.addProperty(new LevelProperty(this, 'level', 100, {
description: 'Level'
}));
}
}
function runServer() {
var thing = makeThing(); // If adding more than one thing, use MultipleThings() with a name.
// In the single thing case, the thing's name will be broadcast.
function App() {
var that = this;
this.port = process.argv[3] ? Number(process.argv[3]) : 8888;
this.url = "http://localhost:".concat(this.port);
this.server = new webthing.WebThingServer(new webthing.SingleThing(new LevelThing()), this.port);
var server = new WebThingServer(new SingleThing(thing), 8888);
process.on('SIGINT', function () {
that.server.stop();
server.stop();
process.exit();
});
console.log(this.url);
this.server.start();
server.start();
}
if (module.parent === null) {
App()
}
runServer();

@@ -14,7 +14,7 @@ {

"type": "git",
"url": "git+https://github.com/rzr/webthing-example.git"
"url": "git+https://github.com/rzr/aframe-webthing.git"
},
"dependencies": {
"webthing-iotjs": "^0.11.2-1"
"webthing-iotjs": "^0.12.0"
}
}
{
"name": "aframe-webthing",
"version": "0.0.1",
"version": "0.0.2",
"description": "Bind webthings to XR",

@@ -21,6 +21,11 @@ "main": "index.js",

"aframe-component",
"motor",
"robot",
"robotic",
"servo"
"digital-twin",
"moziot",
"virtual-reality",
"vr",
"webthing",
"webthings",
"webvr",
"webxr",
"xr"
],

@@ -27,0 +32,0 @@ "bugs": {

# AFRAME-WEBTHING #
[![GitHub forks](https://img.shields.io/github/forks/rzr/aframe-webthing.svg?style=social&label=Fork&maxAge=2592000)](https://GitHub.com/rzr/aframe-webthing/network/)
[![license](https://img.shields.io/badge/license-MPL--2.0-blue.svg)](LICENSE)
[![NPM](https://img.shields.io/npm/v/aframe-webthing.svg)](https://www.npmjs.com/package/aframe-webthing)
[![IRC Channel](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://kiwiirc.com/client/irc.freenode.net/#tizen)
## ABOUT: ##
AFrame-Webthing is a webcomponent that bind properties of physical devices to virtual models.
[![aframe-webthing](https://image.slidesharecdn.com/aframe-webthing-20190710-190710195750/95/aframewebthing20190710-27-638.jpg)](https://speakerdeck.com/rzr/aframe-webthing-20190710rzr# "aframe-webthing")
## USAGE: ##
As reference example we'll use simulator devices from webthing SDK,
but it's mosty same if deployed on actual devices,
check resources chapter for more details.
### USING IOT.JS: ###
```sh
make -C example/webthing-iotjs start
make -C example/webthing-iotjs start &
#| node index.js
#| http://localhost:8888
#| Ctrl+C
bg
make -C example/webthing-iotjs demo
#| curl -H "Accept: application/json" -H "Content-type: application/json" http://localhost:8888/properties/level
#| {"level":100}
#| curl http://localhost:8888/properties
#| {"on":true, "level":42}
x-www-browser './example/aframe/index.html?verbose=yes'
```
### USING NODE.JS: ###
```sh
make -C example/webthing-node start &
#| node index.js
#| http://localhost:8888
#| Ctrl+C
bg
make -C example/webthing-node demo
#| curl http://localhost:8888/properties
#| {"on":true, "level":42}
make start

@@ -20,5 +58,38 @@ #| PORT=8880 node index.js

x-www-browser http://localhost:8880?verbose=yes&useWs=no
x-www-browser 'http://localhost:8880?verbose=yes&useWs=no'
# Or you could use a public server (on http):
x-www-browser 'http://rzr.github.io/aframe-webthing?useWs=no&verbose=yes'
```
### XR FROM THE WEB: ###
For our developement purposes we used local filesystem (file:// scheme),
but for more advanced scenes, hosting on the web (on http) is also possible.
```sh
make start
#| PORT=8880 node index.js
#| Your app is listening on port 8880
x-www-browser 'http://localhost:8880/example/aframe/?verbose=yes&useWs=no'
# Or you could use a public server (on http):
x-www-browser 'http://rzr.github.io/aframe-webthing?useWs=no&verbose=yes'
```
URL can be accesed from VR Headset like GearVR,
just type the URL from SamsungInternet in VR mode (aka sVRbrowser).
## SUPPORT: ##
* Samsung Internet on GearVR (sVRbrowser)
* MagicLeap ML1 OS Version 0.96.1. ML Helio 0.5.5
[![#aframe-webthing-0.0.2
](https://pbs.twimg.com/media/EAaIYzvXUAAq73_?format=jpg&name=small)
](https://twitter.com/utopiah/status/1154760317546762240#aframe-webthing-0.0.2#
"aframe-webthing-0.0.2")
## RESOURCES: ##

@@ -28,1 +99,7 @@

* <https://purl.org/aframe-webthing>
* <https://www.npmjs.com/package/twins>
* <https://en.wikipedia.org/wiki/Digital_twin>
* <https://github.com/rzr/webthing-iotjs/wiki/IotJs>
* <https://github.com/rzr/webthing-iotjs/wiki/XR>
* <https://github.com/rzr/webthing-iotjs/wiki/DigitalTwins>
* <https://github.com/mozilla-iot/webthing-node/pull/108>

@@ -23,2 +23,3 @@ // -*- mode: js; js-indent-level:2; -*-

verbose: {type: "string", default: "no" },
persist: {type: "string", default: "no" },
settings: {type: "string", default: ""}

@@ -85,3 +86,3 @@ },

verbose(`log: stopping: ${that.data.pause}`);
that.inverval = clearInterval(that.interval);
toggle(false);
}

@@ -94,2 +95,3 @@ query();

{
query();
let useWebsockets = ("WebSocket" in window) && (that.data.useWs === 'yes');

@@ -120,3 +122,2 @@ if (useWebsockets) {

}
query();
poll();

@@ -137,12 +138,30 @@ }

clearInterval(that.interval);
that.interval = null;
}
}
}
//TODO: Overloading from Local storage (to relocate elsewhere)
let el = document.getElementById(that.data.properties);
for (let key of Object.keys(localStorage)) {
if (that.data[key] != undefined) {
that.el.setAttribute('webthing', key, localStorage[key]);
if (document.location.search) {
let searchParams = null;
searchParams = (new URL(document.location)).searchParams;
if (searchParams) {
for (let entry of searchParams.entries()) {
that.data[entry[0]] = entry[1];
}
}
if (that.data['persist'] === 'yes') {
for (let entry of searchParams.entries()) {
localStorage[entry[0]] = entry[1];
}
}
window.history.pushState(null, null, window.location.pathname);
}
if (that.data['persist'] === 'yes') {
let el = document.getElementById(that.data.properties);
for (let key of Object.keys(localStorage)) {
if (that.data[key] != undefined) {
that.el.setAttribute('webthing', key, localStorage[key]);
}
}
}

@@ -149,0 +168,0 @@ verbose('log: Starting');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc