UniqueTransport

Unique Transport

npm version Code Climate Test Coverage Issue Count Donate

This plugin is designed to deliver a message from Alice to Bob at any cost.

Description

The basic idea of the script is that there are two devices (client Alice and the server Bob). Alice needs to send a message to Bob and get his data. While there is a third party that monitors the traffic between Alice and Bob and does some queries.

Thus to send the message using multiple channels:

  • xhr support http methods GET, POST, PUT, PATH and data transfer path, file name, parameters, headers and request body.
  • fetch - support http methods GET, POST, PUT, PATH and data transfer path, file name, parameters, headers and request body.
  • iframe - data communication path, the file name and parameters.
  • script - data communication path, the file name and parameters.
  • image - data communication path, the file name and parameters.
  • style - with data transfer in the path, the file name and parameters.

Channel transmission method and transmission parts data are selected randomly. Data requests are performed until.

Build

The repository contains pre-compiled files, but if you want to add your files and compile, then run the following commands in the repository folder.

  • npm install
  • npm run production

or

  • npm run development

The build required NodeJs version 6 or higher.

Usage

For details, see /src/ts/**.

Client

import ClientClass from "../../lib/ts/client";

const Client = new ClientClass();

Client.emit().then(
    (result) => {
        console.log(result);
    }
);

Server

import ServerClass from "../../lib/ts/server";

const Server = new ServerClass();

// Listened event name and callback
Server.on("connect", (data) => {
    return "OK";
});

Settings

Client

Main settings

{
    ServerAddress: "http://127.0.0.1:8888/", // Default connection address
    ConnectionTimeout: 1000, // Connection timeout
    Password: "xmas", // Password
    Reconnections: 10, // Default reconnection
    Transports: { // Transports: If some settings of the transport or the whole transport is not needed, then it should be set to false go is to remove from the settings.
        xhr: {
            HttpMethods: {
                GET: true,
                POST: true,
                PUT: true,
                PATCH: true,
            },
            SubTransports: {
                path: true,
                name: true,
                params: true,
                header: true,
                body: true,
            },
        },
        fetch: {
            HttpMethods: {
                GET: true,
                POST: true,
                PUT: true,
                PATCH: true,
            },
            SubTransports: {
                path: true,
                name: true,
                params: true,
                header: true,
                body: true,
            },
        },
        iframe: {
            SubTransports: {
                path: true,
                name: true,
                params: true,
            },
        },
        script: {
            SubTransports: {
                path: true,
                name: true,
                params: true,
            },
        },
        image: {
            SubTransports: {
                path: true,
                name: true,
                params: true,
            },
        },
        style: {
            SubTransports: {
                path: true,
                name: true,
                params: true,
            },
        }
    },
}

Emit settings

{
    Event: "connect", // Event name [required]
    Data: {}, // Data [optional]
    Url: "http://127.0.0.1:8888/test/", // Connection url [optional]
    Reconnections: 10, // Max reconnections [optional]
}

Server

Main settings

{
    ServerPort: 8888, // Port to listen on
    ConnectionTimeout: 1000, // Connection timeout
    Password: "xmas", // Password
    SuccessResponseCode: 200, // Success http response code
    ErrorResponseCode: 404, // Error http response code
}
Apskatīt un atstāt komentārus