# srd-web-sdk-demo

> SRD Web javascript sdk

Latest version **1.0.12** (published 2023-10-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install srd-web-sdk-demo
pnpm add srd-web-sdk-demo
yarn add srd-web-sdk-demo
bun add srd-web-sdk-demo
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2023-10-30 |
| First published | 2023-09-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 83.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | dmuller189 |

## Links

- npm: https://www.npmjs.com/package/srd-web-sdk-demo
- Repository: https://bitbucket.org/ballastlane/srd-web-sdk
- Homepage: https://bitbucket.org/ballastlane/srd-web-sdk/src/master/README.md
- Issues: https://bitbucket.org/ballastlane/srd-web-sdk/issues
- npm.io page: https://npm.io/package/srd-web-sdk-demo

## Dependencies (4)

- [@types/node](https://npm.io/package/@types/node.md) ^12.20.55
- [ts-standard](https://npm.io/package/ts-standard.md) ^12.0.2
- [@vladmandic/face-api](https://npm.io/package/@vladmandic/face-api.md) ^1.7.12
- [@tensorflow-models/coco-ssd](https://npm.io/package/@tensorflow-models/coco-ssd.md) ^2.2.3

## Recent versions

- 1.0.12 (latest) — 2023-10-30
- 1.0.11 — 2023-10-20
- 1.0.9 — 2023-10-18
- 1.0.7 — 2023-10-18
- 1.0.6 — 2023-10-18
- 1.0.5 — 2023-10-18
- 1.0.4 — 2023-10-17
- 1.0.3 — 2023-10-17
- 1.0.2 — 2023-10-12
- 1.0.1 — 2023-09-28
- 1.0.0 — 2023-09-28

## README

---
slug: web-getting-started
title: Getting Started with JavaScript
authors: [bla]
tags: [JavaScript, usage]
---

## Installation
```npm i https://bitbucket.org/ballastlane/srd-web-sdk/src/master/```

Once installed, copy the `dist/model` folder to you project's `public` or `assets` folder.

### Initialization
Initialize the sdk with your apiKey, which is used to persist and retrieve the emitted events. 
Without a valid API key, the SDK will emit errors when attempting to persist the events.
```typescript
import { FYFOFaceTracker, FYFOFace, FYFOTrackingEventPublisher, FYFOTrackingEvent } from 'fyfo-web-sdk'
const sdk = new FYFOFaceTracker('apiKey')
```

### Setting up the Camera
```typescript
const video: HTMLVideoElement = document.getElementById("my-video")
const constraints = {
    audio: false,
    video: {
        facingMode: "user",
        resizeMode: "crop-and-scale",
        width: video.width,
        height: video.height,
    },
};
video.srcObject  = await navigator.mediaDevices.getUserMedia(constraints);

video.onloadeddata = async () => {
    video.play()
}

```

### Add Face

The primary purpose of `FYFOFaceTracker` is to identify a face which can be added to the tracker using the `addFace` method. This method accepts a `FYFOFace` object, and returns a promise.
The added face is considered authorized when the the model starts the loop and emits events.

```typescript
//1. Get an HTMLVideoElement or HTMLCanvasElement
const imageRef: HTMLImageElement = document.getElementById('my-image')

// 2. Create a FYFOFace
const face: FYFOFace = new FYFOFace('id_01', [imageRef])

// 3. Get back the same FYFOFace with a Float32Array of descriptors from the model 
const faceDescriptor: FYFOFace = await sdk.addFace(face)
```

### Start recognition and tracking

With one or more added faces, begin the recognition loop with the `start` method
```typescript

    const videoRef = document.getElementById('my-video')

    const emitter: FYFOTrackingEventPublisher = sdk.start({ cameraSelector: videoRef })

    emitter.addEventListener("data", (event) => {
        const evt = event.detail as FYFOTrackingEvent
        console.log(evt)
    })

    emitter.addEventListener("error", (err) => {
        console.log(err.detail)
    })

    // ...
    sdk.stop()
```

---
_Source: https://npm.io/package/srd-web-sdk-demo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
