Skip to content

Commit

Permalink
Adds docs
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Sep 11, 2021
1 parent 76f9f04 commit 809d00c
Show file tree
Hide file tree
Showing 12 changed files with 1,997 additions and 56 deletions.
31 changes: 31 additions & 0 deletions .scripts/docs-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!
"use strict";
const jsdoc2md = require("jsdoc-to-markdown");
const fs = require("fs");
const path = require("path");

/* input and output paths */
const inputFile = path.join(__dirname, "../dist/*.js");
const outputDir = path.join(__dirname, "../docs");

/* get template data */
const templateData = jsdoc2md.getTemplateDataSync({ files: inputFile });

/* reduce templateData to an array of class names */
const classNames = templateData.reduce((names, identifier) => {
if (identifier.kind === "class") names.push(identifier.name);
return names;
}, []);

/* create a documentation file for each class */
for (const className of classNames) {
// Workaround an issue with the inputFile picking up wrong classes
if (["Scanner", "Walker", "Parser", "Filter"].includes(className)) continue;
const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`;
console.log(`rendering ${className}, template: ${template}`);
const output = jsdoc2md.renderSync({
data: templateData,
template: template
});
fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output);
}
158 changes: 149 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,153 @@
# WPhone
<a name="WPhone"></a>

The very begining of Fonoster WPhone.
## WPhone
WPhone is a basic SIP useragent you can use to create web based softphones.
It uses [SIP.js](sipjs.com) as the foundation, but aims to be much easier for simple uses-cases.

Usage:
Simply create an HTMLAudioElement, in your html code, give it an `id` and use it to create your WPhone object.
See `src/examples.ts` for an implementation example.

```bash
git clone https://github.com/fonoster/wphone
cd wphone
npm i
npm run build
npm run start:unsecured
> Thanks to the folks at [onsip.com](onsip.com) for such an amazing job with SIP.js
**Kind**: global class

* [WPhone](#WPhone)
* [new WPhone(config)](#new_WPhone_new)
* [.call(request)](#WPhone+call)
* [.hangup()](#WPhone+hangup)
* [.connect(register)](#WPhone+connect)
* [.reconnect()](#WPhone+reconnect)
* [.disconnect()](#WPhone+disconnect)
* [.isConnected()](#WPhone+isConnected)
* [.sendDtmf(tones)](#WPhone+sendDtmf)
* [.sendMessage(request)](#WPhone+sendMessage)
* [.on()](#WPhone+on)

<a name="new_WPhone_new"></a>

### new WPhone(config)
Constructs a new WPhone object.


| Param | Type | Description |
| --- | --- | --- |
| config | <code>WPhoneConfig</code> | Configuration object for WPhone |
| config.displayName | <code>string</code> | Optional friendly name to send to the receiver endpoint |
| config.domain | <code>string</code> | Domain or host for the user agent account |
| config.username | <code>string</code> | Username for authentication |
| config.secret | <code>string</code> | Password for authentication |
| config.server | <code>string</code> | Signaling server |
| config.audioElementId | <code>string</code> | HTML element to connect the audio to |
| config.extraHeaders | <code>Array.&lt;string&gt;</code> | Optional headers |
| config.expires | <code>string</code> | Expiration for register requests |

**Example**
```js
const WPhone = require("wphone");

const wpconfig = {
displayName: "John Doe",
domain: "sip.acme.com",
username: "john",
secret: "changeit"
audioElementId: "remoteAudio",
secret: "ws://yoursignalingserver:5062"
extraHeaders: ["X-Extra-Header: 'extra header'"]
}

phone = new WPhone(wpconfig);
await phone.connect();
await phone.call({
targetAOR: "sip:1001@sip.domain.net",
extraHeaders: ["X-Extra-Header: 'more extra headers'"]
});
```
<a name="WPhone+call"></a>

### wPhone.call(request)
Calls another SIP endpoint.

**Kind**: instance method of [<code>WPhone</code>](#WPhone)

| Param | Type | Description |
| --- | --- | --- |
| request | <code>CallRequest</code> | Request for SIP invite |
| request.targetAOR | <code>string</code> | Address of Record of receiving endpoint |
| request.extraHeaders | <code>Array.&lt;string&gt;</code> | Optional headers |

**Example**
```js
await phone.connect();
await phone.call({
targetAOR: "sip:1001@sip.domain.net"
});
```
<a name="WPhone+hangup"></a>

### wPhone.hangup()
Closes the session.

**Kind**: instance method of [<code>WPhone</code>](#WPhone)
<a name="WPhone+connect"></a>

### wPhone.connect(register)
Connects to signaling server and optionally register too.

**Kind**: instance method of [<code>WPhone</code>](#WPhone)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| register | <code>boolean</code> | <code>false</code> | If set to `true` it will also register the endpoint |

<a name="WPhone+reconnect"></a>

### wPhone.reconnect()
Reconnects to signaling server.

**Kind**: instance method of [<code>WPhone</code>](#WPhone)
<a name="WPhone+disconnect"></a>

### wPhone.disconnect()
Closes connection to signaling server.

**Kind**: instance method of [<code>WPhone</code>](#WPhone)
<a name="WPhone+isConnected"></a>

### wPhone.isConnected()
Returns `true` if the wphone is connected to WS or WSS server.

**Kind**: instance method of [<code>WPhone</code>](#WPhone)
<a name="WPhone+sendDtmf"></a>

### wPhone.sendDtmf(tones)
Sends a DTMF tones to another SIP endpoint.

**Kind**: instance method of [<code>WPhone</code>](#WPhone)

| Param | Type | Description |
| --- | --- | --- |
| tones | <code>string</code> | Tones to send |

<a name="WPhone+sendMessage"></a>

### wPhone.sendMessage(request)
Sends a SIP message to another SIP endpoint.

**Kind**: instance method of [<code>WPhone</code>](#WPhone)

| Param | Type | Description |
| --- | --- | --- |
| request | <code>MessageRequest</code> | Request to send SIP message |

<a name="WPhone+on"></a>

### wPhone.on()
Fires user agents events.
Events:
- invite
- message
- hangup
- error
- disconnect

**Kind**: instance method of [<code>WPhone</code>](#WPhone)
1 change: 0 additions & 1 deletion dist/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/utils.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 28 additions & 10 deletions dist/wphone.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,38 @@ import { CallRequest, MessageRequest, WPhoneConfig } from "./types";
import { Inviter, Registerer, SessionDescriptionHandler, UserAgent } from "sip.js";
import Events from "events";
/**
* @classdesc WPhone is a basic user agent you can use to build more
* complex WebRTC solutions.
* @classdesc WPhone is a basic SIP useragent you can use to create web based softphones.
* It uses [SIP.js](sipjs.com) as the foundation, but aims to be much easier for simple uses-cases.
*
* Simply create an HTMLAudioElement, in your html code, give it an `id` and use it to create your WPhone object.
* See `src/examples.ts` for an implementation example.
*
* > Thanks to the folks at [onsip.com](onsip.com) for such an amazing job with SIP.js
*
* @example
* const WPhone = require("wphone");
* phone = new WPhone({...});
*
* const wpconfig = {
* displayName: "John Doe",
* domain: "sip.acme.com",
* username: "john",
* secret: "changeit"
* audioElementId: "remoteAudio",
* secret: "ws://yoursignalingserver:5062"
* extraHeaders: ["X-Extra-Header: 'extra header'"]
* }
*
* phone = new WPhone(wpconfig);
* await phone.connect();
* phone.call({
* targetAOR: "sip:1001@sip.domain.net"
* await phone.call({
* targetAOR: "sip:1001@sip.domain.net",
* extraHeaders: ["X-Extra-Header: 'more extra headers'"]
* });
*/
export default class WPhone {
audioElement: HTMLAudioElement;
userAgent: UserAgent;
events: Events;
connected: boolean;
registerer: Registerer;
inviter: Inviter;
sessionDescriptionHandler: SessionDescriptionHandler;
Expand Down Expand Up @@ -46,7 +62,7 @@ export default class WPhone {
* @example
*
* await phone.connect();
* phone.call({
* await phone.call({
* targetAOR: "sip:1001@sip.domain.net"
* });
*/
Expand All @@ -57,18 +73,20 @@ export default class WPhone {
hangup(): void;
/**
* Connects to signaling server and optionally register too.
*
* @param {boolean} register - If set to `true` it will also register the endpoint
*/
connect(register?: boolean): Promise<void>;
/**
* Reconnects to signaling server.
*/
reconnect(): Promise<void>;
/**
* Clsoses connection to signaling server.
* Closes connection to signaling server.
*/
disconnect(): void;
/**
* Returns true if the wphone is connected to WS or WSS server.
* Returns `true` if the wphone is connected to WS or WSS server.
*/
isConnected(): boolean;
/**
Expand All @@ -80,7 +98,7 @@ export default class WPhone {
/**
* Sends a SIP message to another SIP endpoint.
*
* @param {MessageRequest} request - Request for SIP message
* @param {MessageRequest} request - Request to send SIP message
*/
sendMessage(request: MessageRequest): void;
/**
Expand Down
38 changes: 28 additions & 10 deletions dist/wphone.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 809d00c

Please sign in to comment.