@casual-simulation/causal-tree-server-socketio
Casual trees served over socket.io.
Last updated 19 days ago by kallyngowdyyeti .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @casual-simulation/causal-tree-server-socketio 
SYNC missed versions from official npm registry.

Causal Tree Server Socket.io

npm (scoped)

Casual trees served over socket.io.

Installation

npm install @casual-simulation/causal-tree-server-socketio

Usage

Start a Causal Tree Server

import * as Http from 'http';
import SocketIO from 'socket.io';
import { MongoClient } from 'mongodb';
import { CausalTreeServerSocketIO } from '@casual-simulation/causal-tree-server-socketio';
import { CausalTreeStoreMongoDB } from '@casual-simulation/causal-tree-store-mongodb';
import { DeviceManagerImpl, ChannelManagerImpl, NullDeviceAuthenticator, NullChannelAuthorizer } from '@casual-simulation/causal-tree-server';
import { CausalTreeFactory, CausalTree } from '@casual-simulation/causal-trees';

demo();

async function demo() {

    // Setup the HTTP server and Socket.io Server.
    const http = new Http.Server();
    const socket = SocketIO(this._http);

    // The claims and roles that the server
    // should have.
    // This is like a user except it bypasses authentication
    // and role lookup and just lets the server act like it
    // has the given claims and roles.
    const serverDevice: DeviceInfo = {
        claims: {
            [USERNAME_CLAIM]: 'server',
            [DEVICE_ID_CLAIM]: 'server',
            [SESSION_ID_CLAIM]: 'server',
        },
        roles: [SERVER_ROLE],
    };

    // The factory that should be used to create causal trees
    // from stored data.
    const causalTreeFactory = new CausalTreeFactory({
        test: (stored, options) => new CausalTree<any, any, any>(stored, new MyReducer(), options)
    });

    // Connect to MongoDB
    MongoClient.connect('mongodb://my_mongo_db:27017' async (client) => {

        // Load and store data in MongoDB
        const causalTreeStore = new CausalTreeStoreMongoDB(client, 'myDB');
        await causalTreeStore.init();

        // Setup the channel manager
        const channelManager = new ChannelManagerImpl(
            causalTreeStore,
            causalTreeFactory
        );

        // Setup the device manager
        const deviceManager = new DeviceManagerImpl();

        // Create a causal tree server with the following services.
        const server = new CausalTreeServerSocketIO(
            serverDevice,
            socket,
            deviceManager,
            channelManager,

            // Allow any connection to be any user
            new NullDeviceAuthenticator(),

            // Allow any user to connect to any channel
            new NullChannelAuthorizer()
        );

        // Listen for connections on port 3000
        http.listen(3000);
    });
}

Current Tags

  • 0.11.5                                ...           latest (19 days ago)

30 Versions

  • 0.11.5                                ...           19 days ago
  • 0.11.3                                ...           21 days ago
  • 0.11.0                                ...           a month ago
  • 0.10.4                                ...           a month ago
  • 0.10.3                                ...           a month ago
  • 0.10.0                                ...           2 months ago
  • 0.9.40                                ...           2 months ago
  • 0.9.39                                ...           2 months ago
  • 0.9.30                                ...           3 months ago
  • 0.9.28                                ...           3 months ago
  • 0.9.27                                ...           3 months ago
  • 0.9.21                                ...           3 months ago
  • 0.9.20                                ...           4 months ago
  • 0.9.19                                ...           4 months ago
  • 0.9.17                                ...           4 months ago
  • 0.9.14                                ...           4 months ago
  • 0.9.12                                ...           4 months ago
  • 0.9.7                                ...           5 months ago
  • 0.9.6                                ...           5 months ago
  • 0.9.1                                ...           5 months ago
  • 0.8.10                                ...           5 months ago
  • 0.8.9                                ...           5 months ago
  • 0.8.0                                ...           6 months ago
  • 0.7.0                                ...           6 months ago
  • 0.6.5                                ...           6 months ago
  • 0.6.0                                ...           6 months ago
  • 0.5.3                                ...           7 months ago
  • 0.5.2                                ...           7 months ago
  • 0.5.1                                ...           7 months ago
  • 0.5.0                                ...           7 months ago
Downloads
Today 0
This Week 0
This Month 45
Last Day 0
Last Week 30
Last Month 66
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |