streaming

package
v0.0.0-...-d22cea1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Subscribe   ActionType = 1
	UnSubscribe ActionType = 2

	Message ResourceType = 1
	Moment  ResourceType = 2
)
View Source
const SEP = "[:bot-ws-sub-key:]"

SEP 起名字特殊一点,防止 botId 包含 SEP

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType int32

type Config

type Config struct {
	Host string
	Port string

	Chathubs    []string
	ChatWebGrpc string

	Mongo utils.MongoConfig
	Oss   utils.OssConfig

	WebBaseUrl string

	ClientId   string
	ClientType string
}

type ErrorHandler

type ErrorHandler struct {
	domains.ErrorHandler
}

type GetBotUnreadMessagesParams

type GetBotUnreadMessagesParams struct {
	BotId         string `json:"botId"`
	PeerId        string `json:"peerId"`
	FromMessageId string `json:"fromMessageId"`
}

type GetConversationMessagesParams

type GetConversationMessagesParams struct {
	BotId  string `json:"botId"`
	PeerId string `json:"peerId"`

	Direction     string `json:"direction"`     // new, old
	FromMessageId string `json:"fromMessageId"` // 以 fromMessageId 为界限获取消息。direction 为 old 必填;new 选填,空则返回最新一页数据,非空则可表示短信重连后获取更新数据
}

type ResourceType

type ResourceType int32

type SendImageMessageParams

type SendImageMessageParams struct {
	ToUserName string `json:"toUserName"`
	Payload    string `json:"payload"`
}

type SendMessage

type SendMessage struct {
	BotLogin string      `json:"botLogin"`
	Type     string      `json:"type"`
	Params   interface{} `json:"params"`
}

type SendTextMessageParams

type SendTextMessageParams struct {
	ToUserName string   `json:"toUserName"`
	Content    string   `json:"content"`
	AtList     []string `json:"atList"`
}

type Server

type Server struct {
	*logger.Logger

	Config Config
	// contains filtered or unexported fields
}

func (*Server) BotAndWsConnectionsSubKey

func (server *Server) BotAndWsConnectionsSubKey(botId string, resourceType int32) string

func (*Server) CreateWsConnection

func (server *Server) CreateWsConnection(wsConnection *websocket.Conn, token string, user *utils.AuthUser) *WsConnection

func (*Server) GetSubscribedConnections

func (server *Server) GetSubscribedConnections(botId string, resourceType int32) []*WsConnection

func (*Server) NewHubGRPCWrapper

func (server *Server) NewHubGRPCWrapper() (*rpc.GRPCWrapper, error)

func (*Server) NewWebGRPCWrapper

func (server *Server) NewWebGRPCWrapper() (*rpc.GRPCWrapper, error)

func (*Server) RecoverConnectionSubs

func (server *Server) RecoverConnectionSubs()

func (*Server) RemoveSubsForConnection

func (server *Server) RemoveSubsForConnection(wsConnection *WsConnection) error

func (*Server) Serve

func (server *Server) Serve() error

func (*Server) ServeWebsocketServer

func (server *Server) ServeWebsocketServer() error

func (*Server) StartHubClient

func (server *Server) StartHubClient()

func (*Server) UpdateConnectionSubs

func (server *Server) UpdateConnectionSubs(wsConnection *WsConnection, resources []*pb.StreamingResource) error

type WsConnection

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

func (*WsConnection) Close

func (wsConnection *WsConnection) Close() error

func (*WsConnection) CreateRequest

func (wsConnection *WsConnection) CreateRequest(eventType string, payload interface{}) *WsEvent

func (*WsConnection) On

func (wsConnection *WsConnection) On(eventName string, eventHandler WsEventEventHandlerFunc)

func (*WsConnection) Send

func (wsConnection *WsConnection) Send(event *WsEvent)

func (*WsConnection) SendHubBotAction

func (wsConnection *WsConnection) SendHubBotAction(botLogin string, actionType string, actionBody string) (*httpx.RestfulResponse, error)

func (*WsConnection) SendWithAck

func (wsConnection *WsConnection) SendWithAck(event *WsEvent, ack WsEventAckFunc)

type WsEvent

type WsEvent struct {
	Seq     int64 `json:"seq,omitempty"`
	Ack     int64 `json:"ack,omitempty"`
	NeedAck bool  `json:"needAck,omitempty"`

	EventType string      `json:"eventType,omitempty"`
	Payload   interface{} `json:"payload,omitempty"`

	Error *WsEventError `json:"error,omitempty"`
}

func (*WsEvent) CreateErrorResponse

func (wsEvent *WsEvent) CreateErrorResponse(code int64, message string) *WsEvent

func (*WsEvent) CreateResponse

func (wsEvent *WsEvent) CreateResponse(payload interface{}) *WsEvent

type WsEventAckFunc

type WsEventAckFunc = func(payload interface{}, err error)

type WsEventAckWrapper

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

type WsEventError

type WsEventError struct {
	Code    int64  `json:"code"`
	Message string `json:"message"`
}

func (*WsEventError) Error

func (error *WsEventError) Error() string

type WsEventEventHandlerFunc

type WsEventEventHandlerFunc = func(payload interface{}) (interface{}, error)

Jump to

Keyboard shortcuts

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