Giter Club home page Giter Club logo

co-share's Introduction

co-share

Build Status  Npm package version  GitHub license  Twitter

Javascript library for easily building shared applications such as chats and games

Transformable Example

A shared 3D Cube with "Alice" and "Bob" as simulated users.
The Example was built with co-share and react-three-fiber

npm i co-share

When to use

Building multiuser applications for the web is often challenging as asynchronous communication can drastically increase the system complexity. Writing robust and performant shared applications requires a structured and fitting architecture.

We propose the abstraction of shared stores to distribute logic and data between participating systems. By using Javascript & Node.js, the same code can be used on the client and the server to carry out the platform-independent communication.

How to use

The library is framework-independent as it runs on the Web and NodeJS. However, we provide react hooks out of the box to simplify the experience. Please help us to build tools for more web frameworks.

new Example extends Store {
    action = Action.create(this, "actionName", (origin, parameter) => {
        action.publishTo(
            origin == null ?
                { to: "all" } :
                { to: "all-except-one", except: origin },
            parameter
        )
    })
}

The Stores contain both, the platform-independent logic and the data. Platform independent logic is specified as Actions, which are methods that can be invoked on a remote client (similar to RPC/RMI). Above, we use publishTo to make the Store execute the given Action with the provided parameter on all nodes linked to this Store.

We will build a globally synchronized counter and display it using react. Every client can increase the counter.

Counter Example

Above, you can see a local simulation with the clients "Alice" and "Bob". Even though we can simulate the communication locally, this library is meant for networked communication using WebSocket or WebRTC.

The code for each example can be found on the respective pages

Simulated locally in your browser

  • Request - request response paradigma
  • Message - direct client to client messaging without any persistent storage in between
  • Lockable - advanced lock functionality to prevent editing by multiple people simultaneously
  • Optimistic Lockable - performance optimize lockable that allows for optimistic behaviour and error correction
  • Whiteboard - collaborative drawing on a shared whiteboard
  • Transformable - shared 3D transformation
  • Consistent - continous states with client-side prediction, lag-compensation and smoothing (using co-consistent)

An extra Project with a server/client architecture using SocketIO

Example Architecture

Sample Architecture Graph

In a multiuser scenario, stores are connected using StoreLinks. One Store can have 0-N StoreLinks to other participants.

In depth description

This framework revolves around the idea of Stores, which can represent any entity or information. A Store is a class that may contain a set of Actions which are methods that can be executed remotely. The communication for executing an action remotely is carried out by the connection of your choice, for instance, with socketio.

However, executing an Action requires an established StoreLink for a connection. This StoreLink uniquely identifies the relation between local Store and remote Store and vice versa. Setting up a StoreLink can be done manually or automatically by subscribing to a certain Store. When subscribing to a Store from a host, its Store will provide the initial parameters to create a local copy of that Store. A Subscriber provides the parameters running on every Store to determine if and what a requesting client should know about the Store. Subscribers can also deny a subscription request.

Supporting Packages

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.