웹 소켓 접속 종료 시그니쳐 변경
This commit is contained in:
@ -18,11 +18,12 @@ const (
|
||||
|
||||
type apiFuncType func(ApiCallContext)
|
||||
type connFuncType func(*websocket.Conn, *Sender)
|
||||
type disconnFuncType func(string, *Sender)
|
||||
|
||||
type WebsocketApiHandler struct {
|
||||
methods map[string]apiFuncType
|
||||
connfunc connFuncType
|
||||
disconnfunc connFuncType
|
||||
disconnfunc disconnFuncType
|
||||
originalReceiverName string
|
||||
}
|
||||
|
||||
@ -40,7 +41,7 @@ func MakeWebsocketApiHandler[T any](receiver *T, receiverName string) WebsocketA
|
||||
}
|
||||
|
||||
var connfunc connFuncType
|
||||
var disconnfunc connFuncType
|
||||
var disconnfunc disconnFuncType
|
||||
|
||||
for i := 0; i < tp.NumMethod(); i++ {
|
||||
method := tp.Method(i)
|
||||
@ -70,7 +71,7 @@ func MakeWebsocketApiHandler[T any](receiver *T, receiverName string) WebsocketA
|
||||
if method.Type.NumIn() != 3 {
|
||||
continue
|
||||
}
|
||||
if method.Type.In(1) != reflect.TypeOf((*websocket.Conn)(nil)) {
|
||||
if method.Type.In(1) != reflect.TypeOf("") {
|
||||
continue
|
||||
}
|
||||
if method.Type.In(2) != reflect.TypeOf((*Sender)(nil)) {
|
||||
@ -79,10 +80,10 @@ func MakeWebsocketApiHandler[T any](receiver *T, receiverName string) WebsocketA
|
||||
funcptr := method.Func.Pointer()
|
||||
p1 := unsafe.Pointer(&funcptr)
|
||||
p2 := unsafe.Pointer(&p1)
|
||||
disconnfuncptr := (*func(*T, *websocket.Conn, *Sender))(p2)
|
||||
disconnfuncptr := (*func(*T, string, *Sender))(p2)
|
||||
|
||||
disconnfunc = func(c *websocket.Conn, s *Sender) {
|
||||
(*disconnfuncptr)(receiver, c, s)
|
||||
disconnfunc = func(msg string, s *Sender) {
|
||||
(*disconnfuncptr)(receiver, msg, s)
|
||||
}
|
||||
} else {
|
||||
if method.Type.NumIn() != 2 {
|
||||
@ -114,7 +115,7 @@ type WebsocketApiBroker struct {
|
||||
methods map[string]apiFuncType
|
||||
methods_dup map[string][]apiFuncType
|
||||
connFuncs []connFuncType
|
||||
disconnFuncs []connFuncType
|
||||
disconnFuncs []disconnFuncType
|
||||
}
|
||||
|
||||
func (hc *WebsocketApiBroker) AddHandler(receiver WebsocketApiHandler) {
|
||||
@ -148,7 +149,7 @@ func (hc *WebsocketApiBroker) AddHandler(receiver WebsocketApiHandler) {
|
||||
if receiver.disconnfunc != nil {
|
||||
// disconnfunc은 역순
|
||||
logger.Printf("ws api registered : %s.ClientDisconnected\n", receiver.originalReceiverName)
|
||||
hc.disconnFuncs = append([]connFuncType{receiver.disconnfunc}, hc.disconnFuncs...)
|
||||
hc.disconnFuncs = append([]disconnFuncType{receiver.disconnfunc}, hc.disconnFuncs...)
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,7 +161,7 @@ func (hc *WebsocketApiBroker) ClientConnected(c *wsconn) {
|
||||
|
||||
func (hc *WebsocketApiBroker) ClientDisconnected(c *wsconn) {
|
||||
for _, v := range hc.disconnFuncs {
|
||||
v(c.Conn, c.sender)
|
||||
v(c.closeMessage, c.sender)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user