@duet3d/connectors
TypeScript icon, indicating that this package has built-in type declarations

3.5.1 • Public • Published

Connectors

TypeScript implementation of the Duet3D HTTP connectors.

Installation

Install via npm install @duet3d/connectors.

Bug reports

Please use the forum for support requests or the DuetWebControl GitHub repository for feature requests and bug reports.

Usage

The connector works for both Duets in SBC and standalone mode. Usage is as simple as:

import { connect, BaseConnector, Callbacks, DefaultSettings } from "@duet3d/connectors";
import ObjectModel from "@duet3d/objectmodel";

// use initial settings
const settings = {
    ...DefaultSettings,
    // your custom settings
};

// try to establish a connection
let connector: BaseConnector;
try {
    const connector = connect(location.hostname, settings);
} catch (e) {
    console.error("Failed to establish connection: " + e);
    return;
}

// load settings from the machine - you can then update "settings" from your loaded settings again

// set up object model instance and stay updated via callbacks
const model = new ObjectModel();
connector.setCallbacks({
    onConnectProgress: function (connector: BaseConnector, progress: number): void {
        if (progress === -1) {
            console.log("Connection attempt complete");
        } else {
            console.log("Connection progress: " + progress + "%");
        }
    },
    onConnectionError: function (connector: BaseConnector, reason: unknown): void {
        console.log("Connection error: " + reason);
        // TODO call connector.reconnect in given intervals
    },
    onReconnected: function (connector: BaseConnector): void {
        console.log("Connection established again");
    },
    onUpdate: function (connector: BaseConnector, data: any): void {
        // Note that this is called before the final connector instance is returned!
        model.update(data);
    },
    onVolumeChanged: function (connector: BaseConnector, volumeIndex: number): void {
        // TODO reload file browser lists of the given volume
    }
});

// do whatever you want to do with the session, see BaseConnector API

Readme

Keywords

none

Package Sidebar

Install

npm i @duet3d/connectors

Weekly Downloads

77

Version

3.5.1

License

LGPL-2.1

Unpacked Size

173 kB

Total Files

19

Last publish

Collaborators

  • chrishamm