You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
4 years ago
|
package ws
|
||
4 years ago
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/gorilla/websocket"
|
||
4 years ago
|
"net/http"
|
||
4 years ago
|
)
|
||
|
|
||
|
type User struct {
|
||
4 years ago
|
Conn *websocket.Conn
|
||
|
Name string
|
||
|
Id string
|
||
|
Avator string
|
||
|
To_id string
|
||
4 years ago
|
}
|
||
|
type Message struct {
|
||
|
conn *websocket.Conn
|
||
|
context *gin.Context
|
||
|
content []byte
|
||
|
messageType int
|
||
|
}
|
||
|
type TypeMessage struct {
|
||
|
Type interface{} `json:"type"`
|
||
|
Data interface{} `json:"data"`
|
||
|
}
|
||
|
type ClientMessage struct {
|
||
|
Name string `json:"name"`
|
||
|
Avator string `json:"avator"`
|
||
|
Id string `json:"id"`
|
||
|
VisitorId string `json:"visitor_id"`
|
||
|
Group string `json:"group"`
|
||
|
Time string `json:"time"`
|
||
|
ToId string `json:"to_id"`
|
||
|
Content string `json:"content"`
|
||
|
City string `json:"city"`
|
||
|
ClientIp string `json:"client_ip"`
|
||
|
Refer string `json:"refer"`
|
||
|
}
|
||
|
|
||
4 years ago
|
var ClientList = make(map[string]*User)
|
||
|
var KefuList = make(map[string][]*User)
|
||
4 years ago
|
var message = make(chan *Message)
|
||
|
var upgrader = websocket.Upgrader{}
|
||
|
|
||
|
func init() {
|
||
|
upgrader = websocket.Upgrader{
|
||
|
ReadBufferSize: 1024,
|
||
|
WriteBufferSize: 1024,
|
||
4 years ago
|
// 解决跨域问题
|
||
|
CheckOrigin: func(r *http.Request) bool {
|
||
|
return true
|
||
|
},
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
}
|