Example #1
0
func Connect(sender Sender) error {
	newMsgChan := make(chan interface{}, 20)
	// login := &mx.Login{Name: br.Login, Password: br.Password, Type: "CSTAMxie", Platform: "Mxie", Version: "0.3"}
	login := &mx.Login{Name: sender.GetLogin(), Password: sender.GetPassword()}
	address := &mx.Address{Server: sender.GetAddress(), IsTLS: true, IsInsecureSkipVerify: true}
	newConn := mx.NewConn(address, login)
	errChan := make(chan error)
	go func(errChan chan error) {
		errChan <- newConn.Connect(newMsgChan)
	}(errChan)
	select {
	case err := <-errChan:
		if err == nil {
			if conn := sender.GetConn(); conn != nil {
				conn.Close()
			}
			sender.SetConn(newConn)
			sender.SetEvents()
			// msgChan := sender.GetChan()
			// *msgChan = newMsgChan
			sender.SetChan(newMsgChan)
			llog.Println("Start listening!")
			go sender.Listen()
		}
		return err
	case <-time.After(time.Second * 7):
		return errors.New("Timeout")
	}
}
Example #2
0
func main() {
	msgChan := make(chan interface{}, 20)
	login := &mx.Login{Name: "sergeyk", Password: "******"}
	address := &mx.Address{Server: "maxhome-msk.dyndns.org:7778", IsTLS: true, IsInsecureSkipVerify: true}
	conn := mx.NewConn(address, login)
	// s := mx.NewServerAddressbook(conn, nil, nil)
	if err := conn.Connect(msgChan); err != nil {
		log.Fatal(err)
	}
	conn.Events.Register(map[string]reflect.Type{
		"presence":   reflect.TypeOf(mx.Presence{}),
		"message":    reflect.TypeOf(Message{}),
		"messageAck": reflect.TypeOf(MessageAck{}),
		"ablist":     reflect.TypeOf(AbList{}),
	})

	go Listen(msgChan, conn)

	for i := 1; i < 2; i++ {
		// go func(i int) {
		// 	users := gm.GetGroup("590890911395826551", conn)
		// 	fmt.Println(i, "<<", users)
		// }(i)
		// time.Sleep(time.Second * 2)
		conn.Send(fmt.Sprintf("<MonitorStartAb/>"))
		// conn.Send(fmt.Sprintf("<GetImGroups><userId>%s</userId></GetImGroups>", "14430159621632068"))
		// info, _ := gm.AboutUser("14430159286645788")
		// fmt.Println(">> Info:", info)
	}

	bracelet := RegistrateUser{
		IsUser:   false,
		Login:    "******",
		Password: "******",
		Ext:      "10000",
		Pin:      "1234",
	}

	var id string
	client, _ := rpc.DialHTTP("tcp", "cs03.xyzrd.com:7778")
	if err := client.Call("MXA.Add", bracelet, &id); err != nil {
		log.Fatal(err)
	}

	fmt.Println("JID ->", id)
	time.Sleep(time.Second * 2)
	var ok bool
	if err := client.Call("MXA.Delete", id, &ok); err != nil {
		log.Fatal(err)
	}

	for {
	}
}