1.9.1 • Published 2 months ago

ng112-js v1.9.1

Weekly downloads
-
License
AGPL-3.0-only
Repository
github
Last release
2 months ago

ng112-js - Next Generation Emergency Services

This javascript library should help integrating browser and node environments with existing NG112 or DEC112 infrastructure and covers standards ETSI TS 103 479 and ETSI TS 103 698, as well as DEC112 specific additions for text based emergency messages/calls.

It handles SIP communication, message types, heartbeats, PIDF-LO, VCards, Multipart MIME and should finally provide a comprehensive implementation of the aformentioned ETSI standards.

Please keep in mind this library is still in development and does not cover standards entirely!

SIP communication can be handeled by a SIP stack of your choice. \ By default, ng112-js comes with adapters for:

If you want to write your own adapter, take a look at one of the linked adapters to get an idea how they are implemented.

License: GNU AGPL-3.0 \ Proprietary licenses are available on request. \ Maintainer: Gabriel Unterholzer (gabriel.unterholzer@dec112.at)

Installation

npm install ng112-js

In addition, you will also have to install one of the available SIP adapters. \ Let's use the JsSIP adapter in this example:

npm install ng112-js-sip-adapter-jssip

Please also note the install requirements of the respective SIP adapters (README.md) \ ng112-js-sip-adapter-jssip will need an additional package, if it is used in node.js environments!

Usage

ng112-js implementation slightly differs in node.js or browser environments. \ E.g. in browser environments there is a native XMLDom implementation that is lacking in node.js.

Therefore, there are separate builds for node.js and browser environments.

Browser Environments

import * from 'ng112-js/dist/browser';

Node Environments

import * from 'ng112-js/dist/node';

Examples

Most complete examples can be found in both browser and node example projects in ./example/browser and ./example/node.

Examples of specific use-cases can be found in ./example/snippets.

Use as a calling device (e.g. in a smartphone app)

import { 
  Agent,
  DEC112Specifics,
  LocationMethod,
  VCard,
} from 'ng112-js/dist/browser';
import { 
  SipJsAdapter, 
} from 'ng112-js-sip-adapter-sipjs';

// define connection to SIP proxy (originating ESRP)
const agent = new Agent({
  sipAdapterFactory: SipJsAdapter.factory,
  endpoint: 'wss://example.com',
  domain: 'example.com',
  user: 'user1234',
  password: 'supersecretpassword',
  // ETSI TS 103 698: optional
  // DEC112: required. Must be set with a verified telephone number, due to legal requirements
  displayName: '004366412345678',
  // DEC112: required. Used to specify additional properties for DEC112 environments
  // either device id or registration id is required
  // in ETSI TS 103 698 environments, `namespaceSpecifics` must not be specified
  namespaceSpecifics: new DEC112Specifics({
    // registration id (registration API version 2)
    registrationId: 'registrationId',
    // user device language (ISO639-1 two letter language code; optional)
    langauge: 'en',
    // client version (e.g. version of application, where ng112-js is used in; optional)
    clientVersion: '1.0.4',
  }),
  // If `debug` is set to `true`, verbose log messages will be printed to the console
  // If `debug` is set to a callback, this callback will be called for each debug statement
  debug: false,
});

// set the agent's vcard
// this function can be called anytime and will be reflected by any conversation sent through this agent
agent.updateVCard(new VCard()
  .addFullName('Default Person')
  .addBirthday(new Date(1990, 1, 1))
  .addGender(Gender.OTHER)
  .addStreet('Example street 13')
  .addTelephone('0123456789')
  .addEmail('default.person@example.com')
);

// set the agent's location
// this function can be called anytime and will be reflected by any conversation sent through this agent
agent.updateLocation({
  latitude: 48.1799778,
  longitude: 16.341437,
  radius: 15,
  method: LocationMethod.GPS,
});

// initializes the agent (sends initial SIP REGISTER)
await agent.initialize();

// start a new emergency conversation ("call")
const conversation = agent.createConversation('sip:144@dec112.at');

// register a callback for *both* incoming and outgoing messages
conversation.addMessageListener((msg) => {
  // print message metadata
  console.log(`${msg.origin} (${msg.type}): ${msg.text}`);
});

// initiate the emergency conversation
// sends the initial START message to the ESRP
const startMsg = conversation.start({
  text: 'This is an emergency call initiated by ng112-js',
});

// `await`ing the promise ensures the message was successfully forwarded by the SIP proxy
await startMsg.promise;

const chatMsg = conversation.sendMessage({
  text: 'My kitchen is burning!',
});
await chatMsg.promise;

// stop the emergency conversation
// sends the STOP message to the ESRP
const stopMsg = conversation.stop();
await stopMsg.promise;

// dispose the agent
await agent.dispose();

Use as a PSAP (e.g. in a node application)

import { 
  Agent,
  ConversationState,
} from 'ng112-js/dist/node';
import { 
  JsSipAdapter, 
} from 'ng112-js-sip-adapter-jssip/dist/node';

// define connection to SIP proxy (terminating ESRP)
const agent = new Agent({
  sipAdapterFactory: JsSipAdapter.factory,
  endpoint: 'wss://example.com',
  domain: 'example.com',
  user: 'psap1',
  password: 'supersecretpassword',
});

// initializes the agent (sends initial SIP REGISTER)
await agent.initialize();

