• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang messaging.Pubnub类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pubnub/go/messaging.Pubnub的典型用法代码示例。如果您正苦于以下问题:Golang Pubnub类的具体用法?Golang Pubnub怎么用?Golang Pubnub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Pubnub类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: ParseSubscribeResponseAndCallUnsubscribe

// ParseSubscribeResponseAndCallUnsubscribe will parse the response on the go channel.
// It will check the subscribe connection status and when connected
// it will initiate the unsubscribe request.
func ParseSubscribeResponseAndCallUnsubscribe(pubnubInstance *messaging.Pubnub, returnChannel chan []byte, channel string, message string, responseChannel chan string) {
	for {
		value, ok := <-returnChannel
		if !ok {
			break
		}
		if string(value) != "[]" {
			response := fmt.Sprintf("%s", value)
			message = "'" + channel + "' " + message
			//messageAbort := "'" + channel + "' aborted"
			//fmt.Printf("response:",response);
			//fmt.Printf("message:", message);

			if strings.Contains(response, message) {
				returnUnsubscribeChannel := make(chan []byte)
				errorChannel := make(chan []byte)

				go pubnubInstance.Unsubscribe(channel, returnUnsubscribeChannel, errorChannel)
				go ParseUnsubscribeResponse(returnUnsubscribeChannel, channel, "unsubscribed", responseChannel)
				go ParseResponseDummy(errorChannel)

				break
			} /*else if (strings.Contains(response, messageAbort)){
			      responseChannel <- "Test unsubscribed: failed."
			      break
			  } else {
			      responseChannel <- "Test unsubscribed: failed."
			      break
			  }*/
		}
	}
}
开发者ID:GleasonK,项目名称:go,代码行数:35,代码来源:pubnubUnsubscribe_test.go


示例2: ParseSetUserStateResponseJSON

func ParseSetUserStateResponseJSON(pubnubInstance *messaging.Pubnub, returnChannel chan []byte, channel string, key1 string, val1 string, key2 string, val2 string, jsonString string, testName string, responseChannel chan string) {
	for {
		value, ok := <-returnChannel
		if !ok {
			break
		}
		if string(value) != "[]" {
			response := fmt.Sprintf("%s", value)
			//fmt.Println("Test JSON'" + testName + "':" +response)
			jsonString = fmt.Sprintf("{\"%s\": \"%s\", \"%s\": \"%s\"}", key2, val2, key1, val1)
			if strings.Contains(response, jsonString) {
				errorChannel := make(chan []byte)
				returnChannel2 := make(chan []byte)
				time.Sleep(3 * time.Second)

				go pubnubInstance.SetUserStateKeyVal(channel, key2, "", returnChannel2, errorChannel)
				go ParseUserStateResponse(returnChannel2, channel, key1, val1, testName, responseChannel)
				go ParseErrorResponse(errorChannel, responseChannel)

				break
			} else {
				responseChannel <- "Test '" + testName + "': failed."
				break
			}
		}
	}
}
开发者ID:GleasonK,项目名称:go,代码行数:27,代码来源:pubnubPresence_test.go


示例3: PublishSimpleMessage

// PublishSimpleMessage publises a message on a pubnub channel and
// calls the parse method to validate the message subscription.
func PublishSimpleMessage(pubnubInstance *messaging.Pubnub, t *testing.T, channel string, testName string, cipherKey string, responseChannel chan string) {
	message := "Test message"

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

	go pubnubInstance.Publish(channel, message, returnChannel, errorChannel)
	go ParseSubscribeResponse(pubnubInstance, returnChannel, t, channel, "", testName, cipherKey, responseChannel)
	go ParseErrorResponse(errorChannel, responseChannel)
}
开发者ID:GleasonK,项目名称:go,代码行数:12,代码来源:pubnubSubscribe_test.go


示例4: populateGroup

func populateGroup(pubnub *messaging.Pubnub, group, channels string) {
	successChannel := make(chan []byte)
	errorChannel := make(chan []byte)

	pubnub.ChannelGroupAddChannel(group, channels, successChannel, errorChannel)

	select {
	case <-successChannel:
	case <-errorChannel:
	}
}
开发者ID:anovikov1984,项目名称:go,代码行数:11,代码来源:subscribeExample.go


