Reference12r1:Concept myPBX Toolbox: Difference between revisions

From innovaphone wiki
Jump to navigation Jump to search
Line 4: Line 4:
= Supported features =
= Supported features =
* Presence monitoring
* Presence monitoring
* Outgoind WebRTC calls with audio, video and application sharing
* Outgoing WebRTC calls with audio, video and application sharing


= Requirements =
= Requirements =

Revision as of 15:09, 13 December 2015

The myPBX toolkit is a set of Java Script files that can be used for integrating functionality of the innovaphone PBX into arbitrary web sites.

Supported features

  • Presence monitoring
  • Outgoing WebRTC calls with audio, video and application sharing

Requirements

Web site
  • The needed JavaScript files of the libraries have to be included in the web site.
PBX
  • User object with password for login and a WebRTC device
  • Call filters for that user object
  • Valid STUN/TURN configuration
Licenses
  • myPBX license
  • Video license (for video telephony)
  • Application Sharing license (for viewing shared applications)
  • WebRTC channel license (per WebRTC call)
Network

Authentication

For connecting the credentials of a PBX user account is needed.

Reference

innovaphone.pbxwebsocket.Connection

Includes

The following files have to be included in the html file in order to use the WebRTC endpoint.

  • innovaphone.common.crypto.js
  • innovaphone.pbxwebsocket.Connection.js

Constructor

