Skip to content

Commit

Permalink
feat: add source field to ConnectMeta (#31)
Browse files Browse the repository at this point in the history
* feat: add source field to ConnectMeta

* feat: add source field to IConnectMeta

---------

Co-authored-by: chenyuxin2 <chenyuxin2@kingsoft.com>
  • Loading branch information
easonchen147 and chenyuxin2 authored May 29, 2024
1 parent 67ba5bb commit 7c9cacc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ws/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type ConnectionMeta struct {
UserId string //userId
Typed int //客户端类型枚举
DeviceId string //设备ID
Source string //defines where the connection comes from
Version int //版本
Charset int //客户端使用的字符集

Expand All @@ -112,7 +113,7 @@ type ConnectionMeta struct {
}

func (m *ConnectionMeta) BuildConnId() string {
return fmt.Sprintf("%v-%v-%v", m.UserId, m.Typed, m.DeviceId)
return fmt.Sprintf("%v-%v-%v-%v", m.UserId, m.Typed, m.DeviceId, m.Source)
}

func (c *Connection) Id() string {
Expand All @@ -131,6 +132,10 @@ func (c *Connection) DeviceId() string {
return c.meta.DeviceId
}

func (c *Connection) Source() string {
return c.meta.Source
}

func (c *Connection) Version() int {
return c.meta.Version
}
Expand Down
1 change: 1 addition & 0 deletions ws/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type IConnection interface {
UserId() string
Type() int
DeviceId() string
Source() string
Version() int
Charset() int
ClientIp() string
Expand Down
6 changes: 6 additions & 0 deletions ws/wss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func TestWssRequestResponse(t *testing.T) {
UserId: r.URL.Query().Get("uid"),
Typed: 0,
DeviceId: "",
Source: "",
Version: 0,
Charset: 0,
}
Expand Down Expand Up @@ -270,6 +271,7 @@ func TestWssRequestResponseWithTimeout(t *testing.T) {
UserId: r.URL.Query().Get("uid"),
Typed: 0,
DeviceId: "",
Source: "",
Version: 0,
Charset: 0,
}
Expand Down Expand Up @@ -399,6 +401,7 @@ func TestWssSendMessage(t *testing.T) {
UserId: r.URL.Query().Get("uid"),
Typed: gocast.ToInt(r.URL.Query().Get("typed")),
DeviceId: r.URL.Query().Get("deviceId"),
Source: r.URL.Query().Get("source"),
Version: gocast.ToInt(r.URL.Query().Get("version")),
Charset: gocast.ToInt(r.URL.Query().Get("charset")),
}
Expand Down Expand Up @@ -535,6 +538,7 @@ func TestWssDialConnect(t *testing.T) {
UserId: r.URL.Query().Get("uid"),
Typed: 0,
DeviceId: "",
Source: "",
Version: 0,
Charset: 0,
}
Expand Down Expand Up @@ -655,6 +659,7 @@ func TestWssDialRetryConnect(t *testing.T) {
UserId: r.URL.Query().Get("uid"),
Typed: 0,
DeviceId: "",
Source: "",
Version: 0,
Charset: 0,
}
Expand Down Expand Up @@ -699,6 +704,7 @@ func TestAutoReDialConnect(t *testing.T) {
UserId: r.URL.Query().Get("uid"),
Typed: 0,
DeviceId: "",
Source: "",
Version: 0,
Charset: 0,
}
Expand Down

0 comments on commit 7c9cacc

Please sign in to comment.