socket

package
v0.0.0-...-785b97d Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultWriteBufferSize = 10
View Source
const UpdatesBatchSize = 50

Variables

View Source
var Session *session

Functions

func InitAck

func InitAck()

func Initialize

func Initialize(ctx context.Context, eg *errgroup.Group, fn func(name string), opts ...InitOption)

func NewClient

func NewClient(conn IConn, option *ClientOption, event IEvent) error

Types

type AckBuffer

type AckBuffer struct {
	TimeWheel *timeutil.SimpleTimeWheel[*AckBufferContent]
}

func (*AckBuffer) Start

func (a *AckBuffer) Start(ctx context.Context) error

type AckBufferContent

type AckBufferContent struct {
	Cid      int64
	Uid      int64
	Channel  string
	Response *accountpb.UpdateResponse
}

type Channel

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

func NewChannel

func NewChannel(name string, outChan chan *SenderContent, updatesRepository IUpdatesRepository) *Channel

func (*Channel) Client

func (c *Channel) Client(cid int64) (*Client, bool)

func (*Channel) Count

func (c *Channel) Count() int64

func (*Channel) Name

func (c *Channel) Name() string

func (*Channel) Start

func (c *Channel) Start(ctx context.Context) error

func (*Channel) Write

func (c *Channel) Write(data *SenderContent)

type Client

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

func (*Client) Channel

func (c *Client) Channel() IChannel

func (*Client) Cid

func (c *Client) Cid() int64

func (*Client) Close

func (c *Client) Close(code int, message string)

func (*Client) Closed

func (c *Client) Closed() bool

func (*Client) Uid

func (c *Client) Uid() int

func (*Client) Write

func (c *Client) Write(data *accountpb.UpdateResponse) error

type ClientOption

type ClientOption struct {
	Uid         int
	Channel     IChannel
	Storage     IStorage
	IDGenerator IDGenerator
	Buffer      int
}

type CloseEvent

type CloseEvent func(client IClient, code int, text string)

type DestroyEvent

type DestroyEvent func(client IClient)

type Event

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

func (*Event) Close

func (e *Event) Close(client IClient, code int, text string)

func (*Event) Destroy

func (e *Event) Destroy(client IClient)

func (*Event) Message

func (e *Event) Message(client IClient, data []byte)

func (*Event) Open

func (e *Event) Open(client IClient)

type EventOption

type EventOption func(event *Event)

func WithCloseEvent

func WithCloseEvent(e CloseEvent) EventOption

func WithDestroyEvent

func WithDestroyEvent(e DestroyEvent) EventOption

func WithMessageEvent

func WithMessageEvent(e MessageEvent) EventOption

func WithOpenEvent

func WithOpenEvent(e OpenEvent) EventOption

type GRPCStreamAdapter

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

func (*GRPCStreamAdapter) Close

func (g *GRPCStreamAdapter) Close() error

func (*GRPCStreamAdapter) Read

func (g *GRPCStreamAdapter) Read() ([]byte, error)

func (*GRPCStreamAdapter) SetCloseHandler

func (g *GRPCStreamAdapter) SetCloseHandler(fn func(code int, text string) error)

func (*GRPCStreamAdapter) Write

func (g *GRPCStreamAdapter) Write(data []byte) error

type IChannel

type IChannel interface {
	Name() string

	Count() int64

	Client(cid int64) (*Client, bool)

	Write(data *SenderContent)
	// contains filtered or unexported methods
}

type IClient

type IClient interface {
	Cid() int64

	Uid() int

	Close(code int, text string)

	Write(data *accountpb.UpdateResponse) error

	Channel() IChannel
}

type IConn

type IConn interface {
	Read() ([]byte, error)

	Write([]byte) error

	Close() error

	SetCloseHandler(fn func(code int, text string) error)
}

type IDGenerator

type IDGenerator interface {
	ID() int64
}

type IEvent

type IEvent interface {
	Open(client IClient)

	Message(client IClient, data []byte)

	Close(client IClient, code int, text string)

	Destroy(client IClient)
}

func NewEvent

func NewEvent(opts ...EventOption) IEvent

type IStorage

type IStorage interface {
	Bind(ctx context.Context, channel string, cid int64, uid int) error

	UnBind(ctx context.Context, channel string, cid int64) error
}

type IUpdatesRepository

type IUpdatesRepository interface {
	Append(ctx context.Context, uid int, updates []*accountpb.Update) (pts, date int64, err error)

	GetSince(ctx context.Context, uid int, sincePts int64) ([]StoredUpdate, error)
}

type InitOption

type InitOption func(*initOptions)

func WithUpdatesRepository

func WithUpdatesRepository(store IUpdatesRepository) InitOption

type MessageEvent

type MessageEvent func(client IClient, data []byte)

type OpenEvent

type OpenEvent func(client IClient)

type SenderContent

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

func NewSenderContent

func NewSenderContent() *SenderContent

func (*SenderContent) Build

func (*SenderContent) BuildWithState

func (s *SenderContent) BuildWithState(pts, date int64) *accountpb.UpdateResponse

func (*SenderContent) IsBroadcast

func (s *SenderContent) IsBroadcast() bool

func (*SenderContent) IsEphemeral

func (s *SenderContent) IsEphemeral() bool

func (*SenderContent) PersistUserIDs

func (s *SenderContent) PersistUserIDs() []int

func (*SenderContent) SetAck

func (s *SenderContent) SetAck(value bool) *SenderContent

func (*SenderContent) SetBroadcast

func (s *SenderContent) SetBroadcast(value bool) *SenderContent

func (*SenderContent) SetExclude

func (s *SenderContent) SetExclude(cid ...int64) *SenderContent

func (*SenderContent) SetPersistUserIDs

func (s *SenderContent) SetPersistUserIDs(uids ...int) *SenderContent

func (*SenderContent) SetReceive

func (s *SenderContent) SetReceive(cid ...int64) *SenderContent

func (*SenderContent) SetUpdateMessageDeleted

func (s *SenderContent) SetUpdateMessageDeleted(update *accountpb.Update_MessageDeleted) *SenderContent

func (*SenderContent) SetUpdateMessageReaction

func (s *SenderContent) SetUpdateMessageReaction(update *accountpb.Update_MessageReaction) *SenderContent

func (*SenderContent) SetUpdateMessageRead

func (s *SenderContent) SetUpdateMessageRead(update *accountpb.Update_MessageRead) *SenderContent

func (*SenderContent) SetUpdateNewMessage

func (s *SenderContent) SetUpdateNewMessage(update *accountpb.Update_NewMessage) *SenderContent

func (*SenderContent) SetUpdateRunnerEnabled

func (s *SenderContent) SetUpdateRunnerEnabled(update *accountpb.Update_RunnerEnabled) *SenderContent

func (*SenderContent) SetUpdateUserStatus

func (s *SenderContent) SetUpdateUserStatus(update *accountpb.Update_UserStatus) *SenderContent

func (*SenderContent) SetUpdateUserTyping

func (s *SenderContent) SetUpdateUserTyping(update *accountpb.Update_UserTyping) *SenderContent

type SnowflakeGenerator

type SnowflakeGenerator struct {
	Node *snowflake.Node
}

func (*SnowflakeGenerator) ID

func (g *SnowflakeGenerator) ID() int64

type StoredUpdate

type StoredUpdate struct {
	Pts     int64
	Date    int64
	Updates []*accountpb.Update
}

Jump to

Keyboard shortcuts

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