| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="websocket-demo"> |
| | | <div> |
| | | <h3>Websocketæ¥å£æµè¯DEMO</h3> |
| | | <div class="config-area"> |
| | | <div class="input-group"> |
| | | <label>CTI_WS_URL</label> |
| | | <input |
| | | type="text" |
| | | v-model="config.cti_ws_url" |
| | | placeholder="ws://40.78.0.169:6688" |
| | | /> |
| | | |
| | | <label>åå¸å·¥å·</label> |
| | | <input type="text" v-model="config.seatname" placeholder="8000" /> |
| | | |
| | | <label>åå¸åæº</label> |
| | | <input type="text" v-model="config.seatnum" placeholder="8000" /> |
| | | |
| | | <label>å¯ç </label> |
| | | <input type="text" v-model="config.password" placeholder="123456" /> |
| | | </div> |
| | | |
| | | <div class="input-group"> |
| | | <label>å¤çº¿å·ç </label> |
| | | <input type="text" v-model="config.phone" placeholder="10086" /> |
| | | |
| | | <label>UUID</label> |
| | | <input type="text" v-model="config.uuid" /> |
| | | |
| | | <label>å
¶ä»åå¸</label> |
| | | <input type="text" v-model="config.other" placeholder="8001" /> |
| | | |
| | | <label>æè½ç»</label> |
| | | <input type="text" v-model="config.group" placeholder="a3" /> |
| | | |
| | | <label>å¤å¼åæ°id</label> |
| | | <input type="text" v-model="config.paramid" placeholder="3" /> |
| | | </div> |
| | | </div> |
| | | |
| | | <!-- æä½æé®åºå --> |
| | | <div class="button-area"> |
| | | <!-- 第ä¸è¡æé® --> |
| | | <div class="button-row"> |
| | | <button @click="seatlogin">ç¾å
¥</button> |
| | | <button @click="seatlogout">ç¾åº</button> |
| | | <button @click="afk">示å¿</button> |
| | | <button @click="online">示é²</button> |
| | | <button @click="pickup">代ç</button> |
| | | </div> |
| | | |
| | | <!-- 第äºè¡æé® --> |
| | | <div class="button-row"> |
| | | <button @click="hangup">ææº</button> |
| | | <button @click="callout">å¤å¼</button> |
| | | <button @click="transfer">éè¯è½¬ç§»</button> |
| | | <button @click="transferresume">éè¯è½¬ç§»æ¶å</button> |
| | | <button @click="hold">éè¯ä¿æ</button> |
| | | <button @click="holdresume">éè¯ä¿ææ¶å</button> |
| | | <button @click="remove">éè¯å¼ºæ</button> |
| | | <button @click="insert">éè¯å¼ºæ</button> |
| | | <button @click="monitor">çå¬</button> |
| | | <button @click="monitor_to_talk">çå¬è½¬éè¯</button> |
| | | <button @click="monitor_end">çå¬ç»æ</button> |
| | | <button @click="choosecall">éæ©</button> |
| | | <button @click="replacecall">代æ¥</button> |
| | | <button @click="three">䏿¹éè¯</button> |
| | | </div> |
| | | |
| | | <!-- 第ä¸è¡æé® --> |
| | | <div class="button-row"> |
| | | <button @click="handoff_ready">å¨è¯¢å¼å§</button> |
| | | <button @click="handoff_call">å¨è¯¢å¼å«</button> |
| | | <button @click="handoff_resume">å¨è¯¢æ¶å</button> |
| | | <button @click="handoff_transfer">å¨è¯¢è½¬ç§»</button> |
| | | <button @click="handoff_three">å¨è¯¢ä¸æ¹</button> |
| | | <button @click="record_start">å¼å§éè¯å½é³</button> |
| | | <button @click="record_stop">忢éè¯å½é³</button> |
| | | </div> |
| | | |
| | | <!-- 第åè¡æé® --> |
| | | <div class="button-row"> |
| | | <button @click="openseatlist">æå¼åå¸ç¶æ</button> |
| | | <button @click="closeseatlist">å
³éåå¸ç¶æ</button> |
| | | <button @click="openqueues">æå¼éåä¿¡æ¯</button> |
| | | <button @click="closequeues">å
³ééåä¿¡æ¯</button> |
| | | <button @click="opencalllist">æå¼éè¯ä¿¡æ¯</button> |
| | | <button @click="closecalllist">å
³ééè¯ä¿¡æ¯</button> |
| | | <button @click="openroutelist">æå¼è·¯ç±ä¿¡æ¯</button> |
| | | <button @click="closeroutelist">å
³éè·¯ç±ä¿¡æ¯</button> |
| | | </div> |
| | | |
| | | <!-- 第äºè¡æé® --> |
| | | <div class="button-row"> |
| | | <button @click="seatlist">è·ååå¸ä¿¡æ¯</button> |
| | | <button @click="queues">è·åéåä¿¡æ¯</button> |
| | | <button @click="calllist">è·åéè¯ä¿¡æ¯</button> |
| | | <button @click="routelist">è·åè·¯ç±ä¿¡æ¯</button> |
| | | <button @click="batch">è·åå¤å¼åæ°ä¿¡æ¯</button> |
| | | <button @click="batch_start">å¼å§å¤å¼ä»»å¡</button> |
| | | <button @click="batch_stop">忢å¤å¼ä»»å¡</button> |
| | | </div> |
| | | </div> |
| | | |
| | | <!-- æ¥å¿æ¾ç¤ºåºå --> |
| | | <h3>åè®®æ¥å¿åº<button @click="testclear">æ¸
é¤</button></h3> |
| | | <div id="msg" class="log-area">{{ logs }}</div> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import { CallsetState, CallgetList } from "@/api/AiCentre/index"; |
| | | |
| | | export default { |
| | | name: "WebsocketDemo", |
| | | |
| | | data() { |
| | | return { |
| | | config: { |
| | | cti_ws_url: "wss://9.208.2.190:8092/cal-api/", |
| | | seatname: "8000", |
| | | seatnum: "8000", |
| | | password: "123456", |
| | | phone: "10086", |
| | | uuid: "", |
| | | other: "8001", |
| | | group: "a3", |
| | | paramid: "3", |
| | | }, |
| | | randomNum: "", |
| | | randomID: "", |
| | | logs: "", |
| | | ws: null, |
| | | isConnected: false, |
| | | }; |
| | | }, |
| | | |
| | | mounted() { |
| | | this.CallgetList(); |
| | | this.initializeWebSocket(); |
| | | }, |
| | | |
| | | beforeUnmount() { |
| | | this.disconnectWebSocket(); |
| | | }, |
| | | |
| | | methods: { |
| | | // åå§åWebSocketè¿æ¥ |
| | | initializeWebSocket() { |
| | | try { |
| | | // æ ¹æ®å½å页é¢åè®®èªå¨éæ©WSåè®® |
| | | const isHttps = window.location.protocol === "https:"; |
| | | this.config.cti_ws_url = isHttps |
| | | ? "wss://9.208.2.190:8092/cal-api/" |
| | | : "ws://40.78.0.169:6688"; |
| | | |
| | | if (typeof window.WebSocket === "undefined") { |
| | | this.addLog("é误: æµè§å¨ä¸æ¯æWebSocket"); |
| | | return; |
| | | } |
| | | |
| | | this.connectWebSocket(); |
| | | } catch (error) { |
| | | this.addLog(`åå§åWebSocketé误: ${error.message}`); |
| | | // å°è¯ä½¿ç¨å¤ç¨å°å |
| | | this.config.cti_ws_url = "wss://9.208.2.190:8092/cal-api/"; |
| | | setTimeout(() => this.connectWebSocket(), 2000); |
| | | } |
| | | }, |
| | | // æ¥è¯¢å¯ç¨åæºå· |
| | | async CallgetList() { |
| | | try { |
| | | const res = await CallgetList(); |
| | | this.randomNum = res.data[0].tel; |
| | | this.randomID = res.data[0].id; |
| | | // æ£ç¡®è®¾ç½® sipUri |
| | | this.config.seatname = randomNum; |
| | | this.config.seatnum = randomNum; |
| | | this.startCallsetState(); |
| | | } catch (error) { |
| | | console.error("è·å座å¸å·å¤±è´¥:", error); |
| | | // this.updateStatus("failed", "è·å座å¸å·å¤±è´¥"); |
| | | } |
| | | }, |
| | | //使ç¨åº§å¸å· |
| | | async startCallsetState() { |
| | | try { |
| | | await CallsetState({ id: this.randomID, state: 1 }); |
| | | console.log("座å¸å·ç¶ææ´æ°ä¸ºä½¿ç¨ä¸"); |
| | | } catch (error) { |
| | | console.error("æ´æ°åº§å¸å·ç¶æå¤±è´¥:", error); |
| | | } |
| | | }, |
| | | //éæ¾åº§å¸å· |
| | | async overCallsetState() { |
| | | try { |
| | | if (this.randomID) { |
| | | await CallsetState({ id: this.randomID, state: 0 }); |
| | | console.log("座å¸å·ç¶ææ´æ°ä¸ºå¯ç¨"); |
| | | } |
| | | } catch (error) { |
| | | console.error("éæ¾åº§å¸å·å¤±è´¥:", error); |
| | | } |
| | | }, |
| | | // è¿æ¥WebSocket |
| | | connectWebSocket() { |
| | | if (this.ws && this.ws.readyState === WebSocket.OPEN) { |
| | | this.addLog("WebSocketå·²è¿æ¥"); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | let wsUrl = this.config.cti_ws_url; |
| | | // ç¡®ä¿HTTPS页é¢ä½¿ç¨WSS |
| | | if ( |
| | | window.location.protocol === "https:" && |
| | | wsUrl.startsWith("ws://") |
| | | ) { |
| | | wsUrl = wsUrl.replace("ws://", "wss://"); |
| | | } |
| | | |
| | | this.ws = new WebSocket(wsUrl); |
| | | |
| | | this.ws.onopen = () => { |
| | | this.isConnected = true; |
| | | this.addLog("WebSocketè¿æ¥æå"); |
| | | }; |
| | | |
| | | this.ws.onmessage = (event) => { |
| | | this.handleWebSocketMessage(event); |
| | | }; |
| | | |
| | | this.ws.onclose = (event) => { |
| | | this.isConnected = false; |
| | | this.addLog(`WebSocketè¿æ¥å
³é: ${event.code} ${event.reason}`); |
| | | // èªå¨éè¿ |
| | | setTimeout(() => this.connectWebSocket(), 3000); |
| | | }; |
| | | |
| | | this.ws.onerror = (error) => { |
| | | this.addLog(`WebSocketé误: ${error.message}`); |
| | | // å°è¯å¤ç¨URL |
| | | if (!wsUrl.includes("9.208.2.190")) { |
| | | this.config.cti_ws_url = "wss://9.208.2.190:8092/cal-api/"; |
| | | setTimeout(() => this.connectWebSocket(), 3000); |
| | | } |
| | | }; |
| | | } catch (error) { |
| | | this.addLog(`è¿æ¥WebSocket失败: ${error.message}`); |
| | | // å°è¯å¤ç¨URL |
| | | this.config.cti_ws_url = "wss://9.208.2.190:8092/cal-api/"; |
| | | setTimeout(() => this.connectWebSocket(), 3000); |
| | | } |
| | | }, |
| | | |
| | | // å¤çWebSocketæ¶æ¯ |
| | | handleWebSocketMessage(event) { |
| | | const reader = new FileReader(); |
| | | reader.onloadend = (e) => { |
| | | const message = reader.result; |
| | | this.addLog(`æ¶å°æ¶æ¯: ${message}`); |
| | | |
| | | try { |
| | | const obj = JSON.parse(message); |
| | | |
| | | // å¤çå¿è·³å
|
| | | if (obj.cmd === "system" && obj.action === "keepalive") { |
| | | this.keepalive(obj.seatname, obj.seatnum); |
| | | } |
| | | |
| | | // èªå¨è®¾ç½®UUID |
| | | if (obj.cmd === "control" && obj.action === "tp_callin") { |
| | | this.config.uuid = obj.uuid; |
| | | this.addLog(`èªå¨è®¾ç½®UUID: ${obj.uuid}`); |
| | | } |
| | | } catch (error) { |
| | | this.addLog(`æ¶æ¯è§£æé误: ${error.message}`); |
| | | } |
| | | }; |
| | | reader.readAsText(event.data); |
| | | }, |
| | | |
| | | // æå¼WebSocketè¿æ¥ |
| | | disconnectWebSocket() { |
| | | if (this.ws) { |
| | | this.ws.close(); |
| | | this.ws = null; |
| | | this.isConnected = false; |
| | | this.addLog("WebSocketå·²æå¼"); |
| | | } |
| | | }, |
| | | |
| | | // åéWebSocketæ¶æ¯ |
| | | sendWebSocketMessage(message) { |
| | | if (!this.isConnected || !this.ws) { |
| | | this.addLog("é误: WebSocketæªè¿æ¥"); |
| | | return false; |
| | | } |
| | | |
| | | try { |
| | | const messageStr = |
| | | typeof message === "string" ? message : JSON.stringify(message); |
| | | this.ws.send(messageStr); |
| | | this.addLog(`åéæ¶æ¯: ${messageStr}`); |
| | | return true; |
| | | } catch (error) { |
| | | this.addLog(`åéæ¶æ¯å¤±è´¥: ${error.message}`); |
| | | return false; |
| | | } |
| | | }, |
| | | |
| | | // éªè¯åæ° |
| | | validateParams(params, requiredFields) { |
| | | for (const field of requiredFields) { |
| | | if (!params[field] || params[field].toString().trim() === "") { |
| | | this.addLog(`é误: ${field} ä¸è½ä¸ºç©º`); |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | }, |
| | | |
| | | // ==================== WebSocket.js åè½æ´å ==================== |
| | | |
| | | // ç¾å
¥ |
| | | seatlogin() { |
| | | const { seatname, seatnum, password, cti_ws_url } = this.config; |
| | | |
| | | if ( |
| | | !this.validateParams({ seatname, seatnum }, ["seatname", "seatnum"]) |
| | | ) { |
| | | return; |
| | | } |
| | | |
| | | // éæ°è¿æ¥WebSocketï¼åjsæä»¶ä¸çé»è¾ï¼ |
| | | this.connectWebSocket(); |
| | | setTimeout(() => { |
| | | const protocol = { |
| | | cmd: "system", |
| | | action: "seatlogin", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | password: password, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, 1000); |
| | | }, |
| | | |
| | | // ç¾åº |
| | | seatlogout() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if ( |
| | | !this.validateParams({ seatname, seatnum }, ["seatname", "seatnum"]) |
| | | ) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "system", |
| | | action: "seatlogout", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | this.ws.close(); |
| | | }, |
| | | |
| | | // ç¤ºå¿ |
| | | afk() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if ( |
| | | !this.validateParams({ seatname, seatnum }, ["seatname", "seatnum"]) |
| | | ) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "system", |
| | | action: "afk", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // ç¤ºé² |
| | | online() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if ( |
| | | !this.validateParams({ seatname, seatnum }, ["seatname", "seatnum"]) |
| | | ) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "system", |
| | | action: "online", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // 代ç |
| | | pickup() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "pickup", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // ææº |
| | | hangup() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "hangup", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å¤å¼ |
| | | callout() { |
| | | const { seatname, seatnum, phone } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, phone }, ["seatnum", "phone"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "callout", |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // éè¯è½¬ç§» |
| | | transfer() { |
| | | const { seatname, seatnum, phone, uuid } = this.config; |
| | | |
| | | if ( |
| | | !this.validateParams({ seatnum, phone, uuid }, [ |
| | | "seatnum", |
| | | "phone", |
| | | "uuid", |
| | | ]) |
| | | ) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "transfer", |
| | | uuid: uuid, |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // éè¯è½¬ç§»æ¶å |
| | | transferresume() { |
| | | const { seatname, seatnum, phone, uuid } = this.config; |
| | | |
| | | if ( |
| | | !this.validateParams({ seatnum, phone, uuid }, [ |
| | | "seatnum", |
| | | "phone", |
| | | "uuid", |
| | | ]) |
| | | ) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "transferresume", |
| | | uuid: uuid, |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // éè¯ä¿æ |
| | | hold() { |
| | | const { seatname, seatnum, uuid } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, uuid }, ["seatnum", "uuid"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "hold", |
| | | uuid: uuid, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // éè¯ä¿ææ¶å |
| | | holdresume() { |
| | | const { seatname, seatnum, uuid } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, uuid }, ["seatnum", "uuid"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "holdresume", |
| | | uuid: uuid, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // éè¯å¼ºæ |
| | | remove() { |
| | | const { seatname, seatnum, phone } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, phone }, ["seatnum", "phone"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "remove", |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // éè¯å¼ºæ |
| | | insert() { |
| | | const { seatname, seatnum, phone } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, phone }, ["seatnum", "phone"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "insert", |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // çå¬ |
| | | monitor() { |
| | | const { seatname, seatnum, phone } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, phone }, ["seatnum", "phone"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "monitor", |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // çå¬è½¬éè¯ |
| | | monitor_to_talk() { |
| | | const { seatname, seatnum, phone } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, phone }, ["seatnum", "phone"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "monitor_to_talk", |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // çå¬ç»æ |
| | | monitor_end() { |
| | | const { seatname, seatnum, phone } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, phone }, ["seatnum", "phone"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "monitor_end", |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // éæ©éè¯ |
| | | choosecall() { |
| | | const { seatname, seatnum, uuid } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, uuid }, ["seatnum", "uuid"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "choosecall", |
| | | uuid: uuid, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // ä»£æ¥ |
| | | replacecall() { |
| | | const { seatname, seatnum, phone } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, phone }, ["seatnum", "phone"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "replacecall", |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // 䏿¹éè¯ |
| | | three() { |
| | | const { seatname, seatnum, phone } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, phone }, ["seatnum", "phone"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "three", |
| | | phone: phone, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å¨è¯¢å¼å§ |
| | | handoff_ready() { |
| | | const { seatname, seatnum, uuid } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, uuid }, ["seatnum", "uuid"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "handoff_ready", |
| | | uuid: uuid, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å¨è¯¢å¼å« |
| | | handoff_call() { |
| | | const { seatname, seatnum, other, uuid } = this.config; |
| | | |
| | | if ( |
| | | !this.validateParams({ seatnum, other, uuid }, [ |
| | | "seatnum", |
| | | "other", |
| | | "uuid", |
| | | ]) |
| | | ) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "handoff_call", |
| | | uuid: uuid, |
| | | phone: other, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å¨è¯¢æ¶å |
| | | handoff_resume() { |
| | | const { seatname, seatnum, uuid } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, uuid }, ["seatnum", "uuid"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "handoff_resume", |
| | | uuid: uuid, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å¨è¯¢è½¬ç§» |
| | | handoff_transfer() { |
| | | const { seatname, seatnum, other, uuid } = this.config; |
| | | |
| | | if ( |
| | | !this.validateParams({ seatnum, other, uuid }, [ |
| | | "seatnum", |
| | | "other", |
| | | "uuid", |
| | | ]) |
| | | ) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "handoff_transfer", |
| | | uuid: uuid, |
| | | phone: other, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å¨è¯¢ä¸æ¹ |
| | | handoff_three() { |
| | | const { seatname, seatnum, uuid } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, uuid }, ["seatnum", "uuid"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "handoff_three", |
| | | uuid: uuid, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å¼å§éè¯å½é³ |
| | | record_start() { |
| | | const { seatname, seatnum, uuid } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, uuid }, ["seatnum", "uuid"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "record_start", |
| | | uuid: uuid, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // 忢éè¯å½é³ |
| | | record_stop() { |
| | | const { seatname, seatnum, uuid } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum, uuid }, ["seatnum", "uuid"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "control", |
| | | action: "record_stop", |
| | | uuid: uuid, |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // æå¼åå¸ç¶æ |
| | | openseatlist() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "openseatlist", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å
³éåå¸ç¶æ |
| | | closeseatlist() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "closeseatlist", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // æå¼éåä¿¡æ¯ |
| | | openqueues() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "openqueues", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å
³ééåä¿¡æ¯ |
| | | closequeues() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "closequeues", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // æå¼éè¯ä¿¡æ¯ |
| | | opencalllist() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "opencalllist", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å
³ééè¯ä¿¡æ¯ |
| | | closecalllist() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "closecalllist", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // æå¼è·¯ç±ä¿¡æ¯ |
| | | openroutelist() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "openroutelist", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å
³éè·¯ç±ä¿¡æ¯ |
| | | closeroutelist() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "closeroutelist", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // è·ååå¸ä¿¡æ¯ |
| | | seatlist() { |
| | | const { group } = this.config; |
| | | |
| | | if (!this.validateParams({ group }, ["group"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "seatlist", |
| | | group: group, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // è·åéåä¿¡æ¯ |
| | | queues() { |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "queues", |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // è·åéè¯ä¿¡æ¯ |
| | | calllist() { |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "calllist", |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // è·åè·¯ç±ä¿¡æ¯ |
| | | routelist() { |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "routelist", |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // è·åå¤å¼åæ°ä¿¡æ¯ |
| | | batch() { |
| | | const { paramid } = this.config; |
| | | |
| | | if (!this.validateParams({ paramid }, ["paramid"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "status", |
| | | action: "batch", |
| | | paramid: paramid, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å¼å§å¤å¼ä»»å¡ |
| | | batch_start() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "system", |
| | | action: "batch_start", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // 忢å¤å¼ä»»å¡ |
| | | batch_stop() { |
| | | const { seatname, seatnum } = this.config; |
| | | |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "system", |
| | | action: "batch_stop", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // å¿è·³å
|
| | | keepalive(seatname, seatnum) { |
| | | if (!this.validateParams({ seatnum }, ["seatnum"])) { |
| | | return; |
| | | } |
| | | |
| | | const protocol = { |
| | | cmd: "system", |
| | | action: "keepalive", |
| | | seatname: seatname, |
| | | seatnum: seatnum, |
| | | timestamp: Date.now(), |
| | | }; |
| | | this.sendWebSocketMessage(protocol); |
| | | }, |
| | | |
| | | // æ¸
餿¥å¿ |
| | | testclear() { |
| | | this.logs = ""; |
| | | this.addLog("æ¥å¿å·²æ¸
é¤"); |
| | | }, |
| | | |
| | | // æ·»å æ¥å¿ |
| | | addLog(message) { |
| | | const timestamp = new Date().toLocaleTimeString(); |
| | | this.logs += `[${timestamp}] ${message}\n`; |
| | | |
| | | // éå¶æ¥å¿é¿åº¦ï¼é²æ¢å
åæº¢åº |
| | | const logLines = this.logs.split("\n"); |
| | | if (logLines.length > 100) { |
| | | this.logs = logLines.slice(-50).join("\n"); |
| | | } |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .websocket-demo { |
| | | font-family: Arial, sans-serif; |
| | | padding: 20px; |
| | | max-width: 1200px; |
| | | margin: 0 auto; |
| | | } |
| | | |
| | | .config-area { |
| | | margin-bottom: 20px; |
| | | padding: 15px; |
| | | border: 1px solid #ddd; |
| | | border-radius: 4px; |
| | | background-color: #f9f9f9; |
| | | } |
| | | |
| | | .input-group { |
| | | display: flex; |
| | | flex-wrap: wrap; |
| | | align-items: center; |
| | | gap: 10px; |
| | | margin-bottom: 10px; |
| | | } |
| | | |
| | | .input-group label { |
| | | font-weight: bold; |
| | | min-width: 80px; |
| | | } |
| | | |
| | | .input-group input { |
| | | padding: 5px 10px; |
| | | border: 1px solid #ccc; |
| | | border-radius: 3px; |
| | | width: 120px; |
| | | } |
| | | |
| | | .button-area { |
| | | margin-bottom: 20px; |
| | | } |
| | | |
| | | .button-row { |
| | | display: flex; |
| | | flex-wrap: wrap; |
| | | gap: 5px; |
| | | margin-bottom: 10px; |
| | | } |
| | | |
| | | .button-row button { |
| | | padding: 8px 15px; |
| | | border: 1px solid #ccc; |
| | | border-radius: 3px; |
| | | background-color: #f0f0f0; |
| | | cursor: pointer; |
| | | transition: background-color 0.3s; |
| | | font-size: 12px; |
| | | } |
| | | |
| | | .button-row button:hover { |
| | | background-color: #e0e0e0; |
| | | } |
| | | |
| | | .button-row button:active { |
| | | background-color: #d0d0d0; |
| | | transform: translateY(1px); |
| | | } |
| | | |
| | | .log-area { |
| | | height: 300px; |
| | | overflow-y: auto; |
| | | border: 1px solid #ccc; |
| | | padding: 10px; |
| | | background-color: #f5f5f5; |
| | | white-space: pre-wrap; |
| | | font-family: "Courier New", monospace; |
| | | font-size: 12px; |
| | | line-height: 1.4; |
| | | } |
| | | |
| | | h3 { |
| | | color: #333; |
| | | border-bottom: 2px solid #eee; |
| | | padding-bottom: 10px; |
| | | display: flex; |
| | | justify-content: space-between; |
| | | align-items: center; |
| | | } |
| | | |
| | | h3 button { |
| | | padding: 5px 10px; |
| | | font-size: 12px; |
| | | background-color: #f0f0f0; |
| | | border: 1px solid #ccc; |
| | | border-radius: 3px; |
| | | cursor: pointer; |
| | | } |
| | | |
| | | /* ååºå¼è®¾è®¡ */ |
| | | @media (max-width: 768px) { |
| | | .websocket-demo { |
| | | padding: 10px; |
| | | } |
| | | |
| | | .input-group { |
| | | flex-direction: column; |
| | | align-items: flex-start; |
| | | } |
| | | |
| | | .input-group input { |
| | | width: 100%; |
| | | } |
| | | |
| | | .button-row { |
| | | flex-direction: column; |
| | | } |
| | | |
| | | .button-row button { |
| | | width: 100%; |
| | | margin-bottom: 5px; |
| | | } |
| | | } |
| | | </style> |