Пример #1
0
// ResumeOnReconnect contains the actual impementation of both TestResumeOnReconnectFalse and TestResumeOnReconnectTrue
// the parameter b determines of resume on reconnect setting is true or false.
func ResumeOnReconnect(t *testing.T, b bool) {
	testName := "ResumeOnReconnectFalse"
	if b {
		pubnubMessaging.SetResumeOnReconnect(true)
		testName = "ResumeOnReconnectTrue"
	} else {
		pubnubMessaging.SetResumeOnReconnect(false)
	}
	pubnubChannel := "testChannel"

	pubnubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", "", false, "")
	returnSubscribeChannel := make(chan []byte)
	errorChannelSub := make(chan []byte)
	responseChannelSub := make(chan string)
	waitChannelSub := make(chan string)

	pubnubMessaging.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)
	pubnubMessaging.SetSubscribeTimeout(310)
}
Пример #2
0
// Init asks the user the basic settings to initialize to the pubnub struct.
// Settings include the pubnub channel(s) to connect to.
// Ssl settings
// Cipher key
// Secret Key
// Custom Uuid
// Proxy details
//
// The method returns false if the channel name is not provided.
//
// returns: a bool, true if the user completed the initail settings.
func Init() (b bool) {
	fmt.Println("PubNub Api for go;", pubnubMessaging.VersionInfo())
	fmt.Println("Please enter the channel name(s). Enter multiple channels separated by comma without spaces.")
	reader := bufio.NewReader(os.Stdin)

	line, _, err := reader.ReadLine()
	if err != nil {
		fmt.Println(err)
	} else {
		_connectChannels = string(line)
		if strings.TrimSpace(_connectChannels) != "" {
			fmt.Println("Channel: ", _connectChannels)
			fmt.Println("Enable SSL? Enter y for Yes, n for No.")
			var enableSsl string
			fmt.Scanln(&enableSsl)

			if enableSsl == "y" || enableSsl == "Y" {
				_ssl = true
				fmt.Println("SSL enabled")
			} else {
				_ssl = false
				fmt.Println("SSL disabled")
			}

			fmt.Println("Please enter a CIPHER key, leave blank if you don't want to use this.")
			fmt.Scanln(&_cipher)
			fmt.Println("Cipher: ", _cipher)

			fmt.Println("Please enter a Custom UUID, leave blank for default.")
			fmt.Scanln(&_uuid)
			fmt.Println("UUID: ", _uuid)

			fmt.Println("Display error messages? Enter y for Yes, n for No. Default is Yes")
			var enableErrorMessages = "y"
			fmt.Scanln(&enableErrorMessages)

			if enableErrorMessages == "y" || enableErrorMessages == "Y" {
				_displayError = true
				fmt.Println("Error messages will be displayed")
			} else {
				_displayError = false
				fmt.Println("Error messages will not be displayed")
			}

			fmt.Println("Enable resume on reconnect? Enter y for Yes, n for No. Default is Yes")
			var enableResumeOnReconnect = "y"
			fmt.Scanln(&enableResumeOnReconnect)

			if enableResumeOnReconnect == "y" || enableResumeOnReconnect == "Y" {
				pubnubMessaging.SetResumeOnReconnect(true)
				fmt.Println("Resume on reconnect enabled")
			} else {
				pubnubMessaging.SetResumeOnReconnect(false)
				fmt.Println("Resume on reconnect disabled")
			}

			fmt.Println("Set subscribe timeout? Enter numerals.")
			var subscribeTimeout = ""
			fmt.Scanln(&subscribeTimeout)
			val, err := strconv.Atoi(subscribeTimeout)
			if err != nil {
				fmt.Println("Entered value is invalid. Using default value.")
			} else {
				pubnubMessaging.SetSubscribeTimeout(int64(val))
			}
			pubnubMessaging.SetOrigin("pubsub.pubnub.com")
			pubInstance := pubnubMessaging.PubnubInit("demo", "demo", "", _cipher, _ssl, _uuid)

			_pub = pubInstance

			SetupProxy()

			return true
		} else {
			fmt.Println("Channel cannot be empty.")
		}
	}
	return false
}