yasuto2002 / SyncMemo

0 stars 0 forks source link

とりあえずgoでwebSoketを試してみる #5

Closed yasuto2002 closed 1 year ago

yasuto2002 commented 1 year ago

やりたいこと

yasuto2002 commented 1 year ago

脳死でとりあえず動かしてみる

https://zenn.dev/tady/articles/adcdc65617ae57

を参考にwebsocketを実装

デフォルトパッケージのwebsocket

https://pkg.go.dev/golang.org/x/net/websocket

yasuto2002 commented 1 year ago

websocket自体は動くように

スクリーンショット 2022-12-09 10 19 25
yasuto2002 commented 1 year ago

nuxt3でwebsocketしたい

https://github.com/theturtle32/WebSocket-Node

使えない?

<script lang="ts" setup>
import * as WebSocket from "websocket";
const socket = new WebSocket.w3cwebsocket("ws://localhost:80/ws");
</script>
スクリーンショット 2022-12-09 11 03 28

__vite_ssr_import_1__.w3cwebsocket is not a constructor

が出る

調査

vueの中ではwebSocketAPIは使えない

onMounted( () => { const config = useRuntimeConfig() const ws = new WebSocket(config.socket) ws.onopen = function () { console.log("接続が開かれたときに呼び出されるイベント"); }; ws.onmessage = function (event) { console.log(event.data) }; function send() { let send_msg = "aaaa" ws.send(send_msg); } })



## 接続自体は可能に
<img width="1353" alt="スクリーンショット 2022-12-09 10 31 31" src="https://user-images.githubusercontent.com/77332271/206602621-22600e50-ee29-4025-848f-6024d975d8b9.png">
yasuto2002 commented 1 year ago

改善できる?

yasuto2002 commented 1 year ago

8 へ