ctrl

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ACall

func ACall(subject string, method string, req interface{}, opts ...*AsyncCallOption) error

func AService

func AService() xctrl.XNodeService

AsyncService 异步调用2,使用Context

func AsyncService

func AsyncService() xctrl.XNodeService

AsyncService 异步调用

func CManService

func CManService() cman.CManService

CManService 同步调用

func Call

func Call(topic string, req *Request, timeout time.Duration) (*nats.Message, error)

Call 发起 request 请求

func ContextWithID

func ContextWithID(id string) context.Context

ContextWithID 创建带请求ID的context

func CtrlStartUp

func CtrlStartUp(req *xctrl.CtrlStartUpRequest) error

func DelChannel

func DelChannel(uuid string) error

DelChannel get channel

func DeliverToChannelEventThread

func DeliverToChannelEventThread(channel *Channel, natsEvent nats.Event)

func DoResultCallback

func DoResultCallback(msg *Message)

func EnableApp

func EnableApp(handler AppHandler, subject string, queue string) error

EnableApp APP事件

func EnableEvent

func EnableEvent(handler EventHandler, subject string, queue string) error

EnableEvent 开启事件监听 cn.xswitch.ctrl.event.cdr cn.xswitch.ctrl.event.custom.sofia>

func EnableNodeStatus

func EnableNodeStatus(subject string) error

EnableNodeStatus 启用节点状态事件 cn.xswitch.node.status

func EnableRequest

func EnableRequest(handler RequestHandler, subject string, queue string) error

EnableRequest 开启Request请求监听 FetchXMl Dialplan

func ForkDTMFEventToChannelEventThread

func ForkDTMFEventToChannelEventThread() error

ForkDTMFEventToChannelEvent 将DTMF事件放到ChannelEvent事件相同的线程处理

func GetChannelState

func GetChannelState(uuid string) string

GetChannelState 获取 channel 状态

func GetNodeList

func GetNodeList() map[string]*xctrl.Node

func Hostname

func Hostname(uuid string) string

Hostname 根据 node uuid 获取 hostname

func Init

func Init(trace bool, addrs string) error

Init 初始化Ctrl trace 是否开启NATS消息跟踪, addrs nats消息队列连接地址

func InitCManService

func InitCManService(addr string) error

func Node

func Node(hostname string) *xctrl.Node

Node 根据 hostname 获取 node 节点信息

func NodeAddress

func NodeAddress(nodeUUID string) string

Node Address 标准化Node地址

func Publish

func Publish(topic string, msg []byte, opts ...nats.PublishOption) error

Publish 发送消息

func PublishJSON

func PublishJSON(topic string, obj interface{}, opts ...nats.PublishOption) error

PublishJSON 发送JSON消息

func RawMessage

func RawMessage(data []byte) *json.RawMessage

RawMessage .

func RegisterHashNodeFun added in v1.1.0

func RegisterHashNodeFun(nodeCallbackFunc NodeHashFun)

func Respond

func Respond(topic string, resp *Response, opts ...nats.PublishOption) error

Respond 响应NATS Request 请求

func Service

func Service() xctrl.XNodeService

Service 同步调用

func SetLogLevel

func SetLogLevel(level LogLevel)

func SetLogger

func SetLogger(l Logger)

func Subscribe

func Subscribe(subject string, cb nats.EventCallback, queue string) (nats.Subscriber, error)

func ToRawMessage

func ToRawMessage(vPoint interface{}) *json.RawMessage

func Transfer

func Transfer(ctrlID string, channel *xctrl.ChannelEvent) error

func TranslateMethod

func TranslateMethod(method string) string

TranslateMethod change request method to NativeJSAPI

func UUID

func UUID() string

UUID get ctrl uuid

func WithAddress

func WithAddress(nodeUUID string) client.CallOption

WithAddress 创建Node地址

func WithAddressDefault

func WithAddressDefault() client.CallOption

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) client.CallOption

NATS Request Timeout

func WithTimeout

func WithTimeout(d time.Duration) client.CallOption

func XCall

func XCall(topic string, method string, params interface{}, timeout time.Duration) (*nats.Message, error)

XCall 发起 request 请求

Types

type AppHandler

type AppHandler interface {
	ChannelEvent(context.Context, *Channel)
	Event(msg *Message, natsEvent nats.Event)
}

type AsyncCallOption

type AsyncCallOption struct {
	// contains filtered or unexported fields
}

func ACallOption

func ACallOption() *AsyncCallOption

func (*AsyncCallOption) WithCallback

func (opt *AsyncCallOption) WithCallback(f ResultCallbackFunc) *AsyncCallOption

func (*AsyncCallOption) WithData

func (opt *AsyncCallOption) WithData(data interface{}) *AsyncCallOption

type Channel

