Code Monkey home page Code Monkey logo

fusion's Introduction

DDP Client - Fusion Mode

This package is an extension to ddp-client, originally from Meteor, with the ability to conditionally start the DDP connection.

Original code: https://github.com/meteor/meteor/tree/devel/packages/ddp-client

Why ?

The reason is simple, websockets are expensive, and most applications won't need it. Or they need it in certain areas, this opens the path of doing so with ease.

How to install

# In your Meteor App
mkdir packages
cd packages
git clone https://github.com/cult-of-coders/fusion.git

It's not on atmosphere because we needed to override the behavior of ddp-client.

If you add this package to Meteor, the client no longer requires an websocket connection. This means that subscriptions will not work out of the box. However you can start/stop the websocket conditionally:

import {DDP} from 'meteor/ddp-client';

DDP.engage(); // establishes WS connection
DDP.disengage(); // cuts the WS connection

And for your convenience we also export the Fusion class that lets components request an websocket connection, and they can release that connection when no longer needed, and if there is no active "requesters" the websocket connection stops.

Sample:

import {Fusion} from 'meteor/ddp-client';

const handler = Fusion.engage(() => {
    Meteor.subscribe('xxx');
})

// When you no longer need it:
handler.stop();

When all registered handlers are stopped, the websocket connection also stops.

Meteor.call will work as expected inside your client, because we create a server side route "/_meteor" that accepts RPC calls. When DDP is engaged, Meteor.call will communicate via DDP

When sending HTTP RPC calls authorization is supported by default, meaning you can still use this.userId inside your methods. This is possible because we pass Accounts._storedLoginToken() to each request.

This works with accounts-password.

License: MIT

fusion's People

Contributors

theodordiaconu avatar

Watchers

James Cloos 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.