# ION PHONER JS

### Enhance Your Business Communication Productivity and Efficiency with Our Softphone and PBX Service
### *Experience the Ease of Unrestricted Communication*

In today's digital age, effective and efficient communication is the cornerstone of running a successful business. Our softphone and PBX service is here to help you achieve that.

[![npm version](https://img.shields.io/npm/v/ion-phoner-js.svg?style=flat-square)](https://www.npmjs.org/package/ion-phoner-js)
![npm bundle size](https://img.shields.io/bundlephobia/min/ion-phoner-js?style=flat-square)
[![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hy/ion-phoner-js?style=flat-square)](https://www.jsdelivr.com/package/npm/ion-phoner-js)
![NPM License](https://img.shields.io/npm/l/ion-phoner-js?style=flat-square)
[![Static Badge](https://img.shields.io/badge/Docs-ION_PHONE-blue?style=flat-square)](https://ion-phone.vercel.app/)

### Benefits of Using Softphone and PBX Service
1.  **Boost productivity**

    Softphones empower you to make phone calls from anywhere, anytime, using any device connected to the internet. This allows you to stay connected with your team and your customers, even when you're on the go.

2.  **Enhance efficiency**

    PBX can automate many phone tasks, such as call forwarding, auto-attendants, and conferencing. This can save you time and money.

3.  **Reduce costs**

    Softphones and PBX can help you save money on phone bills by reducing long-distance call charges and phone hardware rental fees.

4.  **Increase scalability**

    Softphones and PBX can easily scale to meet the growing needs of your business.

### Key Features of Our Softphone and PBX Service

1. **HD voice quality**

    Enjoy crystal-clear and interference-free voice quality.

2. **Comprehensive calling features**

    Make voice and video calls, send instant messages, and host conferences.

3. **CRM integration**

    Integrate your softphone with your CRM to easily access customer information.

4. **Monitoring and reporting**

    Monitor your call activity and get detailed reports on phone usage.



### 1. Installation
`npm install ion-phoner-js`

**Example usage:**

```js

import IonPhoner from "ion-phoner-js";

const opt = {
    credential: { host : 'https://example.com', 
                  token : 'example-token', 
                  userkey :'example-user'
                 },
    config: {
        dom: {
            localVideo: document.querySelector('#localVideo') as HTMLElement,
            remoteVideo: document.querySelector('#remoteVideo') as HTMLElement,
        }
    }
};

const phoner = new IonPhoner(opt);
```
<br/>

Make sure you have HTML elements with the IDs `localVideo` and `remoteVideo` in your `index.html` file or DOM.

```html
<video id="localVideo" autoplay></video>
<video id="remoteVideo" autoplay></video>
```

## 2. Connection

After initialization, call the `connect()` method to establish a connection to the server. The connection status will be updated via the `isConnected` variable.

```typescript
let isConnected = false;

phoner.connect().then((e: any) => {
console.log('connect status', e);
isConnected = e?.status ?? false;
});
```

## 3. Event Handling

You can listen to various events emitted by the `phoner` object to monitor the connection and registration status.

```typescript
phoner.on('connection-status', (e: any) => {
console.log('connection-status', e);
});

phoner.on('registration-status', (e: any) => {
console.log('registration-status', e);
});
```

## 4. Main Functions

The following functions are available in the `phoner` object for managing calls and status. Ensure `isConnected` is `true` before calling these functions.

### 4.1. `register()`

Registers a user to the phoner service.

```typescript
function register() {
if (isConnected) phoner.register();
}
```

### 4.2. `unregister()`

Unregisters a user from the phoner service.

```typescript
function unregister() {
if (isConnected) phoner.unregister();
}
```

### 4.3. `hangup()`

Ends an ongoing call.

```typescript
function hangup() {
if (isConnected) phoner.hangup();
}
```

### 4.4. `hold()`

Puts a call on hold.

```typescript
function hold() {
if (isConnected) phoner.hold();
}
```

### 4.5. `unhold()`

Cancels a call on hold.

```typescript
function unhold() {
if (isConnected) phoner.unhold();
}
```

### 4.6. `answer()`

Answers an incoming call.

```typescript
function answer() {
if (isConnected) phoner.answer();
}
```

### 4.7. `mute()`

Mutes the microphone.

```typescript
function mute() {
if (isConnected) phoner.mute();
}
```

### 4.8. `unmute()`

Unmutes the microphone.

```typescript
function unmute() {
if (isConnected) phoner.unmute();
}
```

### 4.9. `dtmf(num: string)`

Sends a DTMF (Dual-Tone Multi-Frequency) tone.

```typescript
function dtmf(num: string) {
if (isConnected) phoner.dtmf(num);
}
```

### 4.10. `dial()`

Initiates a call to the specified phone number.

```typescript
function dial() { 
const phone = (document.querySelector('#phone') as HTMLInputElement | null)?.value ?? ''; 

const call = phoner.call(phone); 

console.log('call', call);
}
```

Make sure you have an HTML element with the ID `phone` which is the input for the phone number.

```html
<input type="text" id="phone" placeholder="Enter phone number">
<button onclick="dial()">Call</button>
```


<br/>
<div align="center" style="text-align:center; align:center; margin:0 auto">
    Presented By:
<br/>
<a href="https://ion-phone.vercel.app/" target="_blank">
<img src="https://ion-smile.vercel.app/profile.png" width=100/>
</a>
<br/>
<strong>Limitless Developer</strong>
</div>