Exemple #1
0
func writeLoop(client *client.Client) {
	shouldStop := false
	for !shouldStop {
		func() {
			defer guble.PanicLogger()
			reader := bufio.NewReader(os.Stdin)
			text, _ := reader.ReadString('\n')
			if strings.TrimSpace(text) == "" {
				return
			}

			if strings.TrimSpace(text) == "?" || strings.TrimSpace(text) == "help" {
				printHelp()
				return
			}

			if strings.HasPrefix(text, ">") {
				fmt.Print("header: ")
				header, _ := reader.ReadString('\n')
				text += header
				fmt.Print("body: ")
				body, _ := reader.ReadString('\n')
				text += strings.TrimSpace(body)
			}

			if args.Verbose {
				log.Printf("Sending: %v\n", text)
			}
			if err := client.WriteRawMessage([]byte(text)); err != nil {
				shouldStop = true
				guble.Err(err.Error())
			}
		}()
	}
}
Exemple #2
0
func readLoop(client client.Client) {
	for {
		select {
		case incomingMessage := <-client.Messages():
			if *verbose {
				fmt.Println(string(incomingMessage.Bytes()))
			} else {
				fmt.Printf("%v: %v\n", incomingMessage.UserID, incomingMessage.BodyAsString())
			}
		case e := <-client.Errors():
			fmt.Println("ERROR: " + string(e.Bytes()))
		case status := <-client.StatusMessages():
			fmt.Println(string(status.Bytes()))
			fmt.Println()
		}
	}
}
Exemple #3
0
func readLoop(client *client.Client) {
	for {
		select {
		case incomingMessage := <-client.Messages():
			if args.Verbose {
				fmt.Println(string(incomingMessage.Bytes()))
			} else {
				fmt.Printf("%v: %v\n", incomingMessage.PublisherUserId, incomingMessage.BodyAsString())
			}
		case error := <-client.Errors():
			fmt.Println("ERROR: " + string(error.Bytes()))
		case status := <-client.StatusMessages():
			fmt.Println(string(status.Bytes()))
			fmt.Println()
		}
	}
}
Exemple #4
0
func expectStatusMessage(t *testing.T, client *client.Client, name string, arg string) string {
	select {
	case notify := <-client.StatusMessages():
		assert.Equal(t, name, notify.Name)
		assert.Equal(t, arg, notify.Arg)
		return notify.Json
	case <-time.After(time.Second * 1):
		t.Logf("no notification of type %s after 1 second", name)
		t.Fail()
		return ""
	}
}
Exemple #5
0
func writeLoop(client client.Client) {
	shouldStop := false
	for !shouldStop {
		func() {
			defer protocol.PanicLogger()
			reader := bufio.NewReader(os.Stdin)
			text, err := reader.ReadString('\n')
			if err != nil {
				return
			}
			if strings.TrimSpace(text) == "" {
				return
			}

			if strings.TrimSpace(text) == "?" || strings.TrimSpace(text) == "help" {
				printHelp()
				return
			}

			if strings.HasPrefix(text, ">") {
				fmt.Print("header: ")
				header, err := reader.ReadString('\n')
				if err != nil {
					return
				}
				text += header
				fmt.Print("body: ")
				body, err := reader.ReadString('\n')
				if err != nil {
					return
				}
				text += strings.TrimSpace(body)
			}

			if *verbose {
				log.Printf("Sending: %v\n", text)
			}
			if err := client.WriteRawMessage([]byte(text)); err != nil {
				shouldStop = true
				logger.WithError(err).Error("Error on Writing  message")
			}
		}()
	}
}
func sendMessageSample(c client.Client) error {
	return c.Send("topic", "personalized offer", "{id:id}")
}
func sendBroadcastSample(c client.Client) error {
	return c.Send("/gcm/broadcast", "general offer", "{id:id}")
}
func sendMessageSample(c client.Client) error {
	return c.Send(testTopic, "test-body", "{id:id}")
}