type Channel struct {
	*xctrl.ChannelEvent        // the parent ChannelEvent
	CtrlUuid            string // the Controller UUID
	// contains filtered or unexported fields
}

Channel call channel

func FindChannel

func FindChannel(condition string, argument string) []*Channel

func NewChannel

func NewChannel(channel_uuid string) *Channel

only call at the first time

func NewChannelEvent

func NewChannelEvent() *Channel

func ReadChannel

func ReadChannel(uuid string) (*Channel, error)

ReadChannel get channel

func WriteChannel

func WriteChannel(uuid string, channel *Channel) *Channel

WriteChannel save channel

func (*Channel) Accept0

func (channel *Channel) Accept0(opts ...client.CallOption) *xctrl.Response

Accept 接管

func (*Channel) AcceptAndTakeOver

func (channel *Channel) AcceptAndTakeOver(opts ...client.CallOption) *xctrl.Response

Accept 接管

func (*Channel) AcceptWithChannelParams

func (channel *Channel) AcceptWithChannelParams(channel_params []string, opts ...client.CallOption) *xctrl.Response

Accept 接管

func (*Channel) AcceptWithChannelParamsAndTakeOver

func (channel *Channel) AcceptWithChannelParamsAndTakeOver(channel_params []string, opts ...client.CallOption) *xctrl.Response

Accept 接管

func (*Channel) Answer0

func (channel *Channel) Answer0(opts ...client.CallOption) *xctrl.Response

Answer 应答

func (*Channel) AnswerWithChannelParams

func (channel *Channel) AnswerWithChannelParams(channel_params []string, opts ...client.CallOption) *xctrl.Response

Answer 应答

func (*Channel) Bridge0

func (channel *Channel) Bridge0(req *xctrl.BridgeRequest, async bool) *xctrl.Response

Bridge 在把当前呼叫桥接(发起)另一个呼叫

func (*Channel) DetectSpeech0

func (channel *Channel) DetectSpeech0(req *xctrl.DetectRequest, async bool) *xctrl.DetectResponse

DetectSpeech 语音识别

func (*Channel) FullCtrlUuid

func (channel *Channel) FullCtrlUuid() string

func (*Channel) GetChannelEvent

func (channel *Channel) GetChannelEvent() *xctrl.ChannelEvent

GetChannelEvent .

func (*Channel) GetNatsEvent

func (channel *Channel) GetNatsEvent() nats.Event

func (*Channel) GetUserData

func (channel *Channel) GetUserData() interface{}

func (*Channel) GetVariable0

func (channel *Channel) GetVariable0(key string) string

GetVariable 获取通道变量

func (*Channel) Hangup0

func (channel *Channel) Hangup0(cause string, flag xctrl.HangupRequest_HangupFlag) *xctrl.Response

Hangup 挂机

func (*Channel) Marshal

func (channel *Channel) Marshal() []byte

Marshal marshal to JSON

func (*Channel) NodeAddress

func (channel *Channel) NodeAddress() client.CallOption

NodeAddress 生成NODE地址

func (*Channel) Play0

func (channel *Channel) Play0(req *xctrl.PlayRequest) *xctrl.Response

Play 播放一个文件,默认超时时间1小时

func (*Channel) PlayFile

func (channel *Channel) PlayFile(file string, opts ...client.CallOption) *xctrl.Response

func (*Channel) PlayTTS

func (channel *Channel) PlayTTS(engine string, voice string, text string, opts ...client.CallOption) *xctrl.Response

func (*Channel) PlayWithTimeout

func (channel *Channel) PlayWithTimeout(req *xctrl.PlayRequest, timeout time.Duration) *xctrl.Response

PlayWithTimeout 播放一个文件,可传入超时时间

func (*Channel) Ready

func (channel *Channel) Ready() bool

Ready 判断通道是否正常状态

func (*Channel) RingBackDetection0

func (channel *Channel) RingBackDetection0(req *xctrl.RingBackDetectionRequest, async bool) *xctrl.Response

RingBackDetection 回铃音检测

func (*Channel) Save

func (channel *Channel) Save() *Channel

func (*Channel) SendDTMF0

func (channel *Channel) SendDTMF0(dtmf string) *xctrl.Response

SendDTMF 发送DTMF

func (*Channel) SetUserData

func (channel *Channel) SetUserData(userData interface{})

func (*Channel) SetVariable0

func (channel *Channel) SetVariable0(key, value string) error

SetVariable 保存通道变量

func (*Channel) SetVariables

func (channel *Channel) SetVariables(vars map[string]string) error

SetVariables 保存多个通道变量

func (*Channel) Stop0

func (channel *Channel) Stop0() *xctrl.Response

Stop 停止当前正在执行的API

func (*Channel) String

func (channel *Channel) String() string

String marshalIndent

func (*Channel) Subscribe

func (channel *Channel) Subscribe(subject string, cb nats.EventCallback, queue string) (nats.Subscriber, error)

