This commit is contained in:
crusader 2018-04-13 21:20:16 +09:00
parent 94901d8877
commit e092f7ef4b
2 changed files with 4 additions and 55 deletions

View File

@ -11,6 +11,8 @@ func New(_config *config.Config) *csgw.Server {
VerifyKey: _config.VerifyKey,
SignKey: _config.SignKey,
}
ws.UseSession = true
sh := &ServerHandlers{
ServerHandlers: *_config.ServerHandler,
Config: _config,

View File

@ -3,7 +3,6 @@ package servlet
import (
"crypto/rsa"
"fmt"
"sync"
"git.loafle.net/commons/logging-go"
"git.loafle.net/commons/server-go"
@ -27,8 +26,6 @@ type WebappServlets struct {
VerifyKey *rsa.PublicKey
SignKey *rsa.PrivateKey
sessions sync.Map
}
func (s *WebappServlets) Init(serverCtx server.ServerCtx) error {
@ -100,21 +97,10 @@ func (s *WebappServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.R
func (s *WebappServlets) OnConnect(servletCtx server.ServletCtx, conn socket.Conn) {
s.RPCServlets.OnConnect(servletCtx, conn)
sessionID := servletCtx.GetAttribute(og.SessionIDKey)
targetID := servletCtx.GetAttribute(og.SessionTargetIDKey)
if nil != sessionID && nil != targetID {
s.sessions.Store(sessionID.(string), ogrs.RetainSession(targetID.(string), servletCtx))
}
}
func (s *WebappServlets) OnDisconnect(servletCtx server.ServletCtx) {
s.RPCServlets.OnDisconnect(servletCtx)
sessionID := servletCtx.GetAttribute(og.SessionIDKey)
if nil != sessionID {
s.sessions.Delete(sessionID.(string))
}
}
func (s *WebappServlets) handleSubscribe(serverCtx server.ServerCtx, subscribeChan <-chan *ogs.Message) {
@ -130,9 +116,9 @@ LOOP:
switch msg.TargetType {
case ogs.MEMBER:
sessions = s.getMemberSessionsByTargetIDs(msg.Targets)
sessions = s.GetSessionsByTargetIDs(msg.Targets)
case ogs.MEMBER_SESSION:
sessions = s.getMemberSessions(msg.Targets)
sessions = s.GetSessions(msg.Targets)
default:
logging.Logger().Warnf("Subscriber: Unknown TargetType %s", msg.TargetType)
continue LOOP
@ -152,42 +138,3 @@ LOOP:
}
}
}
func (s *WebappServlets) getMemberSessions(sessionIDs []string) []*ogrs.Session {
var sessions []*ogrs.Session
if nil == sessionIDs || 0 == len(sessionIDs) {
return sessions
}
for _, sessionID := range sessionIDs {
session, ok := s.sessions.Load(sessionID)
if ok {
sessions = append(sessions, session.(*ogrs.Session))
}
}
return sessions
}
func (s *WebappServlets) getMemberSessionsByTargetIDs(targetIDs []string) []*ogrs.Session {
var sessions []*ogrs.Session
if nil == targetIDs || 0 == len(targetIDs) {
return sessions
}
s.sessions.Range(func(k, v interface{}) bool {
session := v.(*ogrs.Session)
for _, targetID := range targetIDs {
if session.TargetID == targetID {
sessions = append(sessions, session)
break
}
}
return true
})
return sessions
}