@wazo/sdk 0.37.43 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wazo-sdk.js +1 -1
- package/esm/index.js +148 -0
- package/esm/simple/Auth.js +148 -0
- package/esm/simple/Configuration.js +148 -0
- package/esm/simple/Phone.js +148 -0
- package/esm/simple/Softphone.js +148 -0
- package/esm/simple/index.js +148 -0
- package/esm/simple/room/LocalParticipant.js +148 -0
- package/esm/simple/room/Participant.js +148 -0
- package/esm/simple/room/RemoteParticipant.js +148 -0
- package/esm/simple/room/Room.js +148 -0
- package/esm/simple/room/SipRoom.js +148 -0
- package/esm/simple/room/Stream.js +148 -0
- package/esm/simple/room/__tests__/RemoteParticipant.test.js +148 -0
- package/esm/simple/utils.js +148 -0
- package/lib/index.js +148 -0
- package/lib/simple/Auth.js +148 -0
- package/lib/simple/Configuration.js +148 -0
- package/lib/simple/Phone.js +148 -0
- package/lib/simple/Softphone.js +150 -0
- package/lib/simple/index.js +148 -0
- package/lib/simple/room/LocalParticipant.js +148 -0
- package/lib/simple/room/Participant.js +148 -0
- package/lib/simple/room/RemoteParticipant.js +148 -0
- package/lib/simple/room/Room.js +148 -0
- package/lib/simple/room/SipRoom.js +148 -0
- package/lib/simple/room/Stream.js +148 -0
- package/lib/simple/room/__tests__/RemoteParticipant.test.js +148 -0
- package/lib/simple/utils.js +148 -0
- package/package.json +1 -1
- package/src/simple/Softphone.js +148 -0
- package/src/simple/index.js +2 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
/* eslint-disable no-unused-vars */
|
|
3
|
+
/* global window, document */
|
|
4
|
+
const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
|
|
5
|
+
const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
|
|
6
|
+
const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
|
|
7
|
+
const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
|
|
8
|
+
const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
|
|
9
|
+
|
|
10
|
+
class Softphone {
|
|
11
|
+
url: string = 'https://softphone.wazo.io';
|
|
12
|
+
width: number = 500;
|
|
13
|
+
height: number = 600;
|
|
14
|
+
displayed: boolean = false;
|
|
15
|
+
iframe: ?Object = null;
|
|
16
|
+
|
|
17
|
+
onLinkEnabled(link: Object) {}
|
|
18
|
+
|
|
19
|
+
onCallMade(call: Object) {}
|
|
20
|
+
onCallIncoming(call: Object) {}
|
|
21
|
+
onCallEnded(call: Object, card: Object, direction: string, fromExtension: string) {}
|
|
22
|
+
onAuthenticated(session: Object) {}
|
|
23
|
+
|
|
24
|
+
init(url: string, width: number, height: number) {
|
|
25
|
+
if (url) {
|
|
26
|
+
this.url = url;
|
|
27
|
+
}
|
|
28
|
+
if (width) {
|
|
29
|
+
this.width = width;
|
|
30
|
+
}
|
|
31
|
+
if (height) {
|
|
32
|
+
this.height = height;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
window.addEventListener('message', this._onMessage.bind(this), false);
|
|
36
|
+
|
|
37
|
+
this._createIframe();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
parseLinks() {
|
|
41
|
+
const links = this._getLinks();
|
|
42
|
+
|
|
43
|
+
links.forEach(link => {
|
|
44
|
+
link.setAttribute('data-wazo-parsed', true);
|
|
45
|
+
link.addEventListener('click', this._onLinkClick.bind(this));
|
|
46
|
+
this.onLinkEnabled(link);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
makeCall(number: string) {
|
|
51
|
+
this.displaySoftphone();
|
|
52
|
+
|
|
53
|
+
if (this.iframe) {
|
|
54
|
+
this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
toggleSoftphoneDisplay() {
|
|
59
|
+
if (this.displayed) {
|
|
60
|
+
this.hideSoftphone();
|
|
61
|
+
} else {
|
|
62
|
+
this.displaySoftphone();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.displayed = !this.displayed;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
displaySoftphone() {
|
|
69
|
+
if (!this.iframe) {
|
|
70
|
+
this._createIframe();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (this.iframe) {
|
|
74
|
+
this.iframe.style.display = 'block';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
hideSoftphone() {
|
|
79
|
+
if (this.iframe) {
|
|
80
|
+
this.iframe.style.display = 'none';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
_createIframe() {
|
|
85
|
+
this.iframe = document.createElement('iframe');
|
|
86
|
+
// $FlowFixMe
|
|
87
|
+
this.iframe.width = this.width;
|
|
88
|
+
// $FlowFixMe
|
|
89
|
+
this.iframe.height = this.height;
|
|
90
|
+
// $FlowFixMe
|
|
91
|
+
this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
|
|
92
|
+
this.iframe.style.position = 'absolute';
|
|
93
|
+
this.iframe.style.left = '0';
|
|
94
|
+
this.iframe.style.bottom = '0';
|
|
95
|
+
this.iframe.style.border = '1px solid #aaa';
|
|
96
|
+
this.iframe.src = this.url;
|
|
97
|
+
this.iframe.style.display = 'none';
|
|
98
|
+
this.iframe.id = 'wazo-softphone';
|
|
99
|
+
|
|
100
|
+
// $FlowFixMe
|
|
101
|
+
document.body.appendChild(this.iframe);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_getLinks() {
|
|
105
|
+
return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
|
|
106
|
+
.filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_onLinkClick(e: Object) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
const number = e.target.href.split(':')[1];
|
|
112
|
+
|
|
113
|
+
this.makeCall(number);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_onAuthenticated() {
|
|
117
|
+
this.parseLinks();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
_onMessage(event: Object) {
|
|
121
|
+
if (!event.data) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
switch (event.data.type) {
|
|
126
|
+
case SDK_ON_CALL_MADE:
|
|
127
|
+
this.onCallMade(event.data.callSession);
|
|
128
|
+
break;
|
|
129
|
+
case SDK_CALL_ENDED: {
|
|
130
|
+
const { callSession, content, direction, userExtension } = event.data;
|
|
131
|
+
this.onCallEnded(callSession, content, direction, userExtension);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case SDK_CALL_INCOMING:
|
|
135
|
+
this.onCallIncoming(event.data.callSession);
|
|
136
|
+
break;
|
|
137
|
+
case SDK_AUTHENTICATED:
|
|
138
|
+
// $FlowFixMe
|
|
139
|
+
this._onAuthenticated(event.data.session);
|
|
140
|
+
this.onAuthenticated(event.data.session);
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default new Softphone();
|
package/src/simple/index.js
CHANGED
|
@@ -39,6 +39,7 @@ import IssueReporter from '../service/IssueReporter';
|
|
|
39
39
|
import Features from '../domain/Features';
|
|
40
40
|
import Meeting from '../domain/Meeting';
|
|
41
41
|
import Checker from '../checker/Checker';
|
|
42
|
+
import Softphone from './Softphone';
|
|
42
43
|
|
|
43
44
|
const Wazo = {
|
|
44
45
|
Auth,
|
|
@@ -58,6 +59,7 @@ const Wazo = {
|
|
|
58
59
|
loggerFor: IssueReporter.loggerFor.bind(IssueReporter),
|
|
59
60
|
Features,
|
|
60
61
|
Checker,
|
|
62
|
+
Softphone,
|
|
61
63
|
|
|
62
64
|
// Domain
|
|
63
65
|
domain: {
|