new Connection(url, username, password)
url
The URL of the PBX websocket service (e.g. ws://10.0.0.1/PBX0/WEBSOCKET/websocket)
username
The username of the PBX user object.
password
The password of the PBX user object.

Methods

function close()
Disconnects from the PBX.
function sendSubscribeEndpoint(name, number)
Starts presence monitoring for a given endpoint specifyed by name or number.
name
The URI or H.323 id
number
The phone number
function sendUnsubscribeEndpoint(name, number)
Stops presence monitoring for a given endpoint specifyed by name or number.
name
The URI or H.323 id
number
The phone number

The methods for WebRTC calls are not described here. Use innovaphone.pbxwebsocket.WebRtcEndpoint.js instead.

Callbacks

function onconnected(userInfo)
Called when the connection has been successfully established.
userInfo
An object containing informmation about the connected user.
function onerror(error)
Called when the connection could not be established or an other error occurred.
error
A string containing an error message.
onclosed()
Called if the connection was closed.
function onendpointpresence(name, number, phoneStatus, imStatus, activity, note)
Called if the presence of a subscribed endpoint has changed.
name
The URI or H.323 id
number
The phone number
phoneStatus
Tells if a phone is registered, open or closed.
imStatus
Tells if a chat client is registered, open or closed.
activity
Presence activity away, busy, lunch, vacation, busy, dnd, on-the-phone
note
Presence note

The callbacks for WebRTC calls are not described here. Use innovaphone.pbxwebsocket.WebRtcEndpoint.js instead.

Example

The following example connects to the PBX and does presence monitoring for the user with the H.323 ID "target".

   <script type="text/javascript" src="innovaphone.common.crypto.js"></script>
   <script type="text/javascript" src="innovaphone.pbxwebsocket.Connection.js"></script>
   <script type="text/javascript">
      
       // dependencies
       var Connection = innovaphone.pbxwebsocket.Connection;
      
       // private
       var connection = null;
       var config = {
           url: "ws://192.168.0.1/PBX0/WEBSOCKET/websocket",
           username: "user",
           password: "password"
       };
      
       // callbacks
       function onConnected(userInfo) {
           console.log("Connected: " + JSON.stringify(userInfo));
           connection.sendSubscribeEndpoint("target", null);
       }
       
       function onError(error) {
           console.log("Error: " + error);
       }
       
       function onClosed() {
           console.log("Closed");
       }
       
       function close() {
           if (connection) connection.close();
           connection = null;
       }
       
       function onEndpointPresence(name, number, phoneStatus, imStatus, activity, note) {
           console.log("EndpointPresence: activity=" + activity + " note=" + note);
       }
      
       // main function
       function start() {
           if (connection) connection.close();
           connection = new Connection(config.url, config.username, config.password);
           connection.onconnected = onConnected;
           connection.onerror = onError;
           connection.onclosed = onClosed;
           connection.onendpointpresence = onEndpointPresence;
       }
      
   </script>

innovaphone.pbxwebsocket.WebRtcEndpoint

This file contains a WebRTC endpoint implementation that can be used for adding WebRTC calls to a web page. For that the credentials of a user object on the PBX is needed. Visitors of the web page will use that user object for making phone calls.

Includes

The following files have to be included in the html file in order to use the WebRTC endpoint.

  • innovaphone.common.crypto.js
  • innovaphone.pbxwebsocket.Connection.js
  • innovaphone.pbxwebsocket.ToneGenerator.js
  • innovaphone.pbxwebsocket.WebRtcEndpoint.js

If you want to use application sharing the following files must also be included:

  • innovaphone.applicationSharing.jpeg.js
  • innovaphone.applicationSharing.zlib.js
  • innovaphone.applicationSharing.png.js
  • innovaphone.applicationSharing.main.js

Additionally the MP3 files containing the ring tones and ring back tones are needed on the web server in the same directory as the javascript files.

Constructor

new WebRtcEndpoint(url, username, password, device, physicalLocation, regContext, onLog, onCall)
url
The URL of the PBX websocket service (e.g. ws://10.0.0.1/PBX0/WEBSOCKET/websocket)
username
The username of the PBX user object.
password
The password of the PBX user object.
device
The device ID that shall be used for making calls.
physicalLocation
The physical location of the user (optional).
regContext
A numeric value that will be used for identifying the registration in the PBX (optional).
logFunction
A callback function that is called for logging debug info (optional).
onCall
A callback function that is called when calls are added, updated or removed. Applications that want to use call control have to specify this callback function. Applications that don't should give null. (optional)

Methods

function close()
Closes the WebRTC endpoint and disconnects from the PBX.
function initCall(name, number, video, sharing)
Starts a phone call. This is only possible if the application supplied an onCall callback to the constructor.
name
The URI to be called (optional, supply name or number).
number
The phone number to be called (optional, supply name or number).
video
Set to true for starting a video call (optional).
sharing
Set to true for starting an application sharing call (optional).
function clearCall(id)
Terminates a call.
id
The ID of the call (optional). If no ID is supplied, all calls are terminated.
function attachVideo(local, remote)
Attaches HTML video elements to the WebRTC endpoints. The endpoint will use them to playback video. Applications can both attach before or during a video call. Also attaching multiple video elements for a single call is possible. The application should mute the video elements (muted="muted") in order to avoid playback of audio.
local
The HTML video element for playback of the local webcam image (optional, may be null).
remote
The HTML video element for playback of the remote video image (optional, may be null).
function detachVideo(local, remote)
Detaches HTML video elements that have previously attached. This will stop the playback on the supplied elements.
local
The HTML video element to be detached (optional, may be null).
remote
The HTML video element to be detached (optional, may be null).
function attachSharing(sharingDiv, createAppCallback, removeAppCallback)
Attaches a DIV element to the WebRTC endpoints. The endpoint will allocate inside this element a canvas object where the application sharing data will be displayed. Since more than one application could be shared, the javascript application has to provide a callback to be informed that a new application arrived and another callback to be informed that an application is not anymore shared. Both callbacks should received an id as argument.
createAppCallback
createAppCallback(id, name). This callback also receives the name of the new application.
removeAppCallback
removeAppCallback(id).
function detachSharing()
Detaches elements that were previously attached.
function sharingEvent(type, data)
The endpoint provides an interface to send events to the application sharing class.
changeDisplayApp
This event is used to switch inside the canvas object between applications being shared. type is equal to changeDisplayApp and data should be the id of the application to be displayed. This id is the one provided in the create application callback.
fitToElement
This event adjusts the application being shared to the size of the DIV element provided with the attachSharing function. type is equal to fitToElement and data should be true if the application should be adjusted to the canvas element or false otherwise (original size).
requestControl
This event allows the client to request control (mouse, keyboard) over the shared applications. The sharing party still must accept this request before the client gets the control. type is equal to requestControl and data should be null.

Callbacks

function onLog(text)
Should write the supplied text to the log of the application.
function onCall(event, call)
Is called when the state of calls of this WebRTC endpoint changes.
event
A string that can be added, updated and removed.
call
The call object containing the current info about the call.
id
The numeric id of the call.
dir
The direction of the call (in or out).
state
The state of the call (idle, calling, incomplete, complete, alerting, connected, disconnecting, disconnected, parked).
hold
true, if the call is on hold (optional).
name
The URI of the remote party (optional).
number
The phone number of the remote party (optional).
video
true, if video is active (optional).
sharing
true, if application sharing is active (optional).
cause
The cause code (optional).

Example

   <script type="text/javascript" src="innovaphone.common.crypto.js"></script>
   <script type="text/javascript" src="innovaphone.pbxwebsocket.Connection.js"></script>
   <script type="text/javascript" src="innovaphone.pbxwebsocket.ToneGenerator.js"></script>
   <script type="text/javascript" src="innovaphone.pbxwebsocket.WebRtcEndpoint.js"></script>
   <script type="text/javascript" src="innovaphone.applicationSharing.jpeg.js"></script>
   <script type="text/javascript" src="innovaphone.applicationSharing.zlib.js"></script>
   <script type="text/javascript" src="innovaphone.applicationSharing.png.js"></script>
   <script type="text/javascript" src="innovaphone.applicationSharing.main.js"></script>
   <script type="text/javascript">
       
       // dependencies
       var WebRtcEndpoint = innovaphone.pbxwebsocket.WebRtc.Endpoint;
      
       var endpoint = null;
       var config = {
           url: "ws://192.168.0.1/PBX0/WEBSOCKET/websocket",
           username: "user",
           password: "password",
           device: "user-webrtc",
           physicalLocation: null,
           regContext: "0"
       };
      
       function logFunction(text) {
           console.log("WebRTC demo: " + text);
       }
      
       function onCall(event, call) {
           if (call.dir == "in") {
               if (endpoint) endpoint.clearCall(call.id);
           }
           console.log("Call " + event + ": " + JSON.stringify(call));
       }
      
       function initCall(name, number, video, sharing) {
           if (endpoint) endpoint.initCall(name, number, video, sharing);
       }
      
       function clearAllCalls() {
           if (endpoint) endpoint.clearCall();
       }
      
       function close() {
           if (endpoint) {
               endpoint.detachVideo(document.getElementById("video-local"), document.getElementById("video-remote"));
               endpoint.detachSharing();
               endpoint.close();
           }
           endpoint = null;
       }
      
       function createNewApplication(id, name) {
           var new_app = document.createElement("input"); 
           new_app.setAttribute("id", "appSharing_" + id);
           new_app.setAttribute("value", name);
           new_app.setAttribute("type", "button");
           appendChild(new_app);
       }
      
       function removeApplication(id) {
           var input_b = document.getElementById("appSharing_" + id);
           if(input_b) removeChild(input_b);
       }
      
       function start() {
           if (endpoint) endpoint.close();
           endpoint = new WebRtcEndpoint(config.url, config.username, config.password, config.device, config.physicalLocation, config.regContext, logFunction, onCall);
           endpoint.attachVideo(document.getElementById("video-local"), document.getElementById("video-remote"));
           endpoint.attachSharing(document.getElementById("sharing-local"), createNewApplication, removeApplication);
       }
   </script>