cordova-plugin-docline-sdkdeprecated

Cordova Docline Video SDK Plugin

Usage no npm install needed!

<script type="module">
  import cordovaPluginDoclineSdk from 'https://cdn.skypack.dev/cordova-plugin-docline-sdk';
</script>

README

Cordova Docline SDK plugin

This plugin for Cordova and Ionic app, allows you to use the Docline SDK.

The Docline SDK makes it easy and simple to integrate Docline video consultation services.

This app needs access to the camera and microphone to make video consultations.

Supported Platforms

  • iOS 11.0 or higher
  • Android (Coming soon)

Installation

The plugin can be installed via Cordova-CLI and is publicly available on NPM.

Execute from the project's root folder:

Cordova

$ cordova plugin add cordova-plugin-docline-sdk

Ionic Cordova

$ ionic cordova plugin add cordova-plugin-docline-sdk

Ionic Capacitor

$ npm install cordova-plugin-docline-sdk

Removing the Plugin from the project

Using cordova Cordova-CLI.

Execute from the project's root folder:

Cordova

$ cordova plugin rm cordova-plugin-docline-sdk

Ionic Cordova

$ ionic cordova plugin rm cordova-plugin-docline-sdk

Ionic Capacitor

$ npm uninstall cordova-plugin-docline-sdk

Usage

The plugin creates the object docline and is accessible after the deviceready event has been fired.

document.addEventListener('deviceready', function () {
    // docline is now available
}, false);

The plugin includes the DoclineSDK class for its use in Ionic.

You need to add this line to use it.

import docline from 'cordova-plugin-docline-sdk';

Core Module

Purpose: Generic and miscellaneous functionality.

Remember you can customize the permissions description if needed.

join()

This method works async. It allows us to connect to the Docline video consultation with the video consultation code.

Parameters

  • { String } code - The video consultation code

Example usage

/**
 * Set Listener
 * @param {String} code - The code param is the video consultation code
 * @param {String} path - The path param is the api url
 * 
 */	
    docline.join(code, path);

If no error occurrs, we will connect to the video consultation. In both cases events will be emitted, if we want to be notified we will have to subscribe to the event.

Example usage


function onClick() {
    let code = document.getElementById("code").value;
    
    let eventId = docline.EventId.consultationJoinSuccess;
    docline.addEventListener(eventId, consultationJoinSuccess);
    let apiURL = "https://api-url";
    docline.join(code);
}

function consultationJoinSuccess() {
    console.log("consultationJoinSuccess event");
}

Error Module

Purpose: Manage the errors that the join method can return.

Error Type

Definition

/**
 * Error Types
 */
const ErrorType = { 
    unauthorizedError: "unauthorizedError", 
    emptyCodeError: "emptyCodeError", 
    connectionError: "connectionError", 
    customError: "customError", 
    defaultError: "defaultError" 
};

setHandleError()

Sets a listener to handle errors.

Parameters

  • { error: { type: String, message: String? } ) => void } handleError - The error handler
    • { String } type - The error type
    • { String } message - The customError message

Example usage

function configureHandleError() {    
    docline.setHandleError(handleError);
}

function handleError(error) {
    console.log(`type: ${error.type}`);
    let types = docline.error.ErrorType;
    switch (error.type) {
        case types.unauthorizedError:
            // code
            break;
        case types.emptyCodeError:
            // code
            break;
        case types.connectionError:
            // code
            break;
        case types.customError:
            console.log(`customError(${error.message})`);
            break;
        case types.defaultError:
            // code
            break;
        default: 
            break;
    }    
}

Events Module

Purpose: Manage the events that are emitted in the background, while the plugin is running.

The events have been grouped into five groups:

  • General Events.
  • Recording Events.
  • Connection Events.
  • Participant Events.
  • Chat Events.

Event Consts

Event Id

Definition
/**
 * General Event Id
 */
const EventId = {
    // General Events
    consultationJoinSuccess: "consultationJoinSuccess", 
    consultationTerminated: "consultationTerminated", 
    showScreenView: "showScreenView", 
    updatedCameraSource: "updatedCameraSource", 
    updatedCameraStatus: "updatedCameraStatus",
    updatedMicrophone: "updatedMicrophone",		
    consultationJoined: "consultationJoined",
    // Recording Events
    screenRecordingStarted: "screenRecordingStarted", 
    screenRecordingFinished: "screenRecordingFinished", 
    screenRecordingApproved: "screenRecordingApproved", 
    screenRecordingDenied: "screenRecordingDenied",
    // Connection Events
    consultationReconnecting: "consultationReconnecting", 
    consultationReconnected: "consultationReconnected", 
    discconectedByError: "discconectedByError",
    userSelectExit: "userSelectExit",
    userTryReconnect: "userTryReconnect",
    // Participant Events
    participantConnected: "participantConnected", 
    participantDisconnected: "participantDisconnected", 
    participantSelected: "participantSelected",
    // Chat Events
    messageSent: "messageSent", 
    messageReceived: "messageReceived"
};

Screen Id

Definition
/**
 * Screen Id
 */