示例5: CommonUserStateJSON

func CommonUserStateJSON(pubnubInstance *messaging.Pubnub, t *testing.T, channel string, key1 string, val1 string, key2 string, val2 string, testName string) {
	returnChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	waitChannel := make(chan string)
	responseChannel := make(chan string)

	jsonString := fmt.Sprintf("{\"%s\": \"%s\",\"%s\": \"%s\"}", key1, val1, key2, val2)
	time.Sleep(2 * time.Second)
	go pubnubInstance.SetUserStateJSON(channel, jsonString, returnChannel, errorChannel)
	go ParseSetUserStateResponseJSON(pubnubInstance, returnChannel, channel, key1, val1, key2, val2, jsonString, testName, responseChannel)
	go ParseErrorResponse(errorChannel, responseChannel)
	go WaitForCompletion(responseChannel, waitChannel)
	ParseWaitResponse(waitChannel, t, testName)
}
开发者ID:GleasonK,项目名称:go,代码行数:14,代码来源:pubnubPresence_test.go


示例6: populateChannelGroup

func populateChannelGroup(pubnub *messaging.Pubnub, group, channels string) {

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

	pubnub.ChannelGroupAddChannel(group, channels, successChannel, errorChannel)

	select {
	case <-successChannel:
		// fmt.Println("Group created")
	case <-errorChannel:
		fmt.Println("Channel group creation error")
	case <-timeout():
		fmt.Println("Channel group creation timeout")
	}
}
开发者ID:anovikov1984,项目名称:go,代码行数:16,代码来源:pubnubGroupSubscribe_test.go


示例7: createChannelGroups

func createChannelGroups(pubnub *messaging.Pubnub, groups []string) {
	successChannel := make(chan []byte, 1)
	errorChannel := make(chan []byte, 1)

	for _, group := range groups {
		// fmt.Println("Creating group", group)

		pubnub.ChannelGroupAddChannel(group, "adsf", successChannel, errorChannel)

		select {
		case <-successChannel:
			// fmt.Println("Group created")
		case <-errorChannel:
			fmt.Println("Channel group creation error")
		case <-timeout():
			fmt.Println("Channel group creation timeout")
		}
	}
}
开发者ID:anovikov1984,项目名称:go,代码行数:19,代码来源:pubnubGroupSubscribe_test.go


示例8: removeChannelGroups

func removeChannelGroups(pubnub *messaging.Pubnub, groups []string) {
	successChannel := make(chan []byte, 1)
	errorChannel := make(chan []byte, 1)

	for _, group := range groups {
		// fmt.Println("Removing group", group)

		pubnub.ChannelGroupRemoveGroup(group, successChannel, errorChannel)

		select {
		case <-successChannel:
			// fmt.Println("Group removed")
		case <-errorChannel:
			fmt.Println("Channel group removal error")
		case <-timeout():
			fmt.Println("Channel group removal timeout")
		}
	}
}
开发者ID:anovikov1984,项目名称:go,代码行数:19,代码来源:pubnubGroupSubscribe_test.go


示例9: PublishMessages

// 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(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(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
}
开发者ID:GleasonK,项目名称:go,代码行数:33,代码来源:pubnubDetailedHistory_test.go


示例10: ParseSetUserStateResponse

func ParseSetUserStateResponse(pubnubInstance *messaging.Pubnub, returnChannel chan []byte, channel string, key string, val string, testName string, responseChannel chan string) {
	for {
		value, ok := <-returnChannel
		if !ok {
			break
		}
		if string(value) != "[]" {
			response := fmt.Sprintf("%s", value)
			//fmt.Println("Test '" + testName + "':" +response)
			message := fmt.Sprintf("{\"%s\": \"%s\"}", key, val)
			//fmt.Println("%s", message)
			if strings.Contains(response, message) {
				errorChannel := make(chan []byte)
				returnChannel2 := make(chan []byte)
				time.Sleep(3 * time.Second)

				if testName == "SetGetUserState" {
					go pubnubInstance.GetUserState(channel, returnChannel2, errorChannel)
				} else if testName == "SetGetUserStateHereNow" {
					go pubnubInstance.HereNow(channel, true, true, returnChannel2, errorChannel)
				} else if testName == "SetGetUserStateGlobalHereNow" {
					go pubnubInstance.GlobalHereNow(true, true, returnChannel2, errorChannel)
				}
				go ParseUserStateResponse(returnChannel2, channel, key, val, testName, responseChannel)
				go ParseErrorResponse(errorChannel, responseChannel)

				break
			} else {
				responseChannel <- "Test '" + testName + "': failed."
				break
			}
		}
	}
}
开发者ID:GleasonK,项目名称:go,代码行数:34,代码来源:pubnubPresence_test.go


