ctrl

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 22 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 异步调用,Depracated

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 EnableTenancy added in v1.2.3

func EnableTenancy()

func ForkDTMFEventToChannelEventThread

func ForkDTMFEventToChannelEventThread() error

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

func GetChannelState

func GetChannelState(uuid string) string

GetChannelState 获取 channel 状态

func GetNATSConn added in v1.1.19

func GetNATSConn() *natsio.Conn

func GetNodeList

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

func GetTenancyTopicAddress added in v1.2.3

func GetTenancyTopicAddress(userPrefix string, topic string) string

func GetTenancyTopicAndUser added in v1.2.3

func GetTenancyTopicAndUser(rawTopic string) (user string, topic string)

func GetTenantID added in v1.2.0

func GetTenantID(subject string) string

func GetTenantId added in v1.1.20

func GetTenantId(subject string) string

deprecated over GetTenantID

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 OnEvicted added in v1.1.18

func OnEvicted(f func(string, interface{}))

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 RegisterHashNodeWithTenancyFun added in v1.2.3

func RegisterHashNodeWithTenancyFun(nodeCallbackFunc NodeHashWithTenacyFun)

func Respond

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

Respond 响应NATS Request 请求

func Service

func Service() xctrl.XNodeService

Service 同步调用

func SetFromPrefix added in v1.1.20

func SetFromPrefix(prefix string)

func SetLogLevel

func SetLogLevel(level LogLevel)

func SetLogger

func SetLogger(l Logger)

func SetMaxChannelLifeTime added in v1.1.14

func SetMaxChannelLifeTime(time uint)

func SetToPrefix added in v1.1.20

func SetToPrefix(prefix string)

func Subscribe

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

func TenantNodeAddress added in v1.2.1

func TenantNodeAddress(tenant string, nodeUUID string) string

TenantNodeAddress Get tenant node add string

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 WithAsync added in v1.1.11

func WithAsync() client.CallOption

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) client.CallOption

NATS Request Timeout

func WithTenantAddress added in v1.1.20

func WithTenantAddress(tenant string, nodeUUID string) client.CallOption

WithTenantAddress 创建租户对应的Node地址

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 NewChannelEventWithPrefix added in v1.1.20

func NewChannelEventWithPrefix(prefix string) *Channel

func ReadChannel

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

ReadChannel get channel

func ReadChannelByInstance added in v1.1.20

func ReadChannelByInstance(c *Ctrl, uuid string) (*Channel, error)

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) GetTenantID added in v1.1.20

func (channel *Channel) GetTenantID() string

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 NewCtrlInstance added in v1.1.20

func NewCtrlInstance(trace bool, addrs string) (*Ctrl, error)

func (*Ctrl) AService added in v1.1.20

func (c *Ctrl) AService() xctrl.XNodeService

func (*Ctrl) AsyncService added in v1.1.20

func (c *Ctrl) AsyncService() xctrl.XNodeService

AsyncService 异步调用,Depracated

func (*Ctrl) CManService added in v1.1.20

func (c *Ctrl) CManService() cman.CManService

CManService 同步调用

func (*Ctrl) Call added in v1.1.20

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

Call 发起 request 请求

func (*Ctrl) CtrlStartUp added in v1.1.20

func (c *Ctrl) CtrlStartUp(req *xctrl.CtrlStartUpRequest) error

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) GetInstanceName added in v1.1.20

func (c *Ctrl) GetInstanceName() string

func (*Ctrl) GetNATSConn added in v1.1.20

func (c *Ctrl) GetNATSConn() *natsio.Conn

func (*Ctrl) GetNodeList added in v1.1.20

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

func (*Ctrl) GetTenancyTopicAddress added in v1.2.3

func (c *Ctrl) GetTenancyTopicAddress(userPrefix string, topic string) string

func (*Ctrl) GetTenancyTopicAndUser added in v1.2.3

func (c *Ctrl) GetTenancyTopicAndUser(rawTopic string) (user string, topic string)

func (*Ctrl) GetTenantID added in v1.2.0

func (c *Ctrl) GetTenantID(subject string) string

func (*Ctrl) GetTenantId added in v1.1.20

func (c *Ctrl) GetTenantId(subject string) string

func (*Ctrl) NewCManService

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

NewCManService 创建 CManService

func (*Ctrl) OnEvicted added in v1.1.18

func (h *Ctrl) OnEvicted(f func(string, interface{}))

func (*Ctrl) Publish added in v1.1.20

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

Publish 发送消息

func (*Ctrl) PublishJSON added in v1.1.20

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

PublishJSON 发送JSON消息

func (*Ctrl) Respond added in v1.1.20

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

Respond 响应NATS Request 请求

func (*Ctrl) Service added in v1.1.20

func (c *Ctrl) Service() xctrl.XNodeService

Service 同步调用

func (*Ctrl) SetFromPrefix added in v1.1.20

func (c *Ctrl) SetFromPrefix(prefix string)

func (*Ctrl) SetInstanceName added in v1.1.20

func (c *Ctrl) SetInstanceName(instanceName string)

func (*Ctrl) SetMaxChannelLifeTime added in v1.1.20

func (c *Ctrl) SetMaxChannelLifeTime(time uint)

func (*Ctrl) SetTenancyStatus added in v1.2.3

func (c *Ctrl) SetTenancyStatus(status bool)

func (*Ctrl) SetToPrefix added in v1.1.20

func (c *Ctrl) SetToPrefix(prefix string)

func (*Ctrl) Subscribe

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

订阅消息

func (*Ctrl) TenantNodeAddress added in v1.2.1

func (c *Ctrl) TenantNodeAddress(tenant string, nodeUUID string) string

func (*Ctrl) Transfer added in v1.1.20

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

func (*Ctrl) UUID added in v1.1.20

func (c *Ctrl) UUID() string

UUID get ctrl uuid

func (*Ctrl) WithTenantAddress added in v1.1.20

func (c *Ctrl) WithTenantAddress(tenant string, nodeUUID string) client.CallOption

func (*Ctrl) XCall added in v1.1.20

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

XCall 发起 request 请求

type CtrlNodes added in v1.1.20

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

func InitCtrlNodes added in v1.1.20

func InitCtrlNodes() CtrlNodes

func (*CtrlNodes) Delete added in v1.1.20

func (c *CtrlNodes) Delete(hostname string)

Delete 删除节点信息

func (*CtrlNodes) GetNodeList added in v1.1.20

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

func (*CtrlNodes) Hostname added in v1.1.20

func (c *CtrlNodes) Hostname(uuid string) string

func (*CtrlNodes) Node added in v1.1.20

func (c *CtrlNodes) Node(hostname string) *xctrl.Node

Node 根据 hostname 获取 node 节点信息

func (*CtrlNodes) Store added in v1.1.20

func (c *CtrlNodes) Store(hostname string, node *xctrl.Node)

Store 保存节点信息

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 NodeHashWithTenacyFun added in v1.2.3

type NodeHashWithTenacyFun func(node *xctrl.Node, method string, tenancy 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