useWebSocket 麻烦前端小哥丢点代码示例,不太会用哈。
1
HoseaDev 2023-11-29 17:02:31 +08:00
1.文档。
2.GPT 。 |
3
lozzow 2023-11-29 17:19:19 +08:00
|
4
webluoye 2023-11-29 18:09:06 +08:00
google 的 bard 可以回复
|
5
Puteulanus 2023-11-29 18:33:40 +08:00
把下面的 source 给 ChatGPT 让它重写了文档和示例,你看能用不 https://chat.openai.com/share/1a3f76ba-40ab-48ae-be95-d3107234ae7a
|
6
lx000377 2023-11-29 18:53:06 +08:00
|
7
tlerbao OP @lx000377
小哥 原生中 ws.onopen 里有一些操作,对应 useWebSockt 应该写在哪里? ``` ws = new WebSocket(url); ws.onopen = function () { m_isConnectWS = true; unload(); sendInitMsg(); //初始化 sendGetPath(); //获取电脑中的路径 m_closed = false; }; ``` |
8
Dragonphy 2023-11-30 08:54:07 +08:00
GPT 不会你可以把源码实现塞给他
|
9
xujiahui 2023-11-30 09:25:47 +08:00
文档不是写的挺清楚吗
|
10
xujiahui 2023-11-30 09:30:39 +08:00
export interface UseWebSocketReturn<T> {
/** * Reference to the latest data received via the websocket, * can be watched to respond to incoming messages */ data: Ref<T | null> /** * The current websocket status, can be only one of: * 'OPEN', 'CONNECTING', 'CLOSED' */ status: Ref<WebSocketStatus> /** * Closes the websocket connection gracefully. */ close: WebSocket['close'] /** * Reopen the websocket connection. * If there the current one is active, will close it before opening a new one. */ open: Fn /** * Sends data through the websocket connection. * * @param data * @param useBuffer when the socket is not yet open, store the data into the buffer and sent them one connected. Default to true. */ send: (data: string | ArrayBuffer | Blob, useBuffer?: boolean) => boolean /** * Reference to the WebSocket instance. */ ws: Ref<WebSocket | undefined> } |