Пример #1
0
func grantSubscribe(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	ch := q.Get("ch")
	read := q.Get("r")
	write := q.Get("w")
	ttl := q.Get("ttl")
	bRead := false
	if read == "1" {
		bRead = true
	}
	bWrite := false
	if write == "1" {
		bWrite = true
	}
	iTTL := 1440
	if ival, err := strconv.Atoi(ttl); err == nil {
		iTTL = ival
	}

	uuid := q.Get("uuid")
	c := appengine.NewContext(r)
	pubInstance := messaging.New(c, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)
	go pubInstance.GrantSubscribe(c, w, r, ch, bRead, bWrite, iTTL, successChannel, errorChannel)
	handleResult(c, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Revoke Subscribe")
}
Пример #2
0
Файл: main.go Проект: pubnub/go
func hereNow(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	channel := q.Get("ch")
	uuid := q.Get("uuid")
	hereNowShowUUID := q.Get("showUUID")
	hereNowIncludeUserState := q.Get("includeUserState")

	disableUUID := false
	includeUserState := false
	if hereNowShowUUID == "1" {
		disableUUID = true
	}
	if hereNowIncludeUserState == "1" {
		includeUserState = true
	}

	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)

	//c := context.NewContext(r)
	c := createContext(r)
	pubInstance := messaging.New(c, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	go pubInstance.HereNow(c, w, r, channel, disableUUID, includeUserState, successChannel, errorChannel)
	handleResult(c, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "HereNow")
}
Пример #3
0
func revokeSubscribe(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	ch := q.Get("ch")
	uuid := q.Get("uuid")
	c := appengine.NewContext(r)
	pubInstance := messaging.New(c, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)
	go pubInstance.GrantSubscribe(c, w, r, ch, false, false, 0, successChannel, errorChannel)
	handleResult(c, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Revoke Subscribe")
}
Пример #4
0
Файл: main.go Проект: pubnub/go
func auditPresence(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	ch := q.Get("ch")
	uuid := q.Get("uuid")
	//c := context.NewContext(r)
	c := createContext(r)
	pubInstance := messaging.New(c, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)
	go pubInstance.AuditPresence(c, w, r, ch, "", successChannel, errorChannel)
	handleResult(c, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Audit Presence")
}
Пример #5
0
func whereNow(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	whereNowUUID := q.Get("whereNowUUID")
	uuid := q.Get("uuid")

	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)

	c := appengine.NewContext(r)
	pubInstance := messaging.New(c, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	go pubInstance.WhereNow(c, w, r, whereNowUUID, successChannel, errorChannel)
	handleResult(c, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "WhereNow")
}
Пример #6
0
func deleteUserState(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	ch := q.Get("ch")
	key := q.Get("k")
	uuid := q.Get("uuid")
	c := appengine.NewContext(r)
	pubInstance := messaging.New(c, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)

	go pubInstance.SetUserStateKeyVal(c, w, r, ch, key, "", successChannel, errorChannel)
	handleResult(c, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Del User State")
}
Пример #7
0
Файл: main.go Проект: pubnub/go
func detailedHistory(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	ch := q.Get("ch")
	uuid := q.Get("uuid")
	start := q.Get("start")
	var iStart int64
	if strings.TrimSpace(start) != "" {
		bi := big.NewInt(0)
		if _, ok := bi.SetString(start, 10); !ok {
			iStart = 0
		} else {
			iStart = bi.Int64()
		}
	}

	end := q.Get("end")
	var iEnd int64
	if strings.TrimSpace(end) != "" {
		bi := big.NewInt(0)
		if _, ok := bi.SetString(end, 10); !ok {
			iEnd = 0
		} else {
			iEnd = bi.Int64()
		}
	}

	limit := q.Get("limit")
	reverse := q.Get("reverse")

	iLimit := 100
	if ival, err := strconv.Atoi(limit); err == nil {
		iLimit = ival
	}

	bReverse := false
	if reverse == "1" {
		bReverse = true
	}

	//	ctx := context.NewContext(r)
	ctx := createContext(r)

	pubInstance := messaging.New(ctx, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)

	go pubInstance.History(ctx, w, r, ch, iLimit, iStart, iEnd, bReverse, successChannel, errorChannel)
	handleResult(ctx, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Detailed History")
}
Пример #8
0
Файл: main.go Проект: pubnub/go
func publish(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	message := q.Get("m")
	uuid := q.Get("uuid")
	ch := q.Get("ch")
	fire := q.Get("fire")
	//meta, _ := url.QueryUnescape(q.Get("meta"))
	metaKey := q.Get("metakey")
	metaVal := q.Get("metaval")
	storeInHistory := q.Get("storeInHistory")
	storeInHistoryBool := false
	if storeInHistory == "1" {
		storeInHistoryBool = true
	}

	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)
	meta := make(map[string]string)
	if strings.TrimSpace(metaKey) != "" && strings.TrimSpace(metaVal) != "" {
		meta[metaKey] = metaVal
	} else {
		meta = nil
	}

	//c := context.NewContext(r)
	c := createContext(r)

	/*message1 := make(map[string]string)
	message1["author"] = "user-a"
	message1["status"] = "I am reading about Advanced Channel Groups!"
	message1["timestamp"] = time.Now().String()*/

	pubInstance := messaging.New(c, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	//go pubInstance.Publish(c, w, r, "my_channel", message1, successChannel, errorChannel)

	if fire == "1" {
		go pubInstance.Fire(c, w, r, ch, message, false, successChannel, errorChannel)
	} else if meta != nil {
		log.Infof(c, fmt.Sprintf("Meta: %s", meta))
		go pubInstance.PublishExtendedWithMeta(c, w, r, ch, message, meta, storeInHistoryBool, false, successChannel, errorChannel)
	} else if storeInHistoryBool {
		go pubInstance.PublishExtended(c, w, r, ch, message, storeInHistoryBool, false, successChannel, errorChannel)
	} else {
		go pubInstance.Publish(c, w, r, ch, message, successChannel, errorChannel)
	}

	handleResult(c, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Publish")
}
Пример #9
0
Файл: main.go Проект: pubnub/go
func setUserState(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	ch := q.Get("ch")
	k := q.Get("k")
	v := q.Get("v")
	uuid := q.Get("uuid")
	//c := context.NewContext(r)
	c := createContext(r)
	pubInstance := messaging.New(c, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)

	//setUserState

	go pubInstance.SetUserStateKeyVal(c, w, r, ch, k, v, successChannel, errorChannel)
	handleResult(c, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Set User State")
}
Пример #10
0
// PublishMessages calls the publish method of messaging package numberOfMessages times
// and appends the count with the message to distinguish from the others.
//
// Parameters:
// pubnubInstance: a reference of *messaging.Pubnub,
// channel: the pubnub channel to publish the messages,
// t: a reference to *testing.T,
// startMessagesFrom: the message identifer,
// numberOfMessages: number of messages to send,
// message: message to send.
//
// returns a bool if the publish of all messages is successful.
func PublishMessages(context context.Context, w http.ResponseWriter, r *http.Request, pubnubInstance *messaging.Pubnub, channel string, t *testing.T, startMessagesFrom int, numberOfMessages int, message string) bool {
	messagesReceived := 0
	messageToSend := ""
	tOut := messaging.GetNonSubscribeTimeout()
	messaging.SetNonSubscribeTimeout(30)
	for i := startMessagesFrom; i < startMessagesFrom+numberOfMessages; i++ {
		messageToSend = message + strconv.Itoa(i)

		returnPublishChannel := make(chan []byte)
		errorChannel := make(chan []byte)
		go pubnubInstance.Publish(context, w, r, channel, messageToSend, returnPublishChannel, errorChannel)

		messagesReceived++
		//time.Sleep(500 * time.Millisecond)
		time.Sleep(1500 * time.Millisecond)
	}
	if messagesReceived == numberOfMessages {
		return true
	}
	messaging.SetNonSubscribeTimeout(tOut)
	return false
}
Пример #11
0
Файл: main.go Проект: pubnub/go
func getUserState(w http.ResponseWriter, r *http.Request) {
	/*successChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	c := createContext(r)
	pubInstance := messaging.New(c, "", w, r, publishKey, subscribeKey, secretKey, "", false)

	go pubInstance.ChannelGroupAddChannel(c, w, r, "cg-user-a-friends", "ch-user-a-present", successChannel, errorChannel)

	select {
	case response := <-successChannel:
		log.Infof(c, "success:", string(response))
	case err := <-errorChannel:
		log.Infof(c, "success:", string(err))
	}

	go pubInstance.ChannelGroupAddChannel(c, w, r, "cg-user-a-status-feed", "ch-user-a-present", successChannel, errorChannel)

	select {
	case response := <-successChannel:
		log.Infof(c, "1success:", string(response))
	case err := <-errorChannel:
		log.Infof(c, "1success:", string(err))
	}*/
	q := r.URL.Query()
	ch := q.Get("ch")
	uuid := q.Get("uuid")

	//c := context.NewContext(r)
	c := createContext(r)
	pubInstance := messaging.New(c, uuid, w, r, publishKey, subscribeKey, secretKey, "", false)
	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)

	go pubInstance.GetUserState(c, w, r, ch, successChannel, errorChannel)
	handleResult(c, w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Get User State")
}