iframe.vue
2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<template>
<div>
<h2>客户端</h2>
<p>
<el-button type="primary" @click="open">呼叫</el-button>
<el-button type="primary" @click="cancelCall">取消呼叫</el-button>
</p>
<iframe
v-if="isStart"
ref="srtcIframe"
title="srtcIframe"
:src="target"
frameborder="2"
allow="microphone;camera;midi;encrypted-media;fullscreen;"
></iframe>
<p>callback:{{ message }}</p>
<p>这还少恩位置</p>
<p>这还少恩位置</p>
<p>这还少恩位置</p>
</div>
</template>
<script>
export default {
data() {
return {
baseUrl: 'https://localhost:8080',
isStart: false,
target: '',
strWindowFeatures: `
left=2400,
top=200
height=500,
width=700,
menubar=1,
toolbar=1,
fullscreen=1
`,
message: '',
windowRef: ''
}
},
beforeMount() {
window.addEventListener('message', this.receiveMessage, false)
},
methods: {
open() {
this.isStart = true
this.target = `${this.baseUrl}/#/srtc-iframe`
this.$nextTick().then(() => {
this.$refs.srtcIframe.onload = () => {
this.sendMessage()
}
})
},
sendMessage() {
this.$refs.srtcIframe.contentWindow.postMessage(
{
type: 'startCall',
data: {
appUserName: '123',
appUserPhone: '16621043587',
orderId: '123213',
webUserName: 'lz'
}
},
this.baseUrl
)
},
cancelCall() {
this.$refs.srtcIframe.contentWindow.postMessage(
{
type: 'cancelCall'
},
this.baseUrl
)
},
receiveMessage(e) {
if (e.origin !== this.baseUrl) {
return
}
const { type, data } = e
// switch (type) {
// case 'userJoin':
// this.popMessage(data)
// break
// case 'appHangUp':
// this.popMessage(data)
// break
// case 'webHangUp':
// this.popMessage(data)
// break
// }
this.popMessage(`${type}---${data}`)
},
popMessage(data) {
this.$message({
type: 'error',
message: data
})
}
}
}
</script>
<style lang="scss" scoped>
iframe {
width: 500px;
height: 600px;
position: fixed;
top: 0;
right: 0;
}
</style>