bigbluebutton-Github/bbb-graphql-middleware/internal/websrv/conninithandler.go

51 lines
1.6 KiB
Go
Raw Normal View History

2023-04-27 09:03:40 +08:00
package websrv
import (
"context"
"github.com/iMDT/bbb-graphql-middleware/internal/common"
2023-04-27 09:03:40 +08:00
log "github.com/sirupsen/logrus"
"sync"
)
func ConnectionInitHandler(browserConnectionId string, browserConnectionContext context.Context, fromBrowser *common.SafeChannel, wg *sync.WaitGroup) {
log := log.WithField("_routine", "ConnectionInitHandler").WithField("browserConnectionId", browserConnectionId)
log.Debugf("starting")
2023-04-27 09:03:40 +08:00
defer wg.Done()
defer log.Debugf("finished")
2023-04-27 09:03:40 +08:00
BrowserConnectionsMutex.RLock()
browserConnection := BrowserConnections[browserConnectionId]
BrowserConnectionsMutex.RUnlock()
2023-04-27 09:03:40 +08:00
// Intercept the fromBrowserMessage channel to get the sessionToken
for {
fromBrowserMessage, ok := fromBrowser.Receive()
if !ok {
//Received all messages. Channel is closed
return
}
2023-04-27 09:03:40 +08:00
if browserConnection.SessionToken == "" {
var fromBrowserMessageAsMap = fromBrowserMessage.(map[string]interface{})
if fromBrowserMessageAsMap["type"] == "connection_init" {
var payloadAsMap = fromBrowserMessageAsMap["payload"].(map[string]interface{})
var headersAsMap = payloadAsMap["headers"].(map[string]interface{})
var sessionToken = headersAsMap["X-Session-Token"]
if sessionToken != nil {
sessionToken := headersAsMap["X-Session-Token"].(string)
log.Infof("[SessionTokenReader] intercepted session token %v", sessionToken)
BrowserConnectionsMutex.Lock()
2023-04-27 09:03:40 +08:00
browserConnection.SessionToken = sessionToken
BrowserConnectionsMutex.Unlock()
go SendUserGraphqlConnectionStablishedSysMsg(sessionToken, browserConnectionId)
fromBrowser.Close()
break
2023-04-27 09:03:40 +08:00
}
}
}
}
}