當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Connection.ReadEvent方法代碼示例

本文整理匯總了Golang中github.com/fiorix/go-eventsocket/eventsocket.Connection.ReadEvent方法的典型用法代碼示例。如果您正苦於以下問題:Golang Connection.ReadEvent方法的具體用法?Golang Connection.ReadEvent怎麽用?Golang Connection.ReadEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/fiorix/go-eventsocket/eventsocket.Connection的用法示例。


在下文中一共展示了Connection.ReadEvent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: playAndGetOneDigit

func playAndGetOneDigit(
	sound string,
	c *eventsocket.Connection,
	uuid string) string {

	c.Send("filter Unique-ID " + uuid)
	c.Send("event plain CHANNEL_EXECUTE_COMPLETE")

	{
		_, err := c.ExecuteUUID(
			uuid,
			"play_and_get_digits",
			"1 1 1 400 # "+
				sound+" silence_stream://250 result \\d")
		if err != nil {
			fmt.Println("Error executing play_and_get_digits: ",
				err)
			return ""
		}
	}

	finished := false
	ret := ""

	for !finished {

		ev, err := c.ReadEvent()
		if err != nil {
			finished = true
		} else {
			if ev.Get("Event-Name") ==
				"CHANNEL_EXECUTE_COMPLETE" &&
				ev.Get("Application") == "play_and_get_digits" {
				ret = ev.Get("Variable_result")
				finished = true
			}
		}
	}

	c.Send("noevents")
	c.Send("filter delete Unique-ID " + uuid)

	return ret
}
開發者ID:transtone,項目名稱:transconfig,代碼行數:44,代碼來源:sec_1.go

示例2: handler

func handler(c *eventsocket.Connection) {
	fmt.Println("new client:", c.RemoteAddr())
	c.Send("connect")
	c.Send("myevents")
	c.Execute("answer", "", false)
	ev, err := c.Execute("playback", audioFile, true)
	if err != nil {
		log.Fatal(err)
	}
	ev.PrettyPrint()
	for {
		ev, err = c.ReadEvent()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println("\nNew event")
		ev.PrettyPrint()
		if ev.Get("Application") == "playback" {
			if ev.Get("Application-Response") == "FILE PLAYED" {
				c.Send("exit")
			}
		}
	}
}
開發者ID:kenrdavis,項目名稱:go-eventsocket,代碼行數:24,代碼來源:server.go


注:本文中的github.com/fiorix/go-eventsocket/eventsocket.Connection.ReadEvent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。