const ScreenId = { 
    setupScreen: "setupScreen", 
    waitingRoom: "waitingRoom", 
    videoConsultation: "videoConsultation", 
    permissionsScreen: "permissionsScreen"
};

Camera Source

Definition
/**
 * Camera Source
 */
const CameraSource = { 
    front: "front", 
    back: "back"
};

Participant Type

Definition
/**
 * Participant Type
 */
const ParticipantType = {
    camera: "camera", 
    screen: "screen"
};

addEventListener()

Sets a listener for the indicated event.

Parameters

  • { String } eventId - The event id
  • { (data: { eventId: string, screenId: string?, cameraSource: string?, isEnabled: Boolean? }) => void } listener - The event listener

Example usage

function configureListener() {
    let eventId = docline.EventId.consultationJoinSuccess;
    docline.addEventListener(eventId, consultationJoinSuccess);

    let eventId2 = docline.EventId.showScreenView;
    docline.addEventListener(eventId2, showScreenView);

    let eventId3 = docline.EventId.updatedCameraSource;
    docline.addEventListener(eventId3, updatedCameraSource);

    let eventId4 = docline.EventId.updatedCameraStatus;
    docline.addEventListener(eventId4, updatedCameraStatus);

    let eventId5 = docline.EventId.participantConnected;
    docline.addEventListener(eventId5, participantConnected);
}

// Listeners

function consultationJoinSuccess(event) {
    console.log(`{eventId: ${event.eventId}}`);
}

function showScreenView(event) {
    console.log(`{eventId: ${event.eventId}, screenId: ${event.screenId}}`);
}

function updatedCameraSource(event) {
    console.log(`{eventId: ${event.eventId}, cameraSource: ${event.cameraSource}}`);
}

function updatedCameraStatus(event) {
    console.log(`{eventId: ${event.eventId}, isEnabled: ${event.isEnabled}}`);
}

function participantConnected(event) {
    console.log(`{eventId: ${event.eventId}, type: ${event.type}}`);
}

General Events

consultationJoinSuccess

Sent when the join() method completes execution without errors.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

consultationTerminated

Sent when the query has finished, this will release the native component.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

consultationJoined

Sent upon entering the waiting room.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

showScreenView

Sent when a screen loads and indicates the screen is loaded.

Parameters

  • { eventId: String, screenId: String } event - The event data
    • { String } eventId - The event id
    • { String } screenId - The screen id where the event occurred

updatedCameraSource

Sent when the source of the camera (front or back) is modified and indicates the screen that generated the event.

Parameters

  • { eventId: String, screenId: String } event - The event data
    • { String } eventId - The event id
    • { String } screenId - The screen id where the event occurred
    • { String } cameraSource - The source of the selected camera

updatedCameraStatus

Sent when the status of the camera is modified (enabled or disabled) and indicates the screen that generated the event.

Parameters

  • { eventId: String, screenId: String } event - The event data
    • { String } eventId - The event id
    • { String } screenId - The screen id where the event occurred
    • { Boolean } isEnabled - Indicates whether the camera has been enabled or disabled

updatedMicrophone

Sent when the status of the microphone is modified (enabled or disabled) and indicates the screen that generated the event.

Parameters

  • { eventId: String, screenId: String } event - The event data
    • { String } eventId - The event id
    • { String } screenId - The screen id where the event occurred
    • { Boolean } isEnabled - Indicates whether the microphone has been enabled or disabled

 

Recording Events

screenRecordingStarted

Sent when the video consultation recording begins. The SDK will automatically ask for user consent and nothing will be recorded until accepted. If the user doesn´t agree, they can exit.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

screenRecordingFinished

Sent when the video consultation recording is finished.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

screenRecordingApproved

Sent when the user accepts the consent of the recording.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

screenRecordingDenied

Sent when the user does not accept the consent of the recording.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

 

Connection Events

consultationReconnecting

Sent when the connection is lost and the plugin tries an automatic recovery.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

consultationReconnected

Sent after the launch of consultationReconnecting event, if the connection is recovered.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

discconectedByError

Sent after the launch of the consultationReconnecting event, if the connection isn´t recovered.

The SDK will automatically ask users if they want to retry the reconnection or want to exit the video consultation.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

userSelectExit

Sent after the launch of the discconectedByError event, if the user decides to exit the video consultation.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

userTryReconnect

Sent after the launch of the discconectedByError event, if the user decides to attempt the reconnection.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

 

Participant Events

participantConnected

Sent when a new participant is connected, this participant can be of camera or screen type.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id
    • { String } type - The participant type, can be camera or screen

participantDisconnected

Sent when a participant disconnects, it can be of camera or screen type.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id
    • { String } type - The participant type, can be camera or screen

participantSelected

Sent when a participant is selected in the list of participants, this participant can be of camera or screen type. The selected participant will go to the main screen of the video consultation.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id
    • { String } type - The participant type, can be camera or screen

 

Chat Events

messageSent

Sent when a message is sent in chat.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id

messageSent

Sent when a message is received in the chat.

Parameters

  • { eventId: String } event - The event data
    • { String } eventId - The event id