Code Monkey home page Code Monkey logo

Comments (5)

lazycatNewton avatar lazycatNewton commented on June 10, 2024

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.

felipejfc avatar felipejfc commented on June 10, 2024

what is the use case you're trying to cover?

from pitaya.

lazycatNewton avatar lazycatNewton commented on June 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.