本文整理匯總了Golang中github.com/fiorix/go-eventsocket/eventsocket.Connection.RemoteAddr方法的典型用法代碼示例。如果您正苦於以下問題:Golang Connection.RemoteAddr方法的具體用法?Golang Connection.RemoteAddr怎麽用?Golang Connection.RemoteAddr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fiorix/go-eventsocket/eventsocket.Connection
的用法示例。
在下文中一共展示了Connection.RemoteAddr方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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")
}
}
}
}
示例2: outboundHandler
func outboundHandler(c *eventsocket.Connection) {
r = redis.New()
r_err = r.Connect(host, port)
if r_err != nil {
log.Fatalf("Connect failed: %s\n", r_err.Error())
}
log.Println("Connected to redis-server.")
fmt.Println("new client:", c.RemoteAddr())
s := Session{}
s.c = c
{
ev, err := c.Send("connect")
if err != nil {
fmt.Println("ERROR: ", err)
return
}
s.callerid = ev.Get("Channel-Caller-Id-Number")
s.callername = ev.Get("Channel-Caller-Id-Name")
s.inbound_uuid = ev.Get("Channel-Unique-Id")
}
c.Send("linger 5")
c.Execute("answer", "", true)
go secretaryCallOut(&s)
c.Execute("playback", "local_stream://moh", true)
fmt.Println("playback aborted")
normal_clearing := false
{
ev, err := c.Send("api uuid_getvar " + s.inbound_uuid +
" hangup_cause")
if err != nil && ev.Body != "" {
normal_clearing = true
}
}
hup := false
if s.secretary_uuid == "" {
hup = true
} else {
ev, err := c.Send("api uuid_exists " + s.secretary_uuid)
if err != nil || ev.Body == "false" {
hup = true
} else {
// secretary is running
if normal_clearing {
// abort the secretary
fmt.Println("Aborting the secretary")
c.Send("api uuid_kill " + s.secretary_uuid)
}
}
}
if hup {
c.Execute("playback", "misc/sorry.wav", true)
c.Execute("sleep", "500", true)
c.Execute("hangup", "", false)
fmt.Println("hup")
}
c.Close()
}
示例3: outboundHandler
func outboundHandler(c *eventsocket.Connection) {
{
r = redis.New()
r_err = r.Connect(host, port)
if r_err != nil {
log.Fatalf("Connect failed: %s\n", r_err.Error())
}
// log.Println("連接redis服務器.")
}
fmt.Println("new client:", c.RemoteAddr())
s := Session{}
s.c = c
{
ev, err := c.Send("connect")
if err != nil {
fmt.Println("ERROR: ", err)
return
}
s.caller_id_number = ev.Get("Channel-Caller-Id-Number")
s.callername = ev.Get("Channel-Caller-Id-Name")
s.destination_number = ev.Get("Channel-Destination-Number")
s.inbound_uuid = ev.Get("Channel-Unique-Id")
// 根據主被叫確定辦公電話,客戶電話,客戶電話狀態和分機號碼
s.office_number_type = "湖南好搜"
s.custom_number_status = "未知"
if len(s.caller_id_number) == 4 { //主叫4位,內線外呼
s.call_direction = "呼出"
s.subnum = s.caller_id_number
s.custom_number = s.destination_number
s.office_number, err = r.HGet("rec:"+s.subnum, "phone")
if err != nil {
s.office_number = "82088888"
}
// 確定分機所屬部門及客戶電話狀態
if subnum, _ := r.SIsMember("allusers:100", s.subnum); subnum {
s.subnum_type = "銷售"
if cnum, _ := r.SIsMember("rec:custom", s.custom_number); cnum {
s.custom_number_status = "custom"
}
if cnum, _ := r.SIsMember("rec:warning", s.custom_number); cnum {
s.custom_number_status = "warning"
}
if cnum, _ := r.SIsMember("rec:bother", s.custom_number); cnum {
s.custom_number_status = "bother"
}
}
} else if len(s.caller_id_number) > 7 { //主叫7位以上號碼,1.外線呼入,被叫是好搜; 2.分公司/客戶呼入,被叫是客戶; 3.外線呼入,被叫是分公司/客戶)
s.call_direction = "呼入"
s.custom_number = s.caller_id_number
s.office_number = s.destination_number
// 確定辦公電話類型
if cnum, _ := r.SIsMember("phone:hnzby", s.caller_id_number); cnum { //主叫電話為周邊雲號碼
s.call_direction = "呼出"
s.custom_number = s.destination_number
s.office_number = s.caller_id_number
s.office_number_type = "湖南周邊雲"
} else if dnum, _ := r.SIsMember("phone:hnzby", s.destination_number); dnum { //被叫電話位周邊雲號碼
s.office_number_type = "湖南周邊雲"
} else {
s.subnum, err = r.HGet("rec:phone", s.caller_id_number) //通過辦公號碼找到分機號
if err != nil {
s.subnum = "8888"
}
}
} else { //其他異常號碼,轉前台
s.call_direction = "未知"
s.custom_number_status = "異常"
}
// 確定客戶電話類型
s.custom_number = clearNum(s.custom_number)
if validate(s.custom_number, MOBILE) { //是否手機號碼
if cnum, _ := r.SIsMember("phone:hdata:0731", s.custom_number[0:7]); cnum {
s.custom_number_type = "本地手機"
} else {
s.custom_number_type = "外地手機"
s.custom_number = "0" + s.custom_number //加0
}
} else {
if s.custom_number[0:1] == "0" {
s.custom_number_type = "外地固話"
} else {
s.custom_number_type = "本地固話"
}
}
r.Quit()
// log.Println("斷開redis服務器.")
}
// 錄音文件名
year := time.Now().Format("2006")
month := time.Now().Format("01")
day := time.Now().Format("02")
s.rec_file = fmt.Sprintf("/mnt/stone/%s/%s/%s/%s_%s_%s.wav", year, month, day, s.caller_id_number, s.destination_number, s.inbound_uuid)
//.........這裏部分代碼省略.........
示例4: handler
// Handle incoming call
func (e *EventSocketServer) handler(c *eventsocket.Connection) {
logger.Logger.Println("Incoming Event Socket connection from", c.RemoteAddr())
connectev, err := c.Send("connect") // Returns: Ganzer Event mit alles
if err != nil {
c.Send("exit")
logger.Logger.Print(err)
return
}
channelUUID := uuid.Parse(connectev.Get("Unique-Id"))
if channelUUID == nil {
c.Send("exit")
logger.Logger.Print(err)
return
}
defer logger.Logger.Println(channelUUID, "Handler ending")
// Filter and subscribe to events
c.Send("linger")
c.Send(fmt.Sprintf("filter Unique-ID %v", channelUUID))
c.Send("event plain CHANNEL_CALLSTATE CUSTOM spandsp::rxfaxnegociateresult spandsp::rxfaxpageresult spandsp::rxfaxresult")
// Extract Caller/Callee
recipient := connectev.Get("Variable_sip_to_user")
cidname := connectev.Get("Channel-Caller-Id-Name")
cidnum := connectev.Get("Channel-Caller-Id-Number")
logger.Logger.Printf("Incoming call to %v from %v <%v>", recipient, cidname, cidnum)
var device *Device
if gofaxlib.Config.Gofaxd.AllocateInboundDevices {
// Find free device
device, err := devmanager.FindDevice(fmt.Sprintf("Receiving facsimile"))
if err != nil {
logger.Logger.Println(err)
c.Execute("respond", "404", true)
c.Send("exit")
return
}
defer device.SetReady()
}
var usedDevice string
if device != nil {
usedDevice = device.Name
} else {
usedDevice = defaultDevice
}
csi := gofaxlib.Config.Freeswitch.Ident
// Query DynamicConfig
if dcCmd := gofaxlib.Config.Gofaxd.DynamicConfig; dcCmd != "" {
logger.Logger.Println("Calling DynamicConfig script", dcCmd)
dc, err := gofaxlib.DynamicConfig(dcCmd, usedDevice, cidnum, cidname, recipient)
if err != nil {
logger.Logger.Println("Error calling DynamicConfig:", err)
} else {
// Check if call should be rejected
if gofaxlib.DynamicConfigBool(dc.GetFirst("RejectCall")) {
logger.Logger.Println("DynamicConfig decided to reject this call")
c.Execute("respond", "404", true)
c.Send("exit")
return
}
// Check if a custom identifier should be set
if dynamicCsi := dc.GetFirst("LocalIdentifier"); dynamicCsi != "" {
csi = dynamicCsi
}
}
}
sessionlog, err := gofaxlib.NewSessionLogger()
if err != nil {
c.Send("exit")
logger.Logger.Print(err)
return
}
logger.Logger.Println(channelUUID, "Logging events for commid", sessionlog.CommID(), "to", sessionlog.Logfile())
sessionlog.Log("Inbound channel UUID: ", channelUUID)
// Check if T.38 should be disabled
disableT38 := gofaxlib.Config.Freeswitch.DisableT38
if disableT38 {
sessionlog.Log("T.38 disabled by configuration")
} else {
disableT38, err = gofaxlib.GetSoftmodemFallback(nil, cidnum)
if err != nil {
sessionlog.Log(err)
disableT38 = false
}
if disableT38 {
sessionlog.Log(fmt.Sprintf("Softmodem fallback active for caller %s, disabling T.38", cidnum))
}
}
//.........這裏部分代碼省略.........