示例11: UpdateValuesAndPublish

func (stock *Stock) UpdateValuesAndPublish(pubnub *messaging.Pubnub,
	cycle chan bool) {
	if stock.CurrentPrice == 0 {
		stock.CurrentPrice = stock.InitialPrice
	}

	rand.Seed(int64(time.Now().Nanosecond()))

	change := float64(rand.Intn(stock.Volatility)-stock.Volatility/2) / 100
	stock.CurrentPrice = stock.CurrentPrice + float64(change)
	delta := stock.CurrentPrice - stock.InitialPrice
	percentage := Roundn((1-stock.InitialPrice/stock.CurrentPrice)*100, 2)
	vol := Randn(stock.Volatility, 1000) * 10

	streamMessage := StreamMessage{
		Time:       time.Now().Format(TIME_FORMAT),
		Price:      fmt.Sprintf("%.2f", stock.CurrentPrice),
		Delta:      fmt.Sprintf("%.2f", delta),
		Percentage: fmt.Sprintf("%.2f", percentage),
		Vol:        vol}

	if math.Abs(percentage) > float64(stock.MaxDelta)/100 {
		stock.CurrentPrice = stock.InitialPrice
	}

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

	go pubnub.Publish(stock.Name, streamMessage, successChannel, errorChannel)
	go handleResponse(successChannel, errorChannel,
		messaging.GetNonSubscribeTimeout(), done)

	sleep := Randn(stock.MinTrade, stock.MaxTrade)
	time.Sleep(time.Duration(sleep) * time.Microsecond)

	cycle <- <-done
}
开发者ID:anovikov1984,项目名称:real-time-stocks-go,代码行数:38,代码来源:stocks.go


示例12: ParseSubcribeResponseForUserState

func ParseSubcribeResponseForUserState(pubnubInstance *messaging.Pubnub, t *testing.T, returnChannel chan []byte, channel string, key string, val string, testName string, responseChannel chan string) {
	for {
		value, ok := <-returnChannel
		if !ok {
			break
		}
		if string(value) != "[]" {
			response := fmt.Sprintf("%s", value)
			message := "'" + channel + "' connected"
			messageReconn := "'" + channel + "' reconnected"
			if (strings.Contains(response, message)) || (strings.Contains(response, messageReconn)) {
				time.Sleep(1 * time.Second)
				errorChannel := make(chan []byte)
				returnChannel2 := make(chan []byte)

				go pubnubInstance.SetUserStateKeyVal(channel, key, val, returnChannel2, errorChannel)
				go ParseSetUserStateResponse(pubnubInstance, returnChannel2, channel, key, val, testName, responseChannel)
				go ParseErrorResponse(errorChannel, responseChannel)
			}
			break
		}
	}
}
开发者ID:GleasonK,项目名称:go,代码行数:23,代码来源:pubnubPresence_test.go


示例13: PublishMessages

// 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(pubnubInstance *messaging.Pubnub, channel string,
	t *testing.T, startMessagesFrom int, numberOfMessages int,
	message string, sleep func(int)) bool {

	assert := assert.New(t)
	messagesReceived := 0
	messageToSend := ""
	tOut := messaging.GetNonSubscribeTimeout()
	messaging.SetNonSubscribeTimeout(30)

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

	for i := startMessagesFrom; i < startMessagesFrom+numberOfMessages; i++ {
		messageToSend = message + strconv.Itoa(i)

		go pubnubInstance.Publish(channel, messageToSend, successChannel, errorChannel)
		select {
		case <-successChannel:
			messagesReceived++
		case err := <-errorChannel:
			assert.Fail("Failed to get channel list", string(err))
		case <-messaging.Timeout():
			assert.Fail("WhereNow timeout")
		}
	}

	sleep(3)
	if messagesReceived == numberOfMessages {
		return true
	}

	messaging.SetNonSubscribeTimeout(tOut)

	return false
}
开发者ID:pubnub,项目名称:go,代码行数:48,代码来源:pubnubHistory_test.go


示例14: CommonUserState

func CommonUserState(pubnubInstance *messaging.Pubnub, t *testing.T, channel string, key string, val string, testName string) {
	returnSubscribeChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	waitChannel := make(chan string)
	//returnChannel := make(chan []byte)
	responseChannel := make(chan string)

	go pubnubInstance.Subscribe(channel, "", returnSubscribeChannel, false, errorChannel)
	go ParseSubcribeResponseForUserState(pubnubInstance, t, returnSubscribeChannel, channel, key, val, testName, responseChannel)
	go ParseResponseDummy(errorChannel)
	//go ParseErrorResponse(errorChannel, responseChannel)
	go WaitForCompletion(responseChannel, waitChannel)
	ParseWaitResponse(waitChannel, t, testName)
	go pubnubInstance.Unsubscribe(channel, returnSubscribeChannel, errorChannel)
	pubnubInstance.CloseExistingConnection()
	time.Sleep(2 * time.Second)
}
开发者ID:GleasonK,项目名称:go,代码行数:17,代码来源:pubnubPresence_test.go


示例15: ParseSubscribeMultiplexedResponse

// ParseSubscribeMultiplexedResponse publishes 2 messages on 2 different channels and
// when both the channels are connected
// it reads the responseChannel for the 2 messages. If we get the same 2 messages as response
// the test is passed.
//
// parameters:
// pubnubInstance: an instace of *messaging.Pubnub,
// returnSubscribeChannel: the channel to read the subscribe response on.
// message1: first message to publish.
// message2: second message to publish.
// pubnubChannel1: pubnub Channel 1 to publish the first message.
// pubnubChannel2: pubnub Channel 2 to publish the second message.
// testName: test name.
// responseChannel: the channelto send a response back.
func ParseSubscribeMultiplexedResponse(pubnubInstance *messaging.Pubnub, returnSubscribeChannel chan []byte, message1 string, message2 string, pubnubChannel1 string, pubnubChannel2 string, testName string, responseChannel chan string) {
	messageCount := 0
	channelCount := 0
	for {
		value, ok := <-returnSubscribeChannel
		if !ok {
			break
		}
		if string(value) != "[]" {
			response := fmt.Sprintf("%s", value)
			message := "' connected"
			messageT1 := "'" + pubnubChannel1 + "' connected"
			messageT2 := "'" + pubnubChannel2 + "' connected"
			if strings.Contains(response, message) {
				if strings.Contains(response, messageT1) {
					channelCount++
				}

				if strings.Contains(response, messageT2) {
					channelCount++
				}
				if channelCount >= 2 {
					returnPublishChannel := make(chan []byte)
					errorChannelPub := make(chan []byte)

					go pubnubInstance.Publish(pubnubChannel1, message1, returnPublishChannel, errorChannelPub)
					go ParseResponseDummy(returnPublishChannel)
					go ParseResponseDummy(errorChannelPub)

					returnPublishChannel2 := make(chan []byte)
					errorChannelPub2 := make(chan []byte)

					go pubnubInstance.Publish(pubnubChannel2, message2, returnPublishChannel2, errorChannelPub2)
					go ParseResponseDummy(returnPublishChannel2)
					go ParseResponseDummy(errorChannelPub2)
				}
			} else {
				var s []interface{}
				err := json.Unmarshal(value, &s)
				if err == nil {
					if len(s) > 2 {
						if message, ok := s[0].([]interface{}); ok {
							if messageT, ok2 := message[0].(string); ok2 {
								if (len(message) > 0) && (messageT == message1) && (s[2].(string) == pubnubChannel1) {
									messageCount++
								}
								if (len(message) > 0) && (messageT == message2) && (s[2].(string) == pubnubChannel2) {
									messageCount++
								}
							}
						}
					}
				}

				if messageCount >= 2 {
					responseChannel <- "Test '" + testName + "': passed."
					break
				}
			}
		}
	}
}
开发者ID:GleasonK,项目名称:go,代码行数:76,代码来源:pubnubSubscribe_test.go


示例16: ParseSubscribeResponse

// ParseSubscribeResponse reads the response from the go channel and unmarshal's it.
// It is used by multiple test cases and acts according to the testcase names.
// The idea is to parse each message in the response based on the type of message
// and test against the sent message. If both match the test case is successful.
// _publishSuccessMessage is defined in the common.go file.
func ParseSubscribeResponse(pubnubInstance *messaging.Pubnub, returnChannel chan []byte, t *testing.T, channel string, message string, testName string, cipherKey string, responseChannel chan string) {
	for {
		value, ok := <-returnChannel
		if !ok {
			break
		}
		if string(value) != "[]" {
			response := fmt.Sprintf("%s", value)
			//fmt.Println("Response1:", response)
			if (testName == "SubscriptionConnectedForComplex") || (testName == "SubscriptionConnectedForComplexWithCipher") {
				message = "'" + channel + "' connected"
				if strings.Contains(response, message) {
					PublishComplexMessage(pubnubInstance, t, channel, publishSuccessMessage, cipherKey, responseChannel)
				} else {
					//fmt.Println("resp:", response)
					if ParseSubscribeData(t, value, testName, cipherKey, responseChannel) {
						responseChannel <- "Test '" + testName + "': passed."
					} else {
						responseChannel <- "Test '" + testName + "': failed."
					}
					break
				}
			} else if (testName == "SubscriptionConnectedForSimple") || (testName == "SubscriptionConnectedForSimpleWithCipher") {
				message = "'" + channel + "' connected"
				if strings.Contains(response, message) {
					PublishSimpleMessage(pubnubInstance, t, channel, publishSuccessMessage, cipherKey, responseChannel)
				} else {
					if ParseSubscribeData(t, value, testName, cipherKey, responseChannel) {
						responseChannel <- "Test '" + testName + "': passed."
					} else {
						responseChannel <- "Test '" + testName + "': failed."
					}
					break
				}
			} else if testName == "SubscriptionAlreadySubscribed" {
				message = "'" + channel + "' connected"

				if strings.Contains(response, message) {
					returnSubscribeChannel2 := make(chan []byte)
					errorChannel2 := make(chan []byte)

					go pubnubInstance.Subscribe(channel, "", returnSubscribeChannel2, false, errorChannel2)
					go ParseSubscribeResponse(pubnubInstance, errorChannel2, t, channel, "already subscribed", "SubscriptionAlreadySubscribedResponse", "", responseChannel)
					go ParseResponseDummy(returnSubscribeChannel2)
				}
				break
			} else if testName == "SubscriptionAlreadySubscribedResponse" {
				message = "'" + channel + "' already subscribed"
				if strings.Contains(response, message) {
					responseChannel <- "Test '" + testName + "': passed."
				} else {
					responseChannel <- "Test '" + testName + "': failed."
					//t.Error("Test '" + testName + "': failed.");
				}
				break
			} else if testName == "SubscriptionConnectStatus" {
				message = "'" + channel + "' connected"
				if strings.Contains(response, message) {
					responseChannel <- "Test '" + testName + "': passed."
				} else {
					responseChannel <- "Test '" + testName + "': failed."
					//t.Error("Test '" + testName + "': failed.");
				}
				break
			}
		}
	}
}
开发者ID:GleasonK,项目名称:go,代码行数:73,代码来源:pubnubSubscribe_test.go


示例17: ParseSubscribeResponseForPresence

