@94ai/nf-softphone 3.3.17
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/.eslintrc.cjs +49 -0
- package/README.md +11 -0
- package/components.d.ts +8 -0
- package/lib/index.d.ts +397 -0
- package/lib/nf-softphone.cjs.js +566 -0
- package/lib/nf-softphone.esm-bundler.js +566 -0
- package/lib/nf-softphone.vue.d.ts +115 -0
- package/lib/softphone.d.ts +30 -0
- package/lib/style/css.d.ts +1 -0
- package/lib/style/css.js +1 -0
- package/lib/style/index.d.ts +1 -0
- package/lib/style/index.js +1 -0
- package/lib/type.d.ts +25 -0
- package/package/index.ts +19 -0
- package/package/nf-softphone.vue +284 -0
- package/package/softphone.ts +243 -0
- package/package/style/css.ts +1 -0
- package/package/style/index.ts +1 -0
- package/package/type.ts +28 -0
- package/package.json +34 -0
- package/postcss.config.js +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/lib/style/css.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@94ai/nf-theme-chalk/lib/css/nf-softphone.css'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@94ai/nf-theme-chalk/lib/nf-softphone.scss'
|
package/lib/type.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type Option = {
|
|
2
|
+
origin: string;
|
|
3
|
+
ancestorOrigin: string;
|
|
4
|
+
envMap: Record<Env, string>;
|
|
5
|
+
env: string;
|
|
6
|
+
selector: string;
|
|
7
|
+
el: string;
|
|
8
|
+
agentTag: string;
|
|
9
|
+
agentId: string;
|
|
10
|
+
appKey: string;
|
|
11
|
+
appSecret: string;
|
|
12
|
+
extStatus: '0' | '1';
|
|
13
|
+
instanceMap: Record<string, any>;
|
|
14
|
+
softphoneConnectCallBack: Function;
|
|
15
|
+
softphoneCallRefreshCallBack: Function;
|
|
16
|
+
softphoneSeatStatusChangeCallBack: Function;
|
|
17
|
+
softphoneAcceptCallBack: Function;
|
|
18
|
+
softphoneIgnoreCallBack: Function;
|
|
19
|
+
softphoneHangupCallBack: Function;
|
|
20
|
+
softphoneSessionStateChangeCallBack: Function;
|
|
21
|
+
softphoneIncomingCallBack: Function;
|
|
22
|
+
softphoneSendDtmfCallBack: Function;
|
|
23
|
+
softphoneConnectRegisteredCallBack: Function;
|
|
24
|
+
};
|
|
25
|
+
export type Env = 'test' | 'dev' | 'sg' | 'gray' | 'prod';
|
package/package/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PluginObject,
|
|
3
|
+
Vue2
|
|
4
|
+
} from 'vue-demi'
|
|
5
|
+
import NfSoftphone from './nf-softphone.vue'
|
|
6
|
+
import softphoneManager, { SoftphoneManager } from './softphone'
|
|
7
|
+
|
|
8
|
+
NfSoftphone.install = (app: typeof Vue2) => {
|
|
9
|
+
app!.prototype.$softphoneManager = softphoneManager
|
|
10
|
+
NfSoftphone.$softphoneManager = softphoneManager
|
|
11
|
+
app!.component('nf-softphone', NfSoftphone)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default NfSoftphone as typeof NfSoftphone & PluginObject<undefined>
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
softphoneManager,
|
|
18
|
+
SoftphoneManager
|
|
19
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="nf-softphone">
|
|
3
|
+
<div class="nf-softphone-container" ref="container" :class="{'nf-transparent': containerScrolling === true}">
|
|
4
|
+
<div class="nf-softphone-iframe-container" ref="iframeContainer">
|
|
5
|
+
<iframe
|
|
6
|
+
ref="iframe"
|
|
7
|
+
class="nf-softphone-iframe"
|
|
8
|
+
src=""
|
|
9
|
+
frameborder="0"
|
|
10
|
+
scrolling="no"
|
|
11
|
+
allow="camera *; microphone *"
|
|
12
|
+
></iframe>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
<div :class="{'nf-softphone-text': true}" :style="{'display': containerScrolling === true ? 'block' : 'none'}">正在滚动中...</div>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
import { defineComponent } from 'vue-demi'
|
|
21
|
+
|
|
22
|
+
export default defineComponent({
|
|
23
|
+
name: 'nf-softphone'
|
|
24
|
+
})
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script lang="ts" setup>
|
|
28
|
+
import { Env } from './type'
|
|
29
|
+
import {
|
|
30
|
+
getCurrentInstance,
|
|
31
|
+
onMounted,
|
|
32
|
+
ref,
|
|
33
|
+
onUnmounted
|
|
34
|
+
} from 'vue-demi'
|
|
35
|
+
import { debounce } from '@94ai/common-utils'
|
|
36
|
+
|
|
37
|
+
const props = withDefaults(defineProps<{
|
|
38
|
+
scrollview?: string,
|
|
39
|
+
envMap?: Partial<Record<Env, string>>,
|
|
40
|
+
env?: Env,
|
|
41
|
+
selector?: string,
|
|
42
|
+
el?: string,
|
|
43
|
+
agentId?: string,
|
|
44
|
+
agentTag?: string,
|
|
45
|
+
appKey?: string,
|
|
46
|
+
appSecret?: string,
|
|
47
|
+
extStatus?: string,
|
|
48
|
+
origin?: string,
|
|
49
|
+
ancestorOrigin?: string,
|
|
50
|
+
}>(), {
|
|
51
|
+
scrollview: undefined,
|
|
52
|
+
envMap: () => ({
|
|
53
|
+
test: 'http://softphone.test.k8s.com',
|
|
54
|
+
dev: 'http://softphone.dev.k8s.com',
|
|
55
|
+
sg: 'https://seatsg.94ai.com',
|
|
56
|
+
gray: 'http://softphone.gray.94ai.com',
|
|
57
|
+
prod: 'https://seat.94ai.com',
|
|
58
|
+
}),
|
|
59
|
+
env: 'test',
|
|
60
|
+
selector: undefined,
|
|
61
|
+
agentId: undefined,
|
|
62
|
+
agentTag: undefined,
|
|
63
|
+
appKey: undefined,
|
|
64
|
+
appSecret: undefined,
|
|
65
|
+
extStatus: '0',
|
|
66
|
+
origin: 'nf-softphone',
|
|
67
|
+
ancestorOrigin: 'nf-softphone'
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const emit = defineEmits<{
|
|
71
|
+
(e: 'softphone-connect', event: any): void
|
|
72
|
+
(e: 'softphone-seats-status-change', event: any): void
|
|
73
|
+
(e: 'softphone-accept', event: any): void
|
|
74
|
+
(e: 'softphone-ignore', event: any): void
|
|
75
|
+
(e: 'softphone-hangup', event: any): void
|
|
76
|
+
(e: 'softphone-send-dtmf', event: any): void
|
|
77
|
+
(e: 'softphone-call-refresh', event: any): void
|
|
78
|
+
(e: 'softphone-session-state-change', event: any): void
|
|
79
|
+
(e: 'softphone-incoming', event: any): void
|
|
80
|
+
(e: 'softphone-connect-registered', event: any): void
|
|
81
|
+
}>()
|
|
82
|
+
|
|
83
|
+
const container = ref()
|
|
84
|
+
const iframeContainer = ref()
|
|
85
|
+
const iframe = ref()
|
|
86
|
+
const instance = getCurrentInstance()?.proxy
|
|
87
|
+
|
|
88
|
+
const getContextDomElement = (el: string) => {
|
|
89
|
+
const parent = instance?.$el || document
|
|
90
|
+
return (props.selector ? (parent.querySelector(props.selector) ?? document.querySelector(props.selector) ?? parent) : parent).querySelector(el)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const handlingCommunication = (e: {data: `{
|
|
94
|
+
type: string,
|
|
95
|
+
ancestorOrigin: string,
|
|
96
|
+
origin: string,
|
|
97
|
+
data: 'expand' | 'shrink'
|
|
98
|
+
}` | string}) => {
|
|
99
|
+
const iframe = getContextDomElement('.nf-softphone-iframe')
|
|
100
|
+
if (iframe) {
|
|
101
|
+
let data: Record<string, any> = {}
|
|
102
|
+
try {
|
|
103
|
+
data = JSON.parse(e.data)
|
|
104
|
+
} catch (e) {}
|
|
105
|
+
if (data.type === 'softphone-expand') {
|
|
106
|
+
if (data.data === 'expand') {
|
|
107
|
+
iframe.setAttribute('style', 'position: fixed;z-index:999;');
|
|
108
|
+
} else if (data.data === 'shrink') {
|
|
109
|
+
iframe.removeAttribute('style');
|
|
110
|
+
}
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
if (data.origin === 'ai-softphone') {
|
|
114
|
+
if (data.type === 'softphone-connect') {
|
|
115
|
+
emit('softphone-connect', data)
|
|
116
|
+
} else if (data.type === 'softphone-call-refresh') {
|
|
117
|
+
emit('softphone-call-refresh', data)
|
|
118
|
+
} else if (data.type === 'softphone-seats-status-change') {
|
|
119
|
+
emit('softphone-seats-status-change', data)
|
|
120
|
+
} else if (data.type === 'softphone-accept') {
|
|
121
|
+
emit('softphone-accept', data)
|
|
122
|
+
} else if (data.type === 'softphone-ignore') {
|
|
123
|
+
emit('softphone-ignore', data)
|
|
124
|
+
} else if (data.type === 'softphone-hangup') {
|
|
125
|
+
emit('softphone-hangup', data)
|
|
126
|
+
} else if (data.type === 'softphone-session-state-change') {
|
|
127
|
+
emit('softphone-session-state-change', data)
|
|
128
|
+
} else if (data.type === 'softphone-incoming') {
|
|
129
|
+
emit('softphone-incoming', data)
|
|
130
|
+
} else if (data.type === 'softphone-send-dtmf') {
|
|
131
|
+
emit('softphone-send-dtmf', data)
|
|
132
|
+
} else if (data.type === 'softphone-connect-registered') {
|
|
133
|
+
emit('softphone-connect-registered', data)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
let timer
|
|
139
|
+
|
|
140
|
+
const refreshStyle = async () => {
|
|
141
|
+
clearTimeout(timer)
|
|
142
|
+
timer = undefined
|
|
143
|
+
const containerStyle = container.value.getAttribute('style')
|
|
144
|
+
const iframeContainerStyle = iframeContainer.value.getAttribute('style')
|
|
145
|
+
container.value.removeAttribute('style')
|
|
146
|
+
iframeContainer.value.removeAttribute('style')
|
|
147
|
+
const leftMargin = getComputedStyle(container.value).marginLeft
|
|
148
|
+
const top = container.value.getBoundingClientRect().top
|
|
149
|
+
if (top <= 0) {
|
|
150
|
+
container.value.setAttribute('style', containerStyle)
|
|
151
|
+
iframeContainer.value.setAttribute('style', iframeContainerStyle)
|
|
152
|
+
return {
|
|
153
|
+
top: 0,
|
|
154
|
+
left: 0
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const left = container.value.getBoundingClientRect().left
|
|
158
|
+
if (left <= 0) {
|
|
159
|
+
container.value.setAttribute('style', containerStyle)
|
|
160
|
+
iframeContainer.value.setAttribute('style', iframeContainerStyle)
|
|
161
|
+
return {
|
|
162
|
+
top: 0,
|
|
163
|
+
left: 0
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
container.value.setAttribute('style', `margin-top:${top}px;margin-left:${leftMargin};margin-bottom:${top}px;`)
|
|
167
|
+
iframeContainer.value.setAttribute('style', `margin-top:-${2 * top}px;margin-left:-${left}px;`)
|
|
168
|
+
timer = setTimeout(() => {
|
|
169
|
+
clearTimeout(timer)
|
|
170
|
+
timer = undefined
|
|
171
|
+
containerScrolling.value = false
|
|
172
|
+
}, 100)
|
|
173
|
+
return {
|
|
174
|
+
leftMargin,
|
|
175
|
+
top,
|
|
176
|
+
left
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const containerScrolling = ref()
|
|
180
|
+
const handlingScrollTransparent = () => {
|
|
181
|
+
containerScrolling.value = true
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const handlingScroll = debounce(async () => {
|
|
185
|
+
const {
|
|
186
|
+
top,
|
|
187
|
+
left,
|
|
188
|
+
} = (await refreshStyle() || {})
|
|
189
|
+
if (top && left) {
|
|
190
|
+
iframe.value?.contentWindow.postMessage(JSON.stringify({
|
|
191
|
+
type: 'softphone-scroll',
|
|
192
|
+
origin: props.origin,
|
|
193
|
+
ancestorOrigin: props.ancestorOrigin,
|
|
194
|
+
data: {
|
|
195
|
+
paddingTop: top + 'px',
|
|
196
|
+
}
|
|
197
|
+
}), '*')
|
|
198
|
+
}
|
|
199
|
+
}, 500, false)
|
|
200
|
+
|
|
201
|
+
onMounted(async () => {
|
|
202
|
+
const {
|
|
203
|
+
top,
|
|
204
|
+
left
|
|
205
|
+
} = await refreshStyle()
|
|
206
|
+
const {
|
|
207
|
+
envMap,
|
|
208
|
+
env,
|
|
209
|
+
agentTag,
|
|
210
|
+
agentId,
|
|
211
|
+
appSecret,
|
|
212
|
+
extStatus,
|
|
213
|
+
appKey
|
|
214
|
+
} = props
|
|
215
|
+
let url = `${ envMap?.[env!] ?? env }/#/?cross=1&open=1`
|
|
216
|
+
url += agentTag ? `&agentTag=${agentTag}` : ''
|
|
217
|
+
url += agentId ? `&agentId=${agentId}` : ''
|
|
218
|
+
url += `&appKey=${appKey}&appSecret=${appSecret}&extStatus=${extStatus}&paddingTop=${top}px&paddingLeft=${left}px`
|
|
219
|
+
iframe.value.src = url
|
|
220
|
+
window.addEventListener('message', handlingCommunication, false);
|
|
221
|
+
if (props.scrollview) {
|
|
222
|
+
document.querySelector(props.scrollview)?.addEventListener('scroll', handlingScroll)
|
|
223
|
+
document.querySelector(props.scrollview)?.addEventListener('scroll', handlingScrollTransparent)
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
onUnmounted(() => {
|
|
228
|
+
window.removeEventListener('message', handlingCommunication, false);
|
|
229
|
+
if (props.scrollview) {
|
|
230
|
+
document.querySelector(props.scrollview)?.removeEventListener('scroll', handlingScroll)
|
|
231
|
+
document.querySelector(props.scrollview)?.removeEventListener('scroll', handlingScrollTransparent)
|
|
232
|
+
}
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
const postMessageCommunicate = (type, status?: boolean) => {
|
|
236
|
+
iframe.value?.contentWindow.postMessage(JSON.stringify({
|
|
237
|
+
origin: props.origin,
|
|
238
|
+
ancestorOrigin: props.ancestorOrigin,
|
|
239
|
+
type,
|
|
240
|
+
data: {
|
|
241
|
+
status,
|
|
242
|
+
type: 'manual'
|
|
243
|
+
}
|
|
244
|
+
}), '*')
|
|
245
|
+
}
|
|
246
|
+
const connect = () => {
|
|
247
|
+
postMessageCommunicate('softphone-connect', true)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
const disconnect = () => {
|
|
252
|
+
postMessageCommunicate('softphone-connect', false)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const seatsStatusChange = (status) => {
|
|
256
|
+
postMessageCommunicate('softphone-seats-status-change', status)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const accept = () => {
|
|
260
|
+
postMessageCommunicate('softphone-accept')
|
|
261
|
+
}
|
|
262
|
+
const ignore = () => {
|
|
263
|
+
postMessageCommunicate('softphone-ignore')
|
|
264
|
+
}
|
|
265
|
+
const hangup = () => {
|
|
266
|
+
postMessageCommunicate('softphone-hangup')
|
|
267
|
+
}
|
|
268
|
+
const sendDtmf = () => {
|
|
269
|
+
postMessageCommunicate('softphone-send-dtmf')
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
defineExpose({
|
|
273
|
+
connect,
|
|
274
|
+
disconnect,
|
|
275
|
+
seatsStatusChange,
|
|
276
|
+
accept,
|
|
277
|
+
ignore,
|
|
278
|
+
hangup,
|
|
279
|
+
sendDtmf,
|
|
280
|
+
iframe,
|
|
281
|
+
containerScrolling
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
</script>
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { Option } from 'packages/nf-softphone/lib/type'
|
|
2
|
+
import { generateUUID } from '@94ai/common-utils'
|
|
3
|
+
|
|
4
|
+
export class SoftphoneManager {
|
|
5
|
+
option: Partial<Option> = {
|
|
6
|
+
origin: 'nf-softphone',
|
|
7
|
+
ancestorOrigin: 'nf-softphone',
|
|
8
|
+
envMap: {
|
|
9
|
+
test: 'http://softphone.test.k8s.com',
|
|
10
|
+
dev: 'http://softphone.dev.k8s.com',
|
|
11
|
+
sg: 'https://seatsg.94ai.com',
|
|
12
|
+
gray: 'http://softphone.gray.94ai.com',
|
|
13
|
+
prod: 'https://seat.94ai.com',
|
|
14
|
+
},
|
|
15
|
+
env: 'test',
|
|
16
|
+
selector: undefined,
|
|
17
|
+
el: undefined,
|
|
18
|
+
agentId: undefined,
|
|
19
|
+
agentTag: undefined,
|
|
20
|
+
appKey: undefined,
|
|
21
|
+
appSecret: undefined,
|
|
22
|
+
extStatus: '0',
|
|
23
|
+
instanceMap: {},
|
|
24
|
+
softphoneConnectCallBack: () => {console.log('softphone-connect')},
|
|
25
|
+
softphoneCallRefreshCallBack: () => {console.log('softphone-call-refresh')},
|
|
26
|
+
softphoneSeatStatusChangeCallBack: () => {console.log('softphone-seats-status-change')},
|
|
27
|
+
softphoneAcceptCallBack: () => {console.log('softphone-accept')},
|
|
28
|
+
softphoneIgnoreCallBack: () => {console.log('softphone-ignore')},
|
|
29
|
+
softphoneHangupCallBack: () => {console.log('softphone-hangup')},
|
|
30
|
+
softphoneSessionStateChangeCallBack: () => {console.log('softphone-session-state-change')},
|
|
31
|
+
softphoneIncomingCallBack: () => {console.log('softphone-incoming')},
|
|
32
|
+
softphoneSendDtmfCallBack: () => {console.log('softphone-send-dtmf')},
|
|
33
|
+
softphoneConnectRegisteredCallBack: () => {console.log('softphone-connect-registered')},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
loadCssCode = (code) => {
|
|
38
|
+
if (!document.getElementById('nf-softphone')) {
|
|
39
|
+
const style = document.createElement('style');
|
|
40
|
+
style.id = 'nf-softphone'
|
|
41
|
+
style.type = 'text/css';
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
style.rel = 'stylesheet';
|
|
44
|
+
//for Chrome Firefox Opera Safari
|
|
45
|
+
style.appendChild(document.createTextNode(code));
|
|
46
|
+
//for IE
|
|
47
|
+
//style.styleSheet.cssText = code;
|
|
48
|
+
const head = document.getElementsByTagName('head')[0];
|
|
49
|
+
head.appendChild(style);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
removeCssCode = () => {
|
|
54
|
+
const css = document.getElementById('nf-softphone')
|
|
55
|
+
if (css) {
|
|
56
|
+
if (css.parentNode) {
|
|
57
|
+
css.parentNode.removeChild(css);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getContextDomElement = (el: string) => {
|
|
63
|
+
return (this.option.selector ? document.querySelector(this.option.selector) ?? document : document).querySelector(el)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
handlingCommunication = (e: {data: `{
|
|
67
|
+
type: string,
|
|
68
|
+
ancestorOrigin: string,
|
|
69
|
+
origin: string,
|
|
70
|
+
data: 'expand' | 'shrink'
|
|
71
|
+
}` | string}) => {
|
|
72
|
+
const iframe = this.getContextDomElement('.nf-softphone-iframe')
|
|
73
|
+
if (iframe) {
|
|
74
|
+
let data: Record<string, any> = {}
|
|
75
|
+
try {
|
|
76
|
+
data = JSON.parse(e.data)
|
|
77
|
+
} catch (e) {}
|
|
78
|
+
if (data.type === 'softphone-expand') {
|
|
79
|
+
if (data.data === 'expand') {
|
|
80
|
+
iframe.setAttribute('style', 'position: fixed;z-index:999;');
|
|
81
|
+
} else if (data.data === 'shrink') {
|
|
82
|
+
iframe.removeAttribute('style');
|
|
83
|
+
}
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
if (data.origin === 'ai-softphone') {
|
|
87
|
+
if (data.type === 'softphone-connect') {
|
|
88
|
+
this.option.softphoneConnectCallBack?.(data)
|
|
89
|
+
} else if (data.type === 'softphone-call-refresh') {
|
|
90
|
+
this.option.softphoneCallRefreshCallBack?.(data)
|
|
91
|
+
} else if (data.type === 'softphone-seats-status-change') {
|
|
92
|
+
this.option.softphoneSeatStatusChangeCallBack?.(data)
|
|
93
|
+
} else if (data.type === 'softphone-accept') {
|
|
94
|
+
this.option.softphoneAcceptCallBack?.(data)
|
|
95
|
+
} else if (data.type === 'softphone-ignore') {
|
|
96
|
+
this.option.softphoneIgnoreCallBack?.(data)
|
|
97
|
+
} else if (data.type === 'softphone-hangup') {
|
|
98
|
+
this.option.softphoneHangupCallBack?.(data)
|
|
99
|
+
} else if (data.type === 'softphone-session-state-change') {
|
|
100
|
+
this.option.softphoneSessionStateChangeCallBack?.(data)
|
|
101
|
+
} else if (data.type === 'softphone-incoming') {
|
|
102
|
+
this.option.softphoneIncomingCallBack?.(data)
|
|
103
|
+
} else if (data.type === 'softphone-send-dtmf') {
|
|
104
|
+
this.option.softphoneSendDtmfCallBack?.(data)
|
|
105
|
+
} else if (data.type === 'softphone-connect-registered') {
|
|
106
|
+
this.option.softphoneConnectRegisteredCallBack?.(data)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
handlerInteractive = () => {
|
|
113
|
+
/**
|
|
114
|
+
* 实时处理层级
|
|
115
|
+
*/
|
|
116
|
+
window.addEventListener('message', this.handlingCommunication, false);
|
|
117
|
+
this.loadCssCode(`
|
|
118
|
+
body,html {
|
|
119
|
+
overflow: hidden;
|
|
120
|
+
}
|
|
121
|
+
.nf-softphone-container {
|
|
122
|
+
margin-left: 10px;
|
|
123
|
+
height: 32px;
|
|
124
|
+
min-width: 600px;
|
|
125
|
+
}
|
|
126
|
+
.nf-softphone-iframe-container {
|
|
127
|
+
height: 32px;
|
|
128
|
+
width: 100%;
|
|
129
|
+
overflow: visible;
|
|
130
|
+
}
|
|
131
|
+
.nf-softphone-iframe {
|
|
132
|
+
width: 100vw;
|
|
133
|
+
height: 100vh;
|
|
134
|
+
top: 0;
|
|
135
|
+
left: 0;
|
|
136
|
+
}
|
|
137
|
+
`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
handlerDomRemove = () => {
|
|
141
|
+
Object.keys(this.option.instanceMap!).forEach(key => {
|
|
142
|
+
const el = document.getElementById(key)
|
|
143
|
+
if (el && el.parentNode) {
|
|
144
|
+
el.parentNode.removeChild(el)
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
handlerDomGenerater = () => {
|
|
149
|
+
const container = document.createElement('div');
|
|
150
|
+
const iframeContainer = document.createElement('div');
|
|
151
|
+
const iframe = document.createElement('iframe');
|
|
152
|
+
const uuid = generateUUID()
|
|
153
|
+
this.option.instanceMap![uuid] = container
|
|
154
|
+
container.setAttribute('id', uuid)
|
|
155
|
+
container.setAttribute('class', "nf-softphone-container")
|
|
156
|
+
iframeContainer.setAttribute('class', "nf-softphone-iframe-container")
|
|
157
|
+
iframe.setAttribute('class', "nf-softphone-iframe")
|
|
158
|
+
iframe.setAttribute('src', "")
|
|
159
|
+
iframe.setAttribute('frameborder', "0")
|
|
160
|
+
iframe.setAttribute('scrolling', "no")
|
|
161
|
+
iframe.setAttribute('allow', "camera *; microphone *")
|
|
162
|
+
iframeContainer.appendChild(iframe)
|
|
163
|
+
container.appendChild(iframeContainer)
|
|
164
|
+
const destination = (this.option.el ? this.getContextDomElement(this.option.el) ?? document.body : document.body)
|
|
165
|
+
destination.appendChild(container)
|
|
166
|
+
const leftMargin = getComputedStyle(container).marginLeft
|
|
167
|
+
const top = container.getBoundingClientRect().top
|
|
168
|
+
const left = container.getBoundingClientRect().left
|
|
169
|
+
container.setAttribute('style', `margin-top:${top}px;margin-left:${leftMargin};margin-bottom:${top}px;`)
|
|
170
|
+
iframeContainer.setAttribute('style', `margin-top:-${2 * top}px;margin-left:-${left}px;`)
|
|
171
|
+
const {
|
|
172
|
+
envMap,
|
|
173
|
+
env,
|
|
174
|
+
agentTag,
|
|
175
|
+
agentId,
|
|
176
|
+
appSecret,
|
|
177
|
+
extStatus,
|
|
178
|
+
appKey
|
|
179
|
+
} = this.option
|
|
180
|
+
let url = `${ envMap?.[env!] ?? env }/#/?cross=1&open=1`
|
|
181
|
+
url += agentTag ? `&agentTag=${agentTag}` : ''
|
|
182
|
+
url += agentId ? `&agentId=${agentId}` : ''
|
|
183
|
+
url += `&appKey=${appKey}&appSecret=${appSecret}&extStatus=${extStatus}&paddingTop=${top}px&paddingLeft=${left}px`
|
|
184
|
+
iframe.src = url
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
initSoftphone = (option) => {
|
|
188
|
+
this.option = option ? { ...this.option, ...option } :this.option
|
|
189
|
+
this.handlerInteractive()
|
|
190
|
+
this.handlerDomGenerater()
|
|
191
|
+
return this
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
postMessageCommunicate = (type, status?: boolean) => {
|
|
195
|
+
const iframe = this.getContextDomElement('.nf-softphone-iframe') as HTMLIFrameElement
|
|
196
|
+
if (iframe) {
|
|
197
|
+
iframe.contentWindow!.postMessage(JSON.stringify({
|
|
198
|
+
origin: this.option.origin,
|
|
199
|
+
ancestorOrigin: this.option.ancestorOrigin,
|
|
200
|
+
type,
|
|
201
|
+
data: {
|
|
202
|
+
status,
|
|
203
|
+
type: 'manual'
|
|
204
|
+
}
|
|
205
|
+
}), '*')
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
connect = () => {
|
|
209
|
+
this.postMessageCommunicate('softphone-connect', true)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
disconnect = () => {
|
|
214
|
+
this.postMessageCommunicate('softphone-connect', false)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
seatsStatusChange = (status: boolean) => {
|
|
218
|
+
this.postMessageCommunicate('softphone-seats-status-change', status)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
accept = () => {
|
|
222
|
+
this.postMessageCommunicate('softphone-accept')
|
|
223
|
+
}
|
|
224
|
+
ignore = () => {
|
|
225
|
+
this.postMessageCommunicate('softphone-ignore')
|
|
226
|
+
}
|
|
227
|
+
hangup = () => {
|
|
228
|
+
this.postMessageCommunicate('softphone-hangup')
|
|
229
|
+
}
|
|
230
|
+
sendDtmf = () => {
|
|
231
|
+
this.postMessageCommunicate('softphone-send-dtmf')
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
destroy = () => {
|
|
235
|
+
window.removeEventListener('message', this.handlingCommunication, false);
|
|
236
|
+
this.removeCssCode()
|
|
237
|
+
this.handlerDomRemove()
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const softphoneManager = new SoftphoneManager()
|
|
242
|
+
|
|
243
|
+
export default softphoneManager
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@94ai/nf-theme-chalk/lib/css/nf-softphone.css'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@94ai/nf-theme-chalk/lib/nf-softphone.scss'
|
package/package/type.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type Option = {
|
|
2
|
+
origin: string
|
|
3
|
+
ancestorOrigin: string
|
|
4
|
+
envMap: Record<Env, string>,
|
|
5
|
+
env: string
|
|
6
|
+
selector: string
|
|
7
|
+
el: string
|
|
8
|
+
agentTag: string
|
|
9
|
+
agentId: string
|
|
10
|
+
appKey: string
|
|
11
|
+
appSecret: string
|
|
12
|
+
extStatus: '0' | '1'
|
|
13
|
+
instanceMap: Record<string, any>,
|
|
14
|
+
|
|
15
|
+
softphoneConnectCallBack: Function
|
|
16
|
+
softphoneCallRefreshCallBack: Function
|
|
17
|
+
softphoneSeatStatusChangeCallBack: Function
|
|
18
|
+
softphoneAcceptCallBack: Function
|
|
19
|
+
softphoneIgnoreCallBack: Function
|
|
20
|
+
softphoneHangupCallBack: Function
|
|
21
|
+
softphoneSessionStateChangeCallBack: Function
|
|
22
|
+
softphoneIncomingCallBack: Function
|
|
23
|
+
softphoneSendDtmfCallBack: Function
|
|
24
|
+
softphoneConnectRegisteredCallBack: Function
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export type Env = 'test' |'dev'| 'sg'| 'gray'| 'prod'
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@94ai/nf-softphone",
|
|
3
|
+
"version": "3.3.17",
|
|
4
|
+
"description": "> TODO: description",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"author": "zoujiahe <zoujiahe@94ai.com>",
|
|
7
|
+
"homepage": "https://oss.xccjh.top/common-ui/#/ai-index",
|
|
8
|
+
"license": "ISC",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "http://94ai.gitlab.com/ui/common-ui.git"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@94ai/nf-theme-chalk": "^3.3.17",
|
|
18
|
+
"vue-demi": "^0.14.5"
|
|
19
|
+
},
|
|
20
|
+
"peerDependenciesMeta": {
|
|
21
|
+
"@vue/composition-api": {
|
|
22
|
+
"optional": true
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@vue/composition-api": "^1.0.0-rc.1",
|
|
27
|
+
"element-ui": ">=2.13.2",
|
|
28
|
+
"vue": "^2.0.0 || >=3.0.0"
|
|
29
|
+
},
|
|
30
|
+
"types": "lib/index.d.ts",
|
|
31
|
+
"main": "lib/nf-softphone.cjs.js",
|
|
32
|
+
"module": "lib/nf-softphone.esm-bundler.js",
|
|
33
|
+
"gitHead": "6c22ca6497060d2c3789c9dade757bf202919452"
|
|
34
|
+
}
|