change chat
This commit is contained in:
parent
336c57e042
commit
954943a750
6 changed files with 1008 additions and 1251 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -330,7 +330,7 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
|
|||
const targetUser = userList.value.find((d: any) => d.id === chatTargetId.value)
|
||||
//console.log(targetUser)
|
||||
if(targetUser.isOnline) {
|
||||
const postUrl = `http://${targetUser.ip}:56780/message`
|
||||
const postUrl = `http://${targetUser.ip}:56780/localchat/message`
|
||||
const completion = await fetch(postUrl, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(saveMsg),
|
||||
|
|
@ -408,7 +408,7 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
|
|||
formData.append("ip", hostInfo.value.ip);
|
||||
formData.append("hostname", hostInfo.value.hostname);
|
||||
//console.log(formData)
|
||||
const postUrl = `http://${targetUser.ip}:56780/upload`
|
||||
const postUrl = `http://${targetUser.ip}:56780/localchat/upload`
|
||||
const res = await fetch(postUrl, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
|
|
|
|||
0
frontend/wailsjs/go/app/App.d.ts
vendored
Normal file → Executable file
0
frontend/wailsjs/go/app/App.d.ts
vendored
Normal file → Executable file
0
frontend/wailsjs/go/app/App.js
Normal file → Executable file
0
frontend/wailsjs/go/app/App.js
Normal file → Executable file
|
|
@ -1,6 +1,3 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package localchat
|
||||
|
||||
import (
|
||||
|
|
@ -11,21 +8,30 @@ import (
|
|||
)
|
||||
|
||||
func StartServiceDiscovery() {
|
||||
conn, err := net.ListenPacket("udp", broadcastAddr)
|
||||
// 解析多播地址
|
||||
addr, err := net.ResolveUDPAddr("udp4", broadcastAddr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Println("Error resolving multicast address:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 监听本地网络接口上的多播地址
|
||||
conn, err := net.ListenMulticastUDP("udp4", nil, addr)
|
||||
if err != nil {
|
||||
fmt.Println("Error listening on multicast address:", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
buffer := make([]byte, 1024)
|
||||
for {
|
||||
n, addr, err := conn.ReadFrom(buffer)
|
||||
n, addr, err := conn.ReadFromUDP(buffer)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Printf("Error reading from UDP: %v", err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("Received message: %s from %s\n", buffer[:n], addr)
|
||||
|
||||
var udpMsg UdpMessage
|
||||
err = json.Unmarshal(buffer[:n], &udpMsg)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package localchat
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
func StartServiceDiscovery() {
|
||||
// 解析多播地址
|
||||
addr, err := net.ResolveUDPAddr("udp4", broadcastAddr)
|
||||
if err != nil {
|
||||
fmt.Println("Error resolving multicast address:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 监听本地网络接口上的多播地址
|
||||
conn, err := net.ListenMulticastUDP("udp4", nil, addr)
|
||||
if err != nil {
|
||||
fmt.Println("Error listening on multicast address:", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
buffer := make([]byte, 1024)
|
||||
for {
|
||||
n, addr, err := conn.ReadFromUDP(buffer)
|
||||
if err != nil {
|
||||
log.Printf("Error reading from UDP: %v", err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("Received message: %s from %s\n", buffer[:n], addr)
|
||||
|
||||
var udpMsg UdpMessage
|
||||
err = json.Unmarshal(buffer[:n], &udpMsg)
|
||||
if err != nil {
|
||||
fmt.Printf("Error unmarshalling JSON: %v\n", err)
|
||||
continue
|
||||
}
|
||||
log.Printf("Get message: %+v", udpMsg)
|
||||
OnlineUsers[udpMsg.IP] = udpMsg
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue