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

Golang messaging.NewPubnub函数代码示例

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

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



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

示例1: TestServerTime

// TestServerTime calls the GetTime method of the messaging to test the time
func TestServerTime(t *testing.T) {
	stop, _ := NewVCRNonSubscribe("fixtures/time", []string{})
	defer stop()

	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, "testTime")

	assert := assert.New(t)
	successChannel := make(chan []byte)
	errorChannel := make(chan []byte)

	go pubnubInstance.GetTime(successChannel, errorChannel)
	select {
	case value := <-successChannel:
		response := string(value)
		timestamp, err := strconv.Atoi(strings.Trim(response, "[]\n"))
		if err != nil {
			assert.Fail(err.Error())
		}

		assert.NotZero(timestamp)
	case err := <-errorChannel:
		assert.Fail(string(err))
	case <-timeouts(10):
		assert.Fail("Getting server timestamp timeout")
	}
}
开发者ID:anovikov1984,项目名称:go,代码行数:27,代码来源:pubnubTime_test.go


示例2: TestSubscribeGrantPositive

func TestSubscribeGrantPositive(t *testing.T) {
	pubnubInstance := messaging.NewPubnub(PamPubKey, PamSubKey, PamSecKey, "", false, "")
	channel := "testChannelSubscribeGrantPositive"
	ttl := 1
	message := fmt.Sprintf(`{"status":200,"service":"Access Manager","message":"Success","payload":{"channels":{"%s":{"r":1,"m":0,"w":1}},"subscribe_key":"%s","ttl":%d,"level":"channel"}}`, channel, PamSubKey, ttl)
	message2 := fmt.Sprintf(`{"status":200,"service":"Access Manager","message":"Success","payload":{"channels":{"%s":{"r":0,"m":0,"w":0}},"subscribe_key":"%s","ttl":%d,"level":"channel"}}`, channel, PamSubKey, ttl)

	time.Sleep(time.Duration(5) * time.Second)

	returnPamChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	responseChannel := make(chan string)
	waitChannel := make(chan string)

	go pubnubInstance.GrantSubscribe(channel, true, true, ttl, returnPamChannel, errorChannel)
	go ParsePamResponse(returnPamChannel, pubnubInstance, message, channel, "SubscribeGrantPositiveGrant", responseChannel)
	go ParseErrorResponse(errorChannel, responseChannel)
	go WaitForCompletion(responseChannel, waitChannel)
	ParseWaitResponse(waitChannel, t, "SubscribeGrantPositiveGrant")

	returnPamChannel2 := make(chan []byte)
	errorChannel2 := make(chan []byte)
	responseChannel2 := make(chan string)
	waitChannel2 := make(chan string)

	go pubnubInstance.GrantSubscribe(channel, false, false, -1, returnPamChannel2, errorChannel2)
	go ParsePamResponse(returnPamChannel2, pubnubInstance, message2, channel, "SubscribeGrantPositiveRevoke", responseChannel2)
	go ParseErrorResponse(errorChannel2, responseChannel2)
	go WaitForCompletion(responseChannel2, waitChannel2)
	ParseWaitResponse(waitChannel2, t, "SubscribeGrantPositiveRevoke")

}
开发者ID:GleasonK,项目名称:go,代码行数:32,代码来源:pubnubPam_test.go


示例3: ResumeOnReconnect

// ResumeOnReconnect contains the actual impementation of both TestResumeOnReconnectFalse and TestResumeOnReconnectTrue
// the parameter b determines of resume on reconnect setting is true or false.
//
// The test contains a data race
func ResumeOnReconnect(t *testing.T, b bool) {
	testName := "ResumeOnReconnectFalse"
	if b {
		messaging.SetResumeOnReconnect(true)
		testName = "ResumeOnReconnectTrue"
	} else {
		messaging.SetResumeOnReconnect(false)
	}
	r := GenRandom()
	pubnubChannel := fmt.Sprintf("testChannel_subror_%d", r.Intn(20))

	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, "")
	returnSubscribeChannel := make(chan []byte)
	errorChannelSub := make(chan []byte)
	responseChannelSub := make(chan string)
	waitChannelSub := make(chan string)

	messaging.SetSubscribeTimeout(12)
	go pubnubInstance.Subscribe(pubnubChannel, "", returnSubscribeChannel, false, errorChannelSub)
	go ParseSubscribeForTimetoken(pubnubInstance, pubnubChannel, returnSubscribeChannel, errorChannelSub, testName, responseChannelSub)
	go WaitForCompletion(responseChannelSub, waitChannelSub)
	ParseWaitResponse(waitChannelSub, t, testName)
	messaging.SetSubscribeTimeout(310)
	go pubnubInstance.Unsubscribe(pubnubChannel, returnSubscribeChannel, errorChannelSub)
	pubnubInstance.CloseExistingConnection()
}
开发者ID:GleasonK,项目名称:go,代码行数:30,代码来源:pubnubSubscribe_test.go


示例4: handler

func handler(w http.ResponseWriter, r *http.Request) {
	log.Print("Info: IN handler")
	uuid := ""
	pubInstance := messaging.NewPubnub(publishKey, subscribeKey, secretKey, "", true, uuid)
	if pubInstance == nil {
		log.Print("Error: Couldn't create pubnub instance")
		http.Error(w, "Couldn't create pubnub instance", http.StatusInternalServerError)
		return
	}
	nuuid := pubInstance.GetUUID()
	log.Print("UUID: %s", nuuid)
	tok := "s"

	err1 := mainTemplate.Execute(w, map[string]string{
		"token":        tok,
		"uuid":         nuuid,
		"subscribeKey": subscribeKey,
		"publishKey":   publishKey,
		"secretKey":    secretKey,
		"hostname":     fmt.Sprintf("%s%s", hostname, port),
	})
	if err1 != nil {
		log.Print("Error: mainTemplate: %v", err1)
	}
}
开发者ID:pubnub,项目名称:go,代码行数:25,代码来源:main.go


示例5: SendMultiplexingRequest

// SendMultiplexingRequest is the common method to test TestMultiplexing,
// TestMultiplexingSSL, TestEncryptedMultiplexing, TestEncryptedMultiplexingWithSSL.
//
// It subscribes to 2 channels in the same request and then calls the ParseSubscribeMultiplexedResponse
// for further processing.
//
// Parameters:
// t: *testing.T instance.
// testName: testname for display.
// ssl: ssl setting.
// encrypted: encryption setting.
func SendMultiplexingRequest(t *testing.T, testName string, ssl bool, encrypted bool) {
	cipher := ""
	if encrypted {
		cipher = "enigma"
	}
	message1 := "message1"
	message2 := "message2"
	r := GenRandom()

	pubnubChannel1 := fmt.Sprintf("testChannel_sub_%d", r.Intn(20))
	pubnubChannel2 := fmt.Sprintf("testChannel_sub_%d", r.Intn(20))

	pubnubChannel := pubnubChannel1 + "," + pubnubChannel2

	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", cipher, ssl, "")
	returnSubscribeChannel := make(chan []byte)
	errorChannelSub := make(chan []byte)
	responseChannelSub := make(chan string)
	waitChannelSub := make(chan string)

	go pubnubInstance.Subscribe(pubnubChannel, "", returnSubscribeChannel, false, errorChannelSub)
	go ParseSubscribeMultiplexedResponse(pubnubInstance, returnSubscribeChannel, message1, message2, pubnubChannel1, pubnubChannel2, testName, responseChannelSub)
	//go ParseErrorResponse(errorChannelSub, responseChannelSub)
	go ParseResponseDummyMessage(errorChannelSub, "aborted", responseChannelSub)
	go WaitForCompletion(responseChannelSub, waitChannelSub)
	ParseWaitResponse(waitChannelSub, t, testName)
	go pubnubInstance.Unsubscribe(pubnubChannel, returnSubscribeChannel, errorChannelSub)
	pubnubInstance.CloseExistingConnection()
}
开发者ID:GleasonK,项目名称:go,代码行数:40,代码来源:pubnubSubscribe_test.go


示例6: TestSubscriptionConnectStatus

// TestSubscriptionConnectStatus sends out a subscribe request to a pubnub channel
// and validates the response for the connect status.
func TestSubscriptionConnectStatus(t *testing.T) {
	assert := assert.New(t)

	stop, _ := NewVCRBoth(
		"fixtures/subscribe/connectStatus", []string{"uuid"})
	defer stop()

	channel := "Channel_ConnectStatus"
	uuid := "UUID_ConnectStatus"
	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, uuid)

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

	go pubnubInstance.Subscribe(channel, "", successChannel, false, errorChannel)
	select {
	case resp := <-successChannel:
		response := fmt.Sprintf("%s", resp)
		if response != "[]" {
			message := "'" + channel + "' connected"
			assert.Contains(response, message)
		}
	case err := <-errorChannel:
		if !IsConnectionRefusedError(err) {
			assert.Fail(string(err))
		}
	case <-timeouts(3):
		assert.Fail("Subscribe timeout 3s")
	}

	go pubnubInstance.Unsubscribe(channel, unsubscribeSuccessChannel, unsubscribeErrorChannel)
	ExpectUnsubscribedEvent(t, channel, "", unsubscribeSuccessChannel, unsubscribeErrorChannel)
}
开发者ID:pubnub,项目名称:go,代码行数:37,代码来源:pubnubSubscribe_test.go


示例7: DetailedHistoryFor10Messages

// DetailedHistoryFor10Messages is a common method used by both TestDetailedHistoryFor10EncryptedMessages
// and TestDetailedHistoryFor10Messages to publish's 10 messages to a pubnub channel, and after that
// call the history method of the messaging package to fetch last 10 messages. These received
// messages are compared to the messages sent and if all match test is successful.
func DetailedHistoryFor10Messages(t *testing.T, cipherKey string, testName string) {
	numberOfMessages := 10
	startMessagesFrom := 0
	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, SecKey, cipherKey, false, "")

	message := "Test Message "
	r := GenRandom()
	channel := fmt.Sprintf("testChannel_dh_%d", r.Intn(20))

	messagesSent := PublishMessages(pubnubInstance, channel, t, startMessagesFrom, numberOfMessages, message)
	if messagesSent {
		returnHistoryChannel := make(chan []byte)
		errorChannel := make(chan []byte)
		responseChannel := make(chan string)
		waitChannel := make(chan string)

		go pubnubInstance.History(channel, numberOfMessages, 0, 0, false, returnHistoryChannel, errorChannel)
		go ParseHistoryResponseForMultipleMessages(returnHistoryChannel, channel, message, testName, startMessagesFrom, numberOfMessages, cipherKey, responseChannel)
		go ParseErrorResponse(errorChannel, responseChannel)
		go WaitForCompletion(responseChannel, waitChannel)
		ParseWaitResponse(waitChannel, t, testName)
	} else {
		t.Error("Test '" + testName + "': failed.")
	}
}
开发者ID:GleasonK,项目名称:go,代码行数:29,代码来源:pubnubDetailedHistory_test.go


示例8: TestSuccessCodeAndInfoForComplexMessage

// TestSuccessCodeAndInfoForComplexMessage sends out a complex message to the pubnub channel
func TestSuccessCodeAndInfoForComplexMessage(t *testing.T) {
	assert := assert.New(t)

	stop, _ := NewVCRNonSubscribe(
		"fixtures/publish/successCodeAndInfoForComplexMessage", []string{"uuid"})
	defer stop()

	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, "")
	channel := "successCodeAndInfoForComplexMessage"

	customStruct := CustomStruct{
		Foo: "hi!",
		Bar: []int{1, 2, 3, 4, 5},
	}

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

	go pubnubInstance.Publish(channel, customStruct, successChannel, errorChannel)
	select {
	case msg := <-successChannel:
		assert.Contains(string(msg), "1,")
		assert.Contains(string(msg), "\"Sent\",")
	case err := <-errorChannel:
		assert.Fail(string(err))
	case <-timeout():
		assert.Fail("Publish timeout")
	}
}
开发者ID:pubnub,项目名称:go,代码行数:30,代码来源:pubnubPublish_test.go


示例9: TestSuccessCodeAndInfoWithEncryption

// TestSuccessCodeAndInfoWithEncryption sends out an encrypted
// message to the pubnub channel
func TestSuccessCodeAndInfoWithEncryption(t *testing.T) {
	assert := assert.New(t)

	stop, _ := NewVCRNonSubscribe(
		"fixtures/publish/successCodeAndInfoWithEncryption", []string{"uuid"})
	defer stop()

	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "enigma", false, "")
	channel := "successCodeAndInfo"
	message := "Pubnub API Usage Example"

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

	go pubnubInstance.Publish(channel, message, successChannel, errorChannel)
	select {
	case msg := <-successChannel:
		assert.Contains(string(msg), "1,")
		assert.Contains(string(msg), "\"Sent\",")
	case err := <-errorChannel:
		assert.Fail(string(err))
	case <-timeout():
		assert.Fail("Publish timeout")
	}
}
开发者ID:pubnub,项目名称:go,代码行数:27,代码来源:pubnubPublish_test.go


示例10: TestWildcardSubscriptionConnectedAndUnsubscribedSingle

func TestWildcardSubscriptionConnectedAndUnsubscribedSingle(t *testing.T) {
	assert := assert.New(t)

	stop, _ := NewVCRBoth("fixtures/wildcard/connAndUns", []string{"uuid"})
	defer stop()

	major := "Channel_ConnAndUns"
	wildcard := fmt.Sprintf("%s.*", major)
	uuid := "UUID_ConnAndUns"
	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, uuid)

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

	go pubnubInstance.Subscribe(wildcard, "",
		subscribeSuccessChannel, false, subscribeErrorChannel)
	select {
	case msg := <-subscribeSuccessChannel:
		val := string(msg)
		assert.Equal(fmt.Sprintf(
			"[1, \"Subscription to channel '%s' connected\", \"%s\"]",
			wildcard, wildcard), val)
	case err := <-subscribeErrorChannel:
		assert.Fail(string(err))
	}

	go pubnubInstance.Unsubscribe(wildcard, successChannel, errorChannel)
	ExpectUnsubscribedEvent(t, wildcard, "", successChannel, errorChannel)

	// pubnubInstance.CloseExistingConnection()
}
开发者ID:anovikov1984,项目名称:go,代码行数:33,代码来源:pubnubWildcardSubscribe_test.go


示例11: TestGroupSubscriptionToNotExistingChannelGroup

func TestGroupSubscriptionToNotExistingChannelGroup(t *testing.T) {
	assert := assert.New(t)

	stop, sleep := NewVCRBoth(
		"fixtures/groups/notExistingCG", []string{"uuid"})
	defer stop()

	group := "Group_NotExistingCG"
	uuid := "UUID_NotExistingCG"
	pubnub := messaging.NewPubnub(PubKey, SubKey, "", "", false, uuid)

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

	removeChannelGroups(pubnub, []string{group})

	sleep(2)

	go pubnub.ChannelGroupSubscribe(group, successChannel, errorChannel)
	select {
	case response := <-successChannel:
		assert.Fail("Received success message while expecting error", string(response))
	case err := <-errorChannel:
		assert.Contains(string(err), "Channel group or groups result in empty subscription set")
		assert.Contains(string(err), group)
	}

	go pubnub.ChannelGroupUnsubscribe(group, unsubscribeSuccessChannel, unsubscribeErrorChannel)
	ExpectUnsubscribedEvent(t, "", group, unsubscribeSuccessChannel,
		unsubscribeErrorChannel)
}
开发者ID:pubnub,项目名称:go,代码行数:33,代码来源:pubnubSubscribeErrors_test.go


示例12: TestGroupSubscriptionNotSubscribed

func TestGroupSubscriptionNotSubscribed(t *testing.T) {
	assert := assert.New(t)

	stop, sleep := NewVCRNonSubscribe(
		"fixtures/groups/notSubscribed", []string{"uuid"})
	defer stop()

	group := "Group_NotSubscribed"
	uuid := "UUID_NotSubscribed"
	pubnub := messaging.NewPubnub(PubKey, SubKey, "", "", false, uuid)

	createChannelGroups(pubnub, []string{group})
	defer removeChannelGroups(pubnub, []string{group})

	sleep(2)

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

	go pubnub.ChannelGroupUnsubscribe(group, successChannel, errorChannel)
	select {
	case response := <-successChannel:
		assert.Fail("Received success message while expecting error", string(response))
	case err := <-errorChannel:
		assert.Contains(string(err), "Subscription to channel group")
		assert.Contains(string(err), "not subscribed")
	}

	pubnub.CloseExistingConnection()
}
开发者ID:pubnub,项目名称:go,代码行数:30,代码来源:pubnubSubscribeErrors_test.go


示例13: SetUpChannelGroup

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

	pubnub := messaging.NewPubnub(config.Keys.Pub, config.Keys.Sub, "", "",
		false, "")

	pubnub.SetAuthenticationKey(bootstrapAuth)

	// Remove Group
	go pubnub.ChannelGroupRemoveGroup(config.StocksChannelGroup,
		successChannel, errorChannel)
	go handleResponse(successChannel, errorChannel,
		messaging.GetNonSubscribeTimeout(), done)

	<-done

	// Create it from the scratch
	go pubnub.ChannelGroupAddChannel(config.StocksChannelGroup, stockNames,
		successChannel, errorChannel)
	go handleResponse(successChannel, errorChannel,
		messaging.GetNonSubscribeTimeout(), done)

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


示例14: grantSubscribe

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")
	pubInstance := messaging.NewPubnub(publishKey, subscribeKey, secretKey, "", true, uuid)
	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)
	go pubInstance.GrantSubscribe(ch, bRead, bWrite, iTTL, "", successChannel, errorChannel)
	handleResult(w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Revoke Subscribe")
}
开发者ID:pubnub,项目名称:go,代码行数:26,代码来源:main.go


示例15: TestUnsubscribeChannel

// TestUnsubscribe will subscribe to a pubnub channel and then send an unsubscribe request
// The response should contain 'unsubscribed'
func TestUnsubscribeChannel(t *testing.T) {
	assert := assert.New(t)

	stop, sleep := NewVCRBoth(
		"fixtures/unsubscribe/channel", []string{"uuid"})
	defer stop()

	channel := "Channel_UnsubscribeChannel"
	uuid := "UUID_UnsubscribeChannel"
	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, uuid)

	subscribeSuccessChannel := make(chan []byte)
	subscribeErrorChannel := make(chan []byte)
	unSubscribeSuccessChannel := make(chan []byte)
	unSubscribeErrorChannel := make(chan []byte)

	go pubnubInstance.Subscribe(channel, "", subscribeSuccessChannel,
		false, subscribeErrorChannel)
	select {
	case msg := <-subscribeSuccessChannel:
		val := string(msg)
		assert.Equal(val, fmt.Sprintf(
			"[1, \"Subscription to channel '%s' connected\", \"%s\"]",
			channel, channel))
	case err := <-subscribeErrorChannel:
		assert.Fail(string(err))
	}

	sleep(2)

	go pubnubInstance.Unsubscribe(channel, unSubscribeSuccessChannel,
		unSubscribeErrorChannel)
	select {
	case msg := <-unSubscribeSuccessChannel:
		val := string(msg)
		assert.Equal(val, fmt.Sprintf(
			"[1, \"Subscription to channel '%s' unsubscribed\", \"%s\"]",
			channel, channel))
	case err := <-unSubscribeErrorChannel:
		assert.Fail(string(err))
	}

	select {
	case ev := <-unSubscribeSuccessChannel:
		var event messaging.PresenceResonse

		err := json.Unmarshal(ev, &event)
		if err != nil {
			assert.Fail(err.Error())
		}

		assert.Equal("leave", event.Action)
		assert.Equal(200, event.Status)
	case err := <-unSubscribeErrorChannel:
		assert.Fail(string(err))
	}

	// pubnubInstance.CloseExistingConnection()
}
开发者ID:anovikov1984,项目名称:go,代码行数:61,代码来源:pubnubUnsubscribe_test.go


示例16: TestSetUserStateGlobalHereNow

func TestSetUserStateGlobalHereNow(t *testing.T) {
	assert := assert.New(t)

	stop, sleep := NewVCRBoth(
		"fixtures/presence/setUserStateGlobalHereNow", []string{"uuid"})
	defer stop()

	channel := "Channel_SetUserStateGlobalHereNow"
	uuid := "UUID_SetUserStateGlobalHereNow"
	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, SecKey, "", false, uuid)

	key := "testkey"
	val := "testval"

	successChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	successSet := make(chan []byte)
	errorSet := make(chan []byte)
	successGet := make(chan []byte)
	errorGet := make(chan []byte)
	unsubscribeSuccessChannel := make(chan []byte)
	unsubscribeErrorChannel := make(chan []byte)

	go pubnubInstance.Subscribe(channel, "", successChannel, false, errorChannel)
	ExpectConnectedEvent(t, channel, "", successChannel, errorChannel)

	go pubnubInstance.SetUserStateKeyVal(channel, key, val, successSet, errorSet)
	select {
	case value := <-successSet:
		actual := string(value)
		expectedSubstring := fmt.Sprintf("{\"%s\": \"%s\"}", key, val)

		assert.Contains(actual, expectedSubstring)
	case err := <-errorSet:
		assert.Fail("Failed to set state", string(err))
	case <-messaging.Timeout():
		assert.Fail("Set state timeout")
	}

	sleep(PresenceServerTimeoutLower)

	go pubnubInstance.GlobalHereNow(true, true, successGet, errorGet)
	select {
	case value := <-successGet:
		actual := string(value)
		expectedSubstring := fmt.Sprintf("{\"%s\": \"%s\"}", key, val)

		assert.Contains(actual, expectedSubstring)
		assert.Contains(actual, pubnubInstance.GetUUID())
	case err := <-errorSet:
		assert.Fail("Failed to get state", string(err))
	case <-messaging.Timeout():
		assert.Fail("Get state timeout")
	}

	go pubnubInstance.Unsubscribe(channel, unsubscribeSuccessChannel, unsubscribeErrorChannel)
	ExpectUnsubscribedEvent(t, channel, "", unsubscribeSuccessChannel, unsubscribeErrorChannel)
}
开发者ID:pubnub,项目名称:go,代码行数:58,代码来源:pubnubPresence_test.go


示例17: setAuthKey

func setAuthKey(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	authKey := q.Get("authkey")
	uuid := q.Get("uuid")

	pubInstance := messaging.NewPubnub(publishKey, subscribeKey, secretKey, "", true, uuid)
	pubInstance.SetAuthenticationKey(authKey)
	sendResponseToChannel(w, "Auth key set", r, uuid)
}
开发者ID:pubnub,项目名称:go,代码行数:9,代码来源:main.go


示例18: revokeSubscribe

func revokeSubscribe(w http.ResponseWriter, r *http.Request) {
	q := r.URL.Query()
	ch := q.Get("ch")
	uuid := q.Get("uuid")
	pubInstance := messaging.NewPubnub(publishKey, subscribeKey, secretKey, "", true, uuid)
	errorChannel := make(chan []byte)
	successChannel := make(chan []byte)
	go pubInstance.GrantSubscribe(ch, false, false, 0, "", successChannel, errorChannel)
	handleResult(w, r, uuid, successChannel, errorChannel, messaging.GetNonSubscribeTimeout(), "Revoke Subscribe")
}
开发者ID:pubnub,项目名称:go,代码行数:10,代码来源:main.go


示例19: subscribe

func subscribe(w http.ResponseWriter, r *http.Request) {
	var errorChannel = make(chan []byte)
	var subscribeChannel = make(chan []byte)
	messaging.LoggingEnabled(true)
	messaging.SetLogOutput(os.Stdout)
	pubInstance := messaging.NewPubnub(publishKey, subscribeKey, secretKey, "", true, "")

	go pubInstance.Subscribe("test2", "", subscribeChannel, false, errorChannel)
	go handleSubscribeResult(subscribeChannel, errorChannel, "Subscribe")
}
开发者ID:pubnub,项目名称:go,代码行数:10,代码来源:main.go


示例20: TestCustomUuid

// TestCustomUuid subscribes to a pubnub channel using a custom uuid and then
// makes a call to the herenow method of the pubnub api. The custom id should
// be present in the response else the test fails.
func TestCustomUuid(t *testing.T) {
	assert := assert.New(t)

	stop, sleep := NewVCRBoth(
		"fixtures/presence/customUuid", []string{"uuid"})
	defer stop()

	uuid := "customuuid"
	pubnubInstance := messaging.NewPubnub(PubKey, SubKey, "", "", false, uuid)
	channel := "customUuid"

	successChannel := make(chan []byte)
	errorChannel := make(chan []byte)
	unsubscribeSuccessChannel := make(chan []byte)
	unsubscribeErrorChannel := make(chan []byte)
	successGet := make(chan []byte)
	errorGet := make(chan []byte)

	go pubnubInstance.Subscribe(channel, "", successChannel, false, errorChannel)
	ExpectConnectedEvent(t, channel, "", successChannel, errorChannel)

	sleep(PresenceServerTimeoutHighter)

	go pubnubInstance.HereNow(channel, "", true, true, successGet, errorGet)
	select {
	case value := <-successGet:
		assert.Contains(string(value), uuid)
		var occupants struct {
			Uuids     []map[string]string
			Occupancy int
		}

		err := json.Unmarshal(value, &occupants)
		if err != nil {
			assert.Fail(err.Error())
		}

		found := false
		for _, v := range occupants.Uuids {
			if v["uuid"] == uuid {
				found = true
			}
		}

		assert.True(found)
	case err := <-errorGet:
		assert.Fail("Failed to get online users", string(err))
	case <-messaging.Timeout():
		assert.Fail("HereNow timeout")
	}

	go pubnubInstance.Unsubscribe(channel, unsubscribeSuccessChannel, unsubscribeErrorChannel)
	ExpectUnsubscribedEvent(t, channel, "", unsubscribeSuccessChannel, unsubscribeErrorChannel)
}
开发者ID:pubnub,项目名称:go,代码行数:57,代码来源:pubnubPresence_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang messaging.Pubnub类代码示例发布时间:2022-05-28
下一篇:
Golang messaging.GetNonSubscribeTimeout函数代码示例发布时间: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