// ParseSubscribeResponseForPresence will look for the connection status in the response
// received on the go channel.
func ParseSubscribeResponseForPresence(pubnubInstance *messaging.Pubnub, customUuid string, returnChannel chan []byte, channel string, testName string, responseChannel chan string) {
	for {
		value, ok := <-returnChannel
		if !ok {
			break
		}
		//response := fmt.Sprintf("%s", value)
		//fmt.Println(response);

		if string(value) != "[]" {
			if (testName == "CustomUuid") || (testName == "HereNow") || (testName == "HereNowWithCipher") {
				response := fmt.Sprintf("%s", value)
				message := "'" + channel + "' connected"
				messageReconn := "'" + channel + "' reconnected"
				if (strings.Contains(response, message)) || (strings.Contains(response, messageReconn)) {
					errorChannel := make(chan []byte)
					returnChannel := make(chan []byte)
					time.Sleep(3 * time.Second)
					go pubnubInstance.HereNow(channel, true, true, returnChannel, errorChannel)
					go ParseHereNowResponse(returnChannel, channel, customUuid, testName, responseChannel)
					go ParseErrorResponse(errorChannel, responseChannel)
					break
				}
			} else if testName == "WhereNow" {
				response := fmt.Sprintf("%s", value)
				message := "'" + channel + "' connected"
				messageReconn := "'" + channel + "' reconnected"
				if (strings.Contains(response, message)) || (strings.Contains(response, messageReconn)) {
					errorChannel := make(chan []byte)
					returnChannel := make(chan []byte)
					time.Sleep(3 * time.Second)
					go pubnubInstance.WhereNow(customUuid, returnChannel, errorChannel)
					go ParseHereNowResponse(returnChannel, channel, customUuid, testName, responseChannel)
					go ParseErrorResponse(errorChannel, responseChannel)
					break
				}
			} else if testName == "GlobalHereNow" {
				response := fmt.Sprintf("%s", value)
				message := "'" + channel + "' connected"
				messageReconn := "'" + channel + "' reconnected"
				if (strings.Contains(response, message)) || (strings.Contains(response, messageReconn)) {
					errorChannel := make(chan []byte)
					returnChannel := make(chan []byte)
					time.Sleep(3 * time.Second)
					go pubnubInstance.GlobalHereNow(true, false, returnChannel, errorChannel)
					go ParseHereNowResponse(returnChannel, channel, customUuid, testName, responseChannel)
					go ParseErrorResponse(errorChannel, responseChannel)
					break
				}
			} else {
				response := fmt.Sprintf("%s", value)
				message := "'" + channel + "' connected"
				messageReconn := "'" + channel + "' reconnected"
				//fmt.Println("Test3 '" + testName + "':" +response)
				if (strings.Contains(response, message)) || (strings.Contains(response, messageReconn)) {

					errorChannel2 := make(chan []byte)
					returnSubscribeChannel := make(chan []byte)
					time.Sleep(1 * time.Second)
					go pubnubInstance.Subscribe(channel, "", returnSubscribeChannel, false, errorChannel2)
					go ParseResponseDummy(returnSubscribeChannel)
					go ParseResponseDummy(errorChannel2)
				} else {
					if testName == "Presence" {
						data, _, returnedChannel, err2 := messaging.ParseJSON(value, "")

						var occupants []struct {
							Action    string
							Uuid      string
							Timestamp float64
							Occupancy int
						}

						if err2 != nil {
							responseChannel <- "Test '" + testName + "': failed. Message: 1 :" + err2.Error()
							break
						}
						//fmt.Println("Test3 '" + testName + "':" +data)
						err := json.Unmarshal([]byte(data), &occupants)
						if err != nil {
							//fmt.Println("err '" + testName + "':",err)
							responseChannel <- "Test '" + testName + "': failed. Message: 2 :" + err.Error()
							break
						} else {
							channelSubRepsonseReceived := false
							for i := 0; i < len(occupants); i++ {
								if (occupants[i].Action == "join") && occupants[i].Uuid == customUuid {
									channelSubRepsonseReceived = true
									break
								}
							}
							if !channelSubRepsonseReceived {
								responseChannel <- "Test '" + testName + "': failed. Message: err3"
								break
							}
							if channel == returnedChannel {
								responseChannel <- "Test '" + testName + "': passed."
								break
//.........这里部分代码省略.........
开发者ID:GleasonK,项目名称:go,代码行数:101,代码来源:pubnubPresence_test.go


示例18: GetServerTime

// GetServerTime calls the GetTime method of the messaging, parses the response to get the
// value and return it.
func GetServerTime(pubnubInstance *messaging.Pubnub, t *testing.T, testName string) int64 {
	returnTimeChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	go pubnubInstance.GetTime(returnTimeChannel, errorChannel)
	return ParseServerTimeResponse(returnTimeChannel, t, testName)
}
开发者ID:GleasonK,项目名称:go,代码行数:8,代码来源:pubnubDetailedHistory_test.go



注:本文中的github.com/pubnub/go/messaging.Pubnub类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang pubnubMessaging.PubnubInit函数代码示例发布时间:2022-05-28
下一篇:
Golang messaging.NewPubnub函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap