FreeSWITCH goesl

今天试了试github.com/0x19/goesl,记录如下:

  • 下载并安装go,放在/usr/bin/go目录,步骤略

  • go配置:

export PATH=$PATH:/usr/bin/go/bin
export GOROOT=/usr/bin/go
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
  • 编辑go.mod:

module goesldemo
go 1.18
require github.com/0x19/goesl v0.0.0-20191107044804-3efcc2f41ccb
require github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
  • 编辑main.go:

package main

// https://pkg.go.dev/github.com/0x19/goesl#section-documentation
// https://pkg.go.dev/github.com/percipia/eslgo#section-documentation

import (
    "flag"
    // "fmt"
    "github.com/0x19/goesl"
    "runtime"
    "strings"
)

var (
    fshost   = flag.String("fshost", "127.0.0.1", "Freeswitch hostname. Default: localhost")
    fsport   = flag.Uint("fsport", 8021, "Freeswitch port. Default: 8021")
    password = flag.String("pass", "ClueCon", "Freeswitch password. Default: ClueCon")
    timeout  = flag.Int("timeout", 10, "Freeswitch conneciton timeout in seconds. Default: 10")
)

// Small client that will first make sure all events are returned as JSON and second, will originate
func main() {
    // Boost it as much as it can go ...
    runtime.GOMAXPROCS(runtime.NumCPU())

    client, err := goesl.NewClient(*fshost, *fsport, *password, *timeout)

    if err != nil {
        goesl.Error("Error while creating new client: %s", err)
        return
    }

    goesl.Debug("Yuhu! New client: %q", client)

    // Apparently all is good... Let us now handle connection :)
    // We don't want this to be inside of new connection as who knows where it my lead us.
    // Remember that this is crutial part in handling incoming messages :)
    go client.Handle()

    client.Send("events json ALL")

    // client.BgApi(fmt.Sprintf("originate %s %s", "sofia/internal/1001@127.0.0.1", "&socket(192.168.1.2:8084 async full)"))

    for {
        msg, err := client.ReadMessage()
        if err != nil {
            // If it contains EOF, we really dont care...
            if !strings.Contains(err.Error(), "EOF") && err.Error() != "unexpected end of JSON input" {
                goesl.Error("Error while reading Freeswitch message: %s", err)
            }
            break
        }

        goesl.Debug("%s", msg)
    }
}
  • go mod tidy && go run main.go # 或者 go build && ./goesldemo

参考下面这个go程序,并略有改动:

https://github.com/0x19/goesl/blob/master/examples/client.go

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值