type ContextKey

type ContextKey string

type Ctrl

type Ctrl struct {
	// contains filtered or unexported fields
}

Ctrl 控制中心

func (*Ctrl) EnableApp

func (h *Ctrl) EnableApp(handler AppHandler, subject string, queue string) error

EnableApp APP事件

func (*Ctrl) EnableEvent

func (h *Ctrl) EnableEvent(handler EventHandler, subject string, queue string) error

EnableEvent 开启事件监听

func (*Ctrl) EnableRequest

func (h *Ctrl) EnableRequest(handler RequestHandler, subject string, queue string) error

EnableRequest 开启Request请求监听

func (*Ctrl) EnbaleNodeStatus

func (h *Ctrl) EnbaleNodeStatus(subject string) error

EnbaleNodeStatus 开启节点监听

func (*Ctrl) ForkDTMFEventToChannelEventThread

func (h *Ctrl) ForkDTMFEventToChannelEventThread() error

ForkDTMFEventToChannelEventThread

func (*Ctrl) NewCManService

func (h *Ctrl) NewCManService(addr string) cman.CManService

NewCManService 创建 CManService

func (*Ctrl) Subscribe

func (h *Ctrl) Subscribe(topic string, cb nats.EventCallback, queue string) (nats.Subscriber, error)

订阅消息

type EmptyAppHandler

type EmptyAppHandler struct{}

func (*EmptyAppHandler) ChannelEvent

func (h *EmptyAppHandler) ChannelEvent(context.Context, *Channel)

func (*EmptyAppHandler) Event

func (h *EmptyAppHandler) Event(*Message, nats.Event)

type EmptyEventHandler

type EmptyEventHandler struct{}

func (*EmptyEventHandler) Event

func (h *EmptyEventHandler) Event(*Request)

type EmptyRequestHandler

type EmptyRequestHandler struct{}

func (*EmptyRequestHandler) Request

func (h *EmptyRequestHandler) Request(*Request, nats.Event)

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error represent JSON-RPC 2.0 "Error object".

func NewError

func NewError(code int, message string) *Error

NewError returns an Error with given code and message.

func ServerError

func ServerError(rpcerr error) *Error

ServerError convert errors returned by Client.Call() into Error. User should check for rpc.ErrShutdown and io.ErrUnexpectedEOF before calling ServerError.

func (*Error) Error

func (e *Error) Error() string

Error returns JSON representation of Error.

type EventHandler

type EventHandler interface {
	Event(req *Request, natsEvent nats.Event)
}

Handler Ctrl事件响应

type LogLevel

type LogLevel int
const (
	LLFatal LogLevel = iota
	LLError
	LLWarn
	LLInfo
	LLDebug
	LLTrace
)

type Logger

type Logger interface {
	Log(level int, v ...interface{})
	Logf(level int, format string, v ...interface{})
}

type Message

type Message struct {
	Version string           `json:"jsonrpc"`
	Method  string           `json:"method"`
	ID      *json.RawMessage `json:"id"`
	Params  *json.RawMessage `json:"params"`
	Result  *json.RawMessage `json:"result,omitempty"`
	Error   *json.RawMessage `json:"error,omitempty"`
}

Message Node异步请求消息

func (*Message) String

func (m *Message) String() string

type NodeHashFun added in v1.1.0

type NodeHashFun func(node *xctrl.Node, method string)

type Request

type Request struct {
	Version string           `json:"jsonrpc"`
	Method  string           `json:"method"`
	ID      *json.RawMessage `json:"id"`
	Params  *json.RawMessage `json:"params"`
}

Request RPC 请求对象

func (*Request) Marshal

func (r *Request) Marshal() []byte

func (*Request) RawMessage

func (r *Request) RawMessage() *json.RawMessage

type RequestHandler

type RequestHandler interface {
	Request(req *Request, natsEvent nats.Event)
}

type Response

type Response struct {
	Version string           `json:"jsonrpc"`
	ID      *json.RawMessage `json:"id"`
	Result  interface{}      `json:"result,omitempty"`
	Error   interface{}      `json:"error,omitempty"`
}

Response RPC 返回对象

type Result

type Result struct {
	Version string           `json:"jsonrpc"`
	ID      *json.RawMessage `json:"id"`
	Result  *json.RawMessage `json:"result,omitempty"`
	Error   *json.RawMessage `json:"error,omitempty"`
}

Result RPC 异步返回对象

type ResultCallbackFunc

type ResultCallbackFunc func(msg *Message, data interface{})

type XRequest

type XRequest struct {
	Version string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	ID      interface{} `json:"id"`
	Params  interface{} `json:"params"`
}

Request RPC 请求对象

Directories

Path Synopsis
Package nats provides a NATS Conn
Package nats provides a NATS Conn

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL