From dafbb909e478015ee062bf962bddcb20a6fed55c Mon Sep 17 00:00:00 2001 From: WXL <1785969728@qq.com> Date: 星期四, 03 七月 2025 14:51:32 +0800 Subject: [PATCH] 测试完成 --- src/components/CallButton/index.vue | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 148 insertions(+), 0 deletions(-) diff --git a/src/components/CallButton/index.vue b/src/components/CallButton/index.vue new file mode 100644 index 0000000..57690ea --- /dev/null +++ b/src/components/CallButton/index.vue @@ -0,0 +1,148 @@ +<template> + <div class="call-container"> + <!-- 鍙风爜杈撳叆 --> + <input + v-model="phoneNumber" + type="text" + placeholder="杈撳叆鐢佃瘽鍙风爜" + @keyup.enter="startCall" + > + + <!-- 鍛煎彨鎸夐挳 --> + <button + :class="['call-btn', { 'calling': isCalling }]" + @click="startCall" + > + {{ isCalling ? '閫氳瘽涓�...' : '涓�閿懠鍙�' }} + </button> + + <!-- 鎸傛柇鎸夐挳 --> + <button + v-if="isCalling" + class="end-call-btn" + @click="endCall" + > + 鎸傛柇 + </button> + + <!-- 闊抽鍏冪礌锛堥殣钘忥級 --> + <audio id="remoteAudio" autoplay></audio> + + <!-- 鐘舵�佹樉绀� --> + <div class="call-status"> + {{ callStatus }} + </div> + </div> +</template> + +<script> +import sipService from '@/utils/sipService' + +export default { + data() { + return { + phoneNumber: '', + isCalling: false, + callStatus: '鍑嗗灏辩华', + sipConfig: { + wsUrl: 'wss://192.168.100.6:7443', + sipUri: '1000@192.168.100.6', + password: 'Smartor@2023', + displayName: 'Web 灏忛緳', + realm: '192.168.100.6:8090' + } + } + }, + mounted() { + // 鍒濆鍖朣IP杩炴帴 + sipService.init(this.sipConfig) + }, + beforeDestroy() { + // 缁勪欢閿�姣佹椂缁撴潫閫氳瘽 + this.endCall() + }, + methods: { + // 寮�濮嬪懠鍙� + async startCall() { + if (!this.phoneNumber) { + this.callStatus = '璇疯緭鍏ョ數璇濆彿鐮�' + return + } + try { + this.isCalling = true + this.callStatus = '鍛煎彨涓�...' + // 璋冪敤SIP鏈嶅姟 + sipService.makeCall(this.phoneNumber) + + this.callStatus = '閫氳瘽宸插缓绔�' + } catch (error) { + console.error('鍛煎彨澶辫触:', error) + this.callStatus = `鍛煎彨澶辫触: ${error.message}` + this.isCalling = false + } + }, + + // 缁撴潫閫氳瘽 + endCall() { + sipService.endCall() + this.isCalling = false + this.callStatus = '閫氳瘽宸茬粨鏉�' + } + } +} +</script> + +<style scoped> +.call-container { + display: flex; + flex-direction: column; + gap: 10px; + max-width: 300px; + margin: 0 auto; + padding: 20px; + border: 1px solid #eee; + border-radius: 8px; +} + +input { + padding: 8px; + border: 1px solid #ccc; + border-radius: 4px; +} + +.call-btn { + padding: 10px; + background-color: #4CAF50; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; +} + +.call-btn:hover { + background-color: #45a049; +} + +.call-btn.calling { + background-color: #2196F3; +} + +.end-call-btn { + padding: 10px; + background-color: #f44336; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; +} + +.end-call-btn:hover { + background-color: #d32f2f; +} + +.call-status { + margin-top: 10px; + font-size: 14px; + color: #666; +} +</style> -- Gitblit v1.9.3