A Niimbot client for web browsers written in TypeScript.
yarn add niimbot
# or
npm install niimbot
Import:
import { Niimbot } from 'niimbot';
Check if Niimbot is available at the current browser:
const isAvailable = Niimbot.available();
Create a Niimbot instance:
const niimbot = new Niimbot();
Add events listeners:
niimbot.addEventListener('connect', handleConnect);
niimbot.addEventListener('disconnect', handleDisconnect);
niimbot.addEventListener('printStart', handlePrintStart);
niimbot.addEventListener('printEnd', handlePrintEnd);
Connect to the printer:
const port = await niimbot.requestPort();
if (port) {
await niimbot.connect(port);
}
Print a sticker drawed on a canvas:
const canvas = document.getElementById('canvas') as HTMLCanvasElement;
const ctx = canvas.getContext('2d');
if (ctx) {
await niimbot.printImage(ctx, canvas.width, canvas.height);
}
Check src/demo.tsx
for a complete example.
yarn install
yarn dev
Jaroslav Khorishchenko