2021-05-13 17:51:06 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
2021-12-03 23:32:00 +08:00
|
|
|
package gclient
|
2021-05-13 17:51:06 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2021-11-13 23:23:55 +08:00
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
2021-05-13 17:51:06 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// WebSocketClient wraps the underlying websocket client connection
|
|
|
|
// and provides convenient functions.
|
|
|
|
type WebSocketClient struct {
|
|
|
|
*websocket.Dialer
|
|
|
|
}
|
|
|
|
|
2021-12-03 23:32:00 +08:00
|
|
|
// NewWebSocket creates and returns a new WebSocketClient object.
|
|
|
|
func NewWebSocket() *WebSocketClient {
|
2021-05-13 17:51:06 +08:00
|
|
|
return &WebSocketClient{
|
|
|
|
&websocket.Dialer{
|
|
|
|
Proxy: http.ProxyFromEnvironment,
|
|
|
|
HandshakeTimeout: 45 * time.Second,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|