From a8799531bd3918b2416b95914b02101ce1337ddb Mon Sep 17 00:00:00 2001 From: heimawl <1785969728@qq.com> Date: 星期二, 04 七月 2023 14:00:14 +0800 Subject: [PATCH] 11 --- src/views/shortmessage/communication/index.vue | 68 ++++++++++++++++++++++++++++++---- 1 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/views/shortmessage/communication/index.vue b/src/views/shortmessage/communication/index.vue index 34e458f..4bb666e 100644 --- a/src/views/shortmessage/communication/index.vue +++ b/src/views/shortmessage/communication/index.vue @@ -65,7 +65,11 @@ <script> import LemonMessageVoice from "./lemon-message-voice"; import EmojiData from "./database/emoji"; -import { sendWebsocket, closeWebsocket } from "@/websocket/websocket.js"; +import { + sendWebsocket, + websocketSend, + closeWebsocket, +} from "@/websocket/websocket.js"; // Vue.component(LemonMessageVoice.name, LemonMessageVoice); // 鑾峰彇鏃堕棿 const getTime = () => { @@ -581,19 +585,66 @@ instance.closeDrawer(); }, // 寤虹珛杩炴帴 - requstWs() { + requstWs(message, next, file) { console.log("杩炴帴"); // 闃叉鐢ㄦ埛澶氭杩炵画鐐瑰嚮鍙戣捣璇锋眰锛屾墍浠ヨ鍏堝叧闂笂娆$殑ws璇锋眰銆� - closeWebsocket(); + // closeWebsocket(); + + if (file) { + const reader = new FileReader(); + console.log(reader); + console.log(file); + reader.onload = (file) => { + console.log(file); + console.log(reader); + const imageData = reader.result; + //鏂囦欢瀛楄妭澶у皬 + // const fileSize = file.loaded; + const fileSize = imageData.length; + console.log("byteLength 锛� ", fileSize); + const chunkSize = 4096; // 璁剧疆姣忎釜鏁版嵁鍧楃殑澶у皬 + let offset = 0; + + // 鍒嗗潡浼犺緭鍥剧墖鏁版嵁 + while (offset < imageData.length) { + const chunk = imageData.slice(offset, offset + chunkSize); + const obj = { + type: file.type, + userId: "1", //鎺ユ敹鏁版嵁鏂� + fileSize: fileSize, + image: chunk, + }; + console.log(JSON.stringify(obj)); + // 鍙戣捣ws璇锋眰 + // sendWebsocket( + // "ws://192.168.31.121:8080/chat?userId=2", + // JSON.stringify(obj), + // this.wsMessage, + // this.wsError + // ); + websocketSend(JSON.stringify(obj)); + offset += chunkSize; + + console.log("offset 锛� ", offset); + } + + // 鍙戦�佸畬鎴愭爣璁� + console.log("message "); + }; + + return reader.readAsDataURL(file); + } + // 璺熷悗绔崗鍟嗭紝闇�瑕佷粈涔堝弬鏁版暟鎹粰鍚庡彴 const obj = { - type: "text", - content: "甯濆緱鍦g浉鐩告洶搴�", + type: "object", userId: "1", //鎺ユ敹鏁版嵁鏂� + fileSize: "1212", + image: "12", }; // 鍙戣捣ws璇锋眰 sendWebsocket( - "ws://192.168.1.4:8080/chat?userId=2", + "ws://192.168.31.121:8080/chat?userId=2", obj, this.wsMessage, this.wsError @@ -625,9 +676,10 @@ }, // 鍙戦�佹柊娑堟伅瑙﹀彂 handleSend(message, next, file) { - console.log(message, file); + console.log(message); + console.log(file); console.log(next); - this.requstWs(); + this.requstWs(message, next, file); setTimeout(() => { next(); }, 1000); -- Gitblit v1.9.3