// listen for incoming conversations
agent.addConversationListener((conversation) => {
  const { created, id, requestedUri, targetUri } = conversation;

  // print some conversation metadata
  console.log(
    created,
    id,
    requestedUri,
    targetUri,
  );

  // print already sent messages
  conversation.messages.forEach(msg => console.log(msg.text));

  // register a callback for *both* incoming and outgoing messages
  conversation.addMessageListener((msg) => {
    // print message metadata
    console.log(`${msg.origin} (${msg.type}): ${msg.text}`);

    const {
      vcard,
      location,
    } = msg;

    // print some VCard information, if available
    if (vcard)
      console.log(
        vcard.firstname,
        vcard.lastname,
        vcard.birthday,
      );

    // print location information, if available
    if (location) {
      // `location` is of type PidfLo
      // for easier access there is a simplified location object
      // however this simple object might not contain all information transmitted through PidfLo
      const simpleLoc = location.simple;
      console.log(
        simpleLoc.latitude,
        simpleLoc.latitude,
        simpleLoc.radius,
        simpleLoc.method,
      )
    }
  });

  // listen for conversation state updates
  conversation.addStateListener((stateObj) => {
    switch(stateObj.value) {
      case ConversationState.STOPPED:
        console.log('The emergency call has ended!');
        break;
      case ConversationState.ERROR:
        console.log('An error has happened!');
        break;        
    }
  });

  // send a message to the caller
  // NOTICE: according to TS 103 698 the PSAP is obliged to send an initial message in response to the caller's START message!
  const startMsg = conversation.sendMessage({
    text: 'Emergency control center. How can we help you?',
  });
  // `await`ing the promise ensures the message was successfully forwarded by the SIP proxy
  await startMsg.promise;

  // end the emergency call
  const stopMsg = conversation.stop({
    text: 'This conversation was ended by the control center.',
  });
  await stopMsg.promise;
});

Documentation

Documentation can be found at https://www.dec112.at/docs/ng112-js

Generate documentation by using the following command. It will be saved in folder ./docs

npm install
npm run docs

Local Build

npm install
npm run build

This project was bootstrapped with TSDX

2.0.0-dev.45

2 months ago

2.0.0-dev.41

6 months ago

2.0.0-dev.40

7 months ago

2.0.0-dev.43

6 months ago

2.0.0-dev.42

6 months ago

2.0.0-dev.44

6 months ago

1.9.1

9 months ago

1.9.0

9 months ago

1.8.2

9 months ago

2.0.0-dev.38.1

9 months ago

2.0.0-dev.38.2

9 months ago

2.0.0-dev.38.3

9 months ago

1.8.1

10 months ago

1.8.0

10 months ago

1.6.0

11 months ago

2.0.0-dev.32

12 months ago

2.0.0-dev.31

12 months ago

1.7.0

10 months ago

2.0.0-dev.34

12 months ago

2.0.0-dev.33

12 months ago

2.0.0-dev.36

12 months ago

2.0.0-dev.35

12 months ago

2.0.0-dev.38

12 months ago

2.0.0-dev.37

12 months ago

2.0.0-dev.39

10 months ago

1.4.0

1 year ago

2.0.0-dev.23

1 year ago

2.0.0-dev.25

1 year ago

2.0.0-dev.24

1 year ago

2.0.0-dev.27

1 year ago

2.0.0-dev.26

1 year ago

2.0.0-dev.29

1 year ago

2.0.0-dev.28

1 year ago

2.0.0-dev.30

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.3.0

1 year ago

2.0.0-dev.22

1 year ago

2.0.0-dev.21

1 year ago

2.0.0-dev.19

1 year ago

2.0.0-dev.20

1 year ago

2.0.0-dev.16

1 year ago

2.0.0-dev.18

1 year ago

2.0.0-dev.17

1 year ago

2.0.0-dev.15

1 year ago

2.0.0-dev.14

1 year ago

2.0.0-dev.13

1 year ago

2.0.0-dev.12

1 year ago

2.0.0-dev.10

1 year ago

2.0.0-dev.11

1 year ago

2.0.0-dev.9

1 year ago

2.0.0-dev.8

1 year ago

2.0.0-dev.7

1 year ago

2.0.0-dev.6

1 year ago

2.0.0-dev.5

1 year ago

2.0.0-dev.3

1 year ago

2.0.0-dev.4

1 year ago

2.0.0-dev.2

1 year ago

1.2.0

2 years ago

1.2.1

1 year ago

2.0.0-dev.1

1 year ago

1.1.0

2 years ago

1.0.0

2 years ago

0.11.20

2 years ago

0.11.21

2 years ago

0.11.19-dev.1

2 years ago

0.11.19

2 years ago

0.11.16

2 years ago

0.11.17

2 years ago

0.11.18

2 years ago

0.11.15

2 years ago

0.11.13

2 years ago

0.11.14

2 years ago

0.11.12

2 years ago

0.11.11

2 years ago

0.11.10

2 years ago

0.11.9

2 years ago

0.11.8

2 years ago

0.11.7-dev.3

2 years ago

0.11.7-dev.2

2 years ago

0.11.7-dev.1

2 years ago

0.11.6-dev.1

2 years ago

0.11.6

2 years ago

0.11.7

2 years ago

0.11.2

2 years ago

0.11.3

2 years ago

0.11.4

2 years ago

0.11.5

2 years ago

0.11.1

2 years ago

0.11.0

2 years ago

0.10.0

2 years ago