Comments (5)
temporary solution:
i want set a function variable in App struct.
before pitaya-app started ,state it. im not sure this is correct (i did it in version 1.x). Maybe i can do something in SessionPool ? i still haven't quite figured out how it works.
thanks for your reply!
from pitaya.
what is the use case you're trying to cover?
from pitaya.
use case in demo (in pitaya version 1.x) :
func main() {
defer pitaya.Shutdown()
s := json.NewSerializer()
conf := configApp()
pitaya.SetSerializer(s)
gsi := groups.NewMemoryGroupService(config.NewConfig(conf))
pitaya.InitGroups(gsi)
err := pitaya.GroupCreate(context.Background(), "room")
if err != nil {
panic(err)
}
// rewrite component and handler name
room := NewRoom()
pitaya.Register(room,
component.WithName("room"),
component.WithNameFunc(strings.ToLower),
)
log.SetFlags(log.LstdFlags | log.Llongfile)
http.Handle("/web/", http.StripPrefix("/web/", http.FileServer(http.Dir("web"))))
go http.ListenAndServe(":3251", nil)
t := acceptor.NewWSAcceptor(":3250")
pitaya.AddAcceptor(t)
pitaya.SetBeforeHandshake(func(s *session.Session, data *session.HandshakeData) error {
t, ok := data.User["token"]
if !ok {
return fmt.Errorf("token not exist")
}
token, ok := t.(string)
if !ok {
return fmt.Errorf("token error")
}
logger.Log.Debugf("token ok %v", token)
return nil
})
pitaya.Configure(true, "chat", pitaya.Standalone, map[string]string{}, conf)
pitaya.Start()
type App struct {
// ...
beforeHandshake func(*session.Session, *session.HandshakeData) error
}
func SetBeforeHandshake(fn func(*session.Session, *session.HandshakeData) error) {
app.beforeHandshake = fn
}
I'm not sure this is expected in pitaya. but it worked
What should I do better in pitaya-2.x?
thanks for the help !
from pitaya.
Related Issues (20)
- Concerns about the Global Message Channel 'chLocalProcess' in Pitaya HOT 6
- What about using redis pub/sub to implement rpc and broadcast? HOT 1
- Why does libpitaya not use Golang to generate the client dll/so ? HOT 1
- unit test fail
- `TestAgentHandle` fails randomly
- There is a panic that could interrupt graceful shutdown HOT 1
- How to implement the authentication policy HOT 2
- config WorkerConfig
- cluster_grpc example error HOT 1
- How to connect web socket?
- How to connect web socket? HOT 1
- Example code error(examples/demo/cluster_grpc/main.go) HOT 1
- Discovered incompatibility issue with dependency libraries (pitaya/v2->etcd ->grpc) when updating dependencies HOT 3
- Can you provide a callback function for the error in request path 404? If there is a business interruption, please handle the path error information uniformly HOT 4
- lua can not use request HOT 13
- Is there any consideration to provide a way for the backend service to listen for session bind and session close events? HOT 1
- Can you provide a way to custom respond to request type message? HOT 2
- How to know when a server in the cluster is shutdown? HOT 1
- Data encoding format for websocket communication between vue client and pitaya server HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pitaya.