Coder Social home page Coder Social logo

pyndn-json-patch's Introduction

An example on using JSON patch, SVS and AFrame to sync on VR/AR scenes.

Run the application

Setup poetry environment:

poetry install

Run the application (needs local NFD):

poetry run python -m uvicorn main:app --port 8000

Then, browse http://127.0.0.1:8000/ to see the scene.

Examples on aincraft

  • Run an instance on 8000: poetry run python -m uvicorn main:app --port 8000
  • Run an instance on 8001: poetry run python -m uvicorn main:app --port 8001
  • Connect to the 8000 instance http://127.0.0.1:8000/
  • Connect to the 8001 instance http://127.0.0.1:8001/
  • Use cursor left click to create boxes on the ground.
    • Right click to move the camera.
  • Verify that boxes are synced.

Alternatively, an NDNts version is deployed at https://zjkmxy.web.app/, which is a static webpage compatible with the python-ndn version.

Note: you still need a running localhost NFD instance to use the NDNts web for now.

Examples on operating objects (V1)

Get the JSON representation of the box

curl http://127.0.0.1:8000/objects/root/theBox

The path /root/theBox can be replaced with any object. This endpoint will automatically resolve sub-entities and return the full JSON representation.

Change the box color to red

curl http://127.0.0.1:8000/patches/root/theBox -H 'Content-Type: application/json' \
  -d '{"op": "replace", "path": "/color", "value":"#EE0000"}'

Create an octahedron

curl http://127.0.0.1:8000/patches/root/theOctahedron -H 'Content-Type: application/json' \
  -d '{"op":"new","value":{"@type":"a-octahedron","@children":{},"color":"#FF926B","radius":1,"position": "2 1.5 -4"}}'
curl http://127.0.0.1:8000/patches/root -H 'Content-Type: application/json' \
  -d '{"op": "add", "path": "/@children/theOctahedron", "value":-1}'

Examples with SVS

  • Run an instance on 8000: poetry run python -m uvicorn main:app --port 8000
  • Run an instance on 8001: poetry run python -m uvicorn main:app --port 8001
  • Manipulate objects on the 8000 instance. For example, add an octahedron.
  • Check the 8001 scene at http://127.0.0.1:8001/, verify the modification is fetched.

Discussion

  • Serverless
    • Though this demo requires python-ndn and local NFD instance to run, all operations can be executed in a browser with ndn-ts. There is nothing must be executed on the backend. It is possible to migrate to ndn-ts and use textbed or WebRTC for connectivity Also, this demo requires manual reloading the page to see new changes, but no reload is required if we migrate to TS.
  • Decentralized
    • This demo does not handle consensus problem properly. However, JSON patch can be extended to a conflict-free replicated data types (CRDT), which means eventual consensus is "automagically" reached irrelevant of the order of receiving the patches. No master server or leader election is needed.
  • Hierarchical namespace
    • There are two kinds of data objects: scene objects (a-entities) and JSON patches (i.e. diffential updates of scene objects). Scene objects can be named in any hierarchical way according to application's need. Patches are named like /<producer>/<sequence-number>, according to the security's need.
    • Peers in the sync group will fetch all patches. Since scene objects can be recovered by JSON patches, they do not need to fetch scene objects directly.
  • Security
    • Patches are signed by their producers.
    • Patches are immutable. Scene objects are updated via applying patches.

pyndn-json-patch's People

Contributors

zjkmxy avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.