websocket-based lrcproto server

export type on channel

Changed files
+40 -48
+22 -24
options.go
··· 8 lrcpb "github.com/rachel-mp4/lrcproto/gen/go" 9 ) 10 11 type options struct { 12 - uri string 13 - secret string 14 - welcome *string 15 - writer *io.Writer 16 - verbose bool 17 - pubChan chan PubEvent 18 - initChan chan struct { 19 - lrcpb.Event_Init 20 - *string 21 - } 22 - mediainitChan chan struct { 23 - lrcpb.Event_Mediainit 24 - *string 25 - } 26 - initialID *uint32 27 - resolver func(externalID string, ctx context.Context) *string 28 } 29 30 type Option func(option *options) error ··· 64 } 65 } 66 67 - func WithInitChannel(initChan chan struct { 68 - lrcpb.Event_Init 69 - *string 70 - }) Option { 71 return func(options *options) error { 72 if initChan == nil { 73 return errors.New("must provide a channel") ··· 77 } 78 } 79 80 - func WithMediainitChannel(mediainitChan chan struct { 81 - lrcpb.Event_Mediainit 82 - *string 83 - }) Option { 84 return func(options *options) error { 85 if mediainitChan == nil { 86 return errors.New("must provide a channel")
··· 8 lrcpb "github.com/rachel-mp4/lrcproto/gen/go" 9 ) 10 11 + type InitChanMsg struct { 12 + lrcpb.Event_Init 13 + *string 14 + } 15 + 16 + type MediaInitChanMsg struct { 17 + lrcpb.Event_Mediainit 18 + *string 19 + } 20 + 21 type options struct { 22 + uri string 23 + secret string 24 + welcome *string 25 + writer *io.Writer 26 + verbose bool 27 + pubChan chan PubEvent 28 + initChan chan InitChanMsg 29 + mediainitChan chan MediaInitChanMsg 30 + initialID *uint32 31 + resolver func(externalID string, ctx context.Context) *string 32 } 33 34 type Option func(option *options) error ··· 68 } 69 } 70 71 + func WithInitChannel(initChan chan InitChanMsg) Option { 72 return func(options *options) error { 73 if initChan == nil { 74 return errors.New("must provide a channel") ··· 78 } 79 } 80 81 + func WithMediainitChannel(mediainitChan chan MediaInitChanMsg) Option { 82 return func(options *options) error { 83 if mediainitChan == nil { 84 return errors.New("must provide a channel")
+18 -24
server.go
··· 16 ) 17 18 type Server struct { 19 - secret string 20 - uri string 21 - eventBus chan clientEvent 22 - ctx context.Context 23 - cancel context.CancelFunc 24 - clients map[*client]bool 25 - clientsMu sync.Mutex 26 - idmapsMu sync.Mutex 27 - idToClient map[uint32]*client 28 - lastID uint32 29 - logger *log.Logger 30 - debugLogger *log.Logger 31 - welcomeEvt []byte 32 - pongEvt []byte 33 - initChan chan struct { 34 - lrcpb.Event_Init 35 - *string 36 - } 37 - mediainitChan chan struct { 38 - lrcpb.Event_Mediainit 39 - *string 40 - } 41 - resolver func(externalID string, ctx context.Context) *string 42 - pubChan chan PubEvent 43 } 44 45 type PubEvent struct {
··· 16 ) 17 18 type Server struct { 19 + secret string 20 + uri string 21 + eventBus chan clientEvent 22 + ctx context.Context 23 + cancel context.CancelFunc 24 + clients map[*client]bool 25 + clientsMu sync.Mutex 26 + idmapsMu sync.Mutex 27 + idToClient map[uint32]*client 28 + lastID uint32 29 + logger *log.Logger 30 + debugLogger *log.Logger 31 + welcomeEvt []byte 32 + pongEvt []byte 33 + initChan chan InitChanMsg 34 + mediainitChan chan MediaInitChanMsg 35 + resolver func(externalID string, ctx context.Context) *string 36 + pubChan chan PubEvent 37 } 38 39 type PubEvent struct {