Git Product home page Git Product logo

Comments (1)

Kroev avatar Kroev commented on May 10, 2024 2

Yeah i had to fiddle a bit too but joining a MUC is simple, once you got the hang of it. Looking into XMPP documentation also helps, see XEP0045.

I did it in the postconnect handler of the streammanger here but you should be able to do it whenever you want, as long as the client is connected

func postConnect(s xmpp.Sender) {
	client, ok := s.(*xmpp.Client)
	if !ok {
		fmt.Println("post connect sender not a client, cannot proceed")
		//error handling 
	}
       
        //I used uuids to make sure the id is unique
	uuid, _ := uuid.NewV4()
	id := uuid.String()

	//prepare presence for joining the MUC
	presence := stanza.NewPresence(stanza.Attrs{
		To:   "<mucroom>@<xmppdomain_supporting_muc>/<muc_nickname>",//fill the fields accordingly
		From: client.Session.BindJid,
		Id:   id,
	})
        
        //as stated in the XEP0045 documentation, you have to tell that you are able to speak muc
	presence.Extensions = append(presence.Extensions, stanza.MucPresence{})

        //send the stuff and actually join the MUC
	err := client.Send(presence)
	if err != nil {
		//err handling
	}
}

from go-xmpp.

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.