liveroom

package
v0.0.0-...-551f129 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

README

liveroom

Liveroom 是一个“可靠的消息通道”的示例。它包含一个简单实现的聊天室服务。

Overview 概要设计

Liveroom 是一个无状态的服务。它依赖下面这些基础组件,

  • redis 里存储房间的消息列表,房间的在线列表
  • nats 用来订阅和通知房间消息有更新

值得注意的一点是,一个房间的在线列表,是所有最近有收取该房间消息的用户。当用户进入聊天室的时候,我们更新这个列表;当用户收取消息的时候,同样也要更新这个列表。

用户进入聊天室之后,就开始收取消息。为了让用户实时同步到新消息,收取消息的 API 采用 long-polling 机制。用户的收取行为,也可以看作是用户的心跳。

RecvUser long polling

简单起见,上图里的接入层、业务logicsvr、RecvSvr都在 Liveroom 里实现。“接入层”的处理在 Room.Recv handler,它向 redis 查询是否有新消息,这个查询请求可以重放。如果没有消息,将执行 SubscribeSync AutoUnsubscribe(1) NextMsg(time.Minute) 等待通知。上图里的 RoomX Waiting Queue 由 nats 提供。

房间的消息列表,由用户在房间里的行为所产生。这里的“消息”是一个广泛的概念,包括但不限于“进入”“退出”“发送文字”等等。

SendUser

Reference 参考

Documentation

Index

Constants

View Source
const (
	ServiceName = "liveroom"
)

Variables

View Source
var RoomMessage_Type_name = map[int32]string{
	0: "UNSPECIFIED",
	1: "ENTER_ROOM",
	2: "LEAVE_ROOM",
	3: "PLAIN_TEXT",
}
View Source
var RoomMessage_Type_value = map[string]int32{
	"UNSPECIFIED": 0,
	"ENTER_ROOM":  1,
	"LEAVE_ROOM":  2,
	"PLAIN_TEXT":  3,
}

Functions

func NewDemoEndpoints

func NewDemoEndpoints() []*api.Endpoint

func NewRoomEndpoints

func NewRoomEndpoints() []*api.Endpoint

func RegisterDemoHandler

func RegisterDemoHandler(s server.Server, hdlr DemoHandler, opts ...server.HandlerOption) error

func RegisterRoomHandler

func RegisterRoomHandler(s server.Server, hdlr RoomHandler, opts ...server.HandlerOption) error

Types

type Demo

type Demo struct{}

func (*Demo) Hello

func (d *Demo) Hello(ctx context.Context, req *HelloReq, res *HelloRes) error

type DemoHandler

type DemoHandler interface {
	Hello(context.Context, *HelloReq, *HelloRes) error
}

type DemoService

type DemoService interface {
	Hello(ctx context.Context, in *HelloReq, opts ...client.CallOption) (*HelloRes, error)
}

func NewDemoService

func NewDemoService(name string, c client.Client) DemoService

type EnterReq

type EnterReq struct {
	Room                 string        `protobuf:"bytes,1,opt,name=room,proto3" json:"room,omitempty"`
	Info                 *MsgEnterRoom `protobuf:"bytes,2,opt,name=info,proto3" json:"info,omitempty"`
	XXX_NoUnkeyedLiteral struct{}      `json:"-"`
	XXX_unrecognized     []byte        `json:"-"`
	XXX_sizecache        int32         `json:"-"`
}

func (*EnterReq) Descriptor

func (*EnterReq) Descriptor() ([]byte, []int)

func (*EnterReq) GetInfo

func (m *EnterReq) GetInfo() *MsgEnterRoom

func (*EnterReq) GetRoom

func (m *EnterReq) GetRoom() string

func (*EnterReq) ProtoMessage

func (*EnterReq) ProtoMessage()

func (*EnterReq) Reset

func (m *EnterReq) Reset()

func (*EnterReq) String

func (m *EnterReq) String() string

func (*EnterReq) XXX_DiscardUnknown

func (m *EnterReq) XXX_DiscardUnknown()

func (*EnterReq) XXX_Marshal

func (m *EnterReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*EnterReq) XXX_Merge

func (m *EnterReq) XXX_Merge(src proto.Message)

func (*EnterReq) XXX_Size

func (m *EnterReq) XXX_Size() int

func (*EnterReq) XXX_Unmarshal

func (m *EnterReq) XXX_Unmarshal(b []byte) error

type EnterRes

type EnterRes struct {
	Uids                 []string `protobuf:"bytes,1,rep,name=uids,proto3" json:"uids,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*EnterRes) Descriptor

func (*EnterRes) Descriptor() ([]byte, []int)

func (*EnterRes) GetUids

func (m *EnterRes) GetUids() []string

func (*EnterRes) ProtoMessage

func (*EnterRes) ProtoMessage()

func (*EnterRes) Reset

func (m *EnterRes) Reset()

func (*EnterRes) String

func (m *EnterRes) String() string

func (*EnterRes) XXX_DiscardUnknown

func (m *EnterRes) XXX_DiscardUnknown()

func (*EnterRes) XXX_Marshal

func (m *EnterRes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*EnterRes) XXX_Merge

func (m *EnterRes) XXX_Merge(src proto.Message)

func (*EnterRes) XXX_Size

func (m *EnterRes) XXX_Size() int

func (*EnterRes) XXX_Unmarshal

func (m *EnterRes) XXX_Unmarshal(b []byte) error

type HelloReq

type HelloReq struct {
	Say                  string   `protobuf:"bytes,1,opt,name=say,proto3" json:"say,omitempty"`
	Sleep                int32    `protobuf:"varint,2,opt,name=sleep,proto3" json:"sleep,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*HelloReq) Descriptor

func (*HelloReq) Descriptor() ([]byte, []int)

func (*HelloReq) GetSay

func (m *HelloReq) GetSay() string

func (*HelloReq) GetSleep

func (m *HelloReq) GetSleep() int32

func (*HelloReq) ProtoMessage

func (*HelloReq) ProtoMessage()

func (*HelloReq) Reset

func (m *HelloReq) Reset()

func (*HelloReq) String

func (m *HelloReq) String() string

func (*HelloReq) XXX_DiscardUnknown

func (m *HelloReq) XXX_DiscardUnknown()

func (*HelloReq) XXX_Marshal

func (m *HelloReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HelloReq) XXX_Merge

func (m *HelloReq) XXX_Merge(src proto.Message)

func (*HelloReq) XXX_Size

func (m *HelloReq) XXX_Size() int

func (*HelloReq) XXX_Unmarshal

func (m *HelloReq) XXX_Unmarshal(b []byte) error

type HelloRes

type HelloRes struct {
	Ack                  string   `protobuf:"bytes,1,opt,name=ack,proto3" json:"ack,omitempty"`
	Account              []*KV    `protobuf:"bytes,2,rep,name=account,proto3" json:"account,omitempty"`
	Time                 float32  `protobuf:"fixed32,3,opt,name=time,proto3" json:"time,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*HelloRes) Descriptor

func (*HelloRes) Descriptor() ([]byte, []int)

func (*HelloRes) GetAccount

func (m *HelloRes) GetAccount() []*KV

func (*HelloRes) GetAck

func (m *HelloRes) GetAck() string

func (*HelloRes) GetTime

func (m *HelloRes) GetTime() float32

func (*HelloRes) ProtoMessage

func (*HelloRes) ProtoMessage()

func (*HelloRes) Reset

func (m *HelloRes) Reset()

func (*HelloRes) String

func (m *HelloRes) String() string

func (*HelloRes) XXX_DiscardUnknown

func (m *HelloRes) XXX_DiscardUnknown()

func (*HelloRes) XXX_Marshal

func (m *HelloRes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HelloRes) XXX_Merge

func (m *HelloRes) XXX_Merge(src proto.Message)

func (*HelloRes) XXX_Size

func (m *HelloRes) XXX_Size() int

func (*HelloRes) XXX_Unmarshal

func (m *HelloRes) XXX_Unmarshal(b []byte) error

type KV

type KV struct {
	Key                  string   `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value                string   `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*KV) Descriptor

func (*KV) Descriptor() ([]byte, []int)

func (*KV) GetKey

func (m *KV) GetKey() string

func (*KV) GetValue

func (m *KV) GetValue() string

func (*KV) ProtoMessage

func (*KV) ProtoMessage()

func (*KV) Reset

func (m *KV) Reset()

func (*KV) String

func (m *KV) String() string

func (*KV) XXX_DiscardUnknown

func (m *KV) XXX_DiscardUnknown()

func (*KV) XXX_Marshal

func (m *KV) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*KV) XXX_Merge

func (m *KV) XXX_Merge(src proto.Message)

func (*KV) XXX_Size

func (m *KV) XXX_Size() int

func (*KV) XXX_Unmarshal

func (m *KV) XXX_Unmarshal(b []byte) error

type LeaveReq

type LeaveReq struct {
	Room                 string   `protobuf:"bytes,1,opt,name=room,proto3" json:"room,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*LeaveReq) Descriptor

func (*LeaveReq) Descriptor() ([]byte, []int)

func (*LeaveReq) GetRoom

func (m *LeaveReq) GetRoom() string

func (*LeaveReq) ProtoMessage

func (*LeaveReq) ProtoMessage()

func (*LeaveReq) Reset

func (m *LeaveReq) Reset()

func (*LeaveReq) String

func (m *LeaveReq) String() string

func (*LeaveReq) XXX_DiscardUnknown

func (m *LeaveReq) XXX_DiscardUnknown()

func (*LeaveReq) XXX_Marshal

func (m *LeaveReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*LeaveReq) XXX_Merge

func (m *LeaveReq) XXX_Merge(src proto.Message)

func (*LeaveReq) XXX_Size

func (m *LeaveReq) XXX_Size() int

func (*LeaveReq) XXX_Unmarshal

func (m *LeaveReq) XXX_Unmarshal(b []byte) error

type LeaveRes

type LeaveRes struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*LeaveRes) Descriptor

func (*LeaveRes) Descriptor() ([]byte, []int)

func (*LeaveRes) ProtoMessage

func (*LeaveRes) ProtoMessage()

func (*LeaveRes) Reset

func (m *LeaveRes) Reset()

func (*LeaveRes) String

func (m *LeaveRes) String() string

func (*LeaveRes) XXX_DiscardUnknown

func (m *LeaveRes) XXX_DiscardUnknown()

func (*LeaveRes) XXX_Marshal

func (m *LeaveRes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*LeaveRes) XXX_Merge

func (m *LeaveRes) XXX_Merge(src proto.Message)

func (*LeaveRes) XXX_Size

func (m *LeaveRes) XXX_Size() int

func (*LeaveRes) XXX_Unmarshal

func (m *LeaveRes) XXX_Unmarshal(b []byte) error

type MsgEnterRoom

type MsgEnterRoom struct {
	Name                 string   `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Agent                string   `protobuf:"bytes,2,opt,name=agent,proto3" json:"agent,omitempty"`
	Avatar               string   `protobuf:"bytes,3,opt,name=avatar,proto3" json:"avatar,omitempty"`
	Ipaddr               string   `protobuf:"bytes,4,opt,name=ipaddr,proto3" json:"ipaddr,omitempty"`
	Location             string   `protobuf:"bytes,5,opt,name=location,proto3" json:"location,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

进入聊天室

func (*MsgEnterRoom) Descriptor

func (*MsgEnterRoom) Descriptor() ([]byte, []int)

func (*MsgEnterRoom) GetAgent

func (m *MsgEnterRoom) GetAgent() string

func (*MsgEnterRoom) GetAvatar

func (m *MsgEnterRoom) GetAvatar() string

func (*MsgEnterRoom) GetIpaddr

func (m *MsgEnterRoom) GetIpaddr() string

func (*MsgEnterRoom) GetLocation

func (m *MsgEnterRoom) GetLocation() string

func (*MsgEnterRoom) GetName

func (m *MsgEnterRoom) GetName() string

func (*MsgEnterRoom) ProtoMessage

func (*MsgEnterRoom) ProtoMessage()

func (*MsgEnterRoom) Reset

func (m *MsgEnterRoom) Reset()

func (*MsgEnterRoom) String

func (m *MsgEnterRoom) String() string

func (*MsgEnterRoom) XXX_DiscardUnknown

func (m *MsgEnterRoom) XXX_DiscardUnknown()

func (*MsgEnterRoom) XXX_Marshal

func (m *MsgEnterRoom) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MsgEnterRoom) XXX_Merge

func (m *MsgEnterRoom) XXX_Merge(src proto.Message)

func (*MsgEnterRoom) XXX_Size

func (m *MsgEnterRoom) XXX_Size() int

func (*MsgEnterRoom) XXX_Unmarshal

func (m *MsgEnterRoom) XXX_Unmarshal(b []byte) error

type MsgLeaveRoom

type MsgLeaveRoom struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

退出聊天室

func (*MsgLeaveRoom) Descriptor

func (*MsgLeaveRoom) Descriptor() ([]byte, []int)

func (*MsgLeaveRoom) ProtoMessage

func (*MsgLeaveRoom) ProtoMessage()

func (*MsgLeaveRoom) Reset

func (m *MsgLeaveRoom) Reset()

func (*MsgLeaveRoom) String

func (m *MsgLeaveRoom) String() string

func (*MsgLeaveRoom) XXX_DiscardUnknown

func (m *MsgLeaveRoom) XXX_DiscardUnknown()

func (*MsgLeaveRoom) XXX_Marshal

func (m *MsgLeaveRoom) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MsgLeaveRoom) XXX_Merge

func (m *MsgLeaveRoom) XXX_Merge(src proto.Message)

func (*MsgLeaveRoom) XXX_Size

func (m *MsgLeaveRoom) XXX_Size() int

func (*MsgLeaveRoom) XXX_Unmarshal

func (m *MsgLeaveRoom) XXX_Unmarshal(b []byte) error

type MsgPlainText

type MsgPlainText struct {
	Text                 string   `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

聊天室文本消息

func (*MsgPlainText) Descriptor

func (*MsgPlainText) Descriptor() ([]byte, []int)

func (*MsgPlainText) GetText

func (m *MsgPlainText) GetText() string

func (*MsgPlainText) ProtoMessage

func (*MsgPlainText) ProtoMessage()

func (*MsgPlainText) Reset

func (m *MsgPlainText) Reset()

func (*MsgPlainText) String

func (m *MsgPlainText) String() string

func (*MsgPlainText) XXX_DiscardUnknown

func (m *MsgPlainText) XXX_DiscardUnknown()

func (*MsgPlainText) XXX_Marshal

func (m *MsgPlainText) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MsgPlainText) XXX_Merge

func (m *MsgPlainText) XXX_Merge(src proto.Message)

func (*MsgPlainText) XXX_Size

func (m *MsgPlainText) XXX_Size() int

func (*MsgPlainText) XXX_Unmarshal

func (m *MsgPlainText) XXX_Unmarshal(b []byte) error

type RecvReq

type RecvReq struct {
	// 聊天室ID
	Room string `protobuf:"bytes,1,opt,name=room,proto3" json:"room,omitempty"`
	// 客户端记住的已经收取到的最后一条消息的序列号
	LastSeq uint64 `protobuf:"varint,2,opt,name=last_seq,json=lastSeq,proto3" json:"last_seq,omitempty"`
	// 是否从最新的消息开始接收。这个选项只在客户端首次收取消息,也就是last_seq=0时,有效。
	// 为了防止漏掉消息,客户端下次收取必须从前一次收取到的消息的last_seq开始。
	OffsetNewest         bool     `protobuf:"varint,3,opt,name=offset_newest,json=offsetNewest,proto3" json:"offset_newest,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*RecvReq) Descriptor

func (*RecvReq) Descriptor() ([]byte, []int)

func (*RecvReq) GetLastSeq

func (m *RecvReq) GetLastSeq() uint64

func (*RecvReq) GetOffsetNewest

func (m *RecvReq) GetOffsetNewest() bool

func (*RecvReq) GetRoom

func (m *RecvReq) GetRoom() string

func (*RecvReq) ProtoMessage

func (*RecvReq) ProtoMessage()

func (*RecvReq) Reset

func (m *RecvReq) Reset()

func (*RecvReq) String

func (m *RecvReq) String() string

func (*RecvReq) XXX_DiscardUnknown

func (m *RecvReq) XXX_DiscardUnknown()

func (*RecvReq) XXX_Marshal

func (m *RecvReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RecvReq) XXX_Merge

func (m *RecvReq) XXX_Merge(src proto.Message)

func (*RecvReq) XXX_Size

func (m *RecvReq) XXX_Size() int

func (*RecvReq) XXX_Unmarshal

func (m *RecvReq) XXX_Unmarshal(b []byte) error

type RecvRes

type RecvRes struct {
	// 本次收取的所有未读消息,按seq排序,最小的seq必须比last_seq大
	Msgs                 []*RoomMessage `protobuf:"bytes,1,rep,name=msgs,proto3" json:"msgs,omitempty"`
	XXX_NoUnkeyedLiteral struct{}       `json:"-"`
	XXX_unrecognized     []byte         `json:"-"`
	XXX_sizecache        int32          `json:"-"`
}

func (*RecvRes) Descriptor

func (*RecvRes) Descriptor() ([]byte, []int)

func (*RecvRes) GetMsgs

func (m *RecvRes) GetMsgs() []*RoomMessage

func (*RecvRes) ProtoMessage

func (*RecvRes) ProtoMessage()

func (*RecvRes) Reset

func (m *RecvRes) Reset()

func (*RecvRes) String

func (m *RecvRes) String() string

func (*RecvRes) XXX_DiscardUnknown

func (m *RecvRes) XXX_DiscardUnknown()

func (*RecvRes) XXX_Marshal

func (m *RecvRes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RecvRes) XXX_Merge

func (m *RecvRes) XXX_Merge(src proto.Message)

func (*RecvRes) XXX_Size

func (m *RecvRes) XXX_Size() int

func (*RecvRes) XXX_Unmarshal

func (m *RecvRes) XXX_Unmarshal(b []byte) error

type Room

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

func (*Room) Enter

func (r *Room) Enter(ctx context.Context, req *EnterReq, res *EnterRes) error

func (*Room) Init

func (r *Room) Init()

func (*Room) Leave

func (r *Room) Leave(ctx context.Context, req *LeaveReq, res *LeaveRes) error

func (*Room) Recv

func (r *Room) Recv(ctx context.Context, req *RecvReq, res *RecvRes) error

func (*Room) Send

func (r *Room) Send(ctx context.Context, req *SendReq, res *SendRes) error

type RoomHandler

type RoomHandler interface {
	// 进入聊天室
	Enter(context.Context, *EnterReq, *EnterRes) error
	// 在聊天室里,发送消息
	Send(context.Context, *SendReq, *SendRes) error
	// 收取聊天室里的未读消息。
	// 这是一个 long-polling 机制的方法,需要指定 `Request-Timeout` 头,
	// 表示当聊天室里没有未读消息时,轮询多少秒。当聊天室里有未读消息时,立刻返回。
	Recv(context.Context, *RecvReq, *RecvRes) error
	// 退出聊天室
	Leave(context.Context, *LeaveReq, *LeaveRes) error
}

type RoomMessage

type RoomMessage struct {
	// // 聊天室ID
	Room string `protobuf:"bytes,1,opt,name=room,proto3" json:"room,omitempty"`
	// 聊天室里的每条消息都有唯一的seq,新消息的seq总是更大
	Seq uint64 `protobuf:"varint,2,opt,name=seq,proto3" json:"seq,omitempty"`
	// 消息类型
	Type RoomMessage_Type `protobuf:"varint,3,opt,name=type,proto3,enum=liveroom.RoomMessage_Type" json:"type,omitempty"`
	// 谁发出的消息
	Uid string `protobuf:"bytes,4,opt,name=uid,proto3" json:"uid,omitempty"`
	// 何时发出的消息(毫秒时间戳)
	SendAt int64 `protobuf:"varint,5,opt,name=send_at,json=sendAt,proto3" json:"send_at,omitempty"`
	// 具体消息对象,与消息类型对应
	EnterRoom            *MsgEnterRoom `protobuf:"bytes,6,opt,name=enter_room,json=enterRoom,proto3" json:"enter_room,omitempty"`
	LeaveRoom            *MsgLeaveRoom `protobuf:"bytes,7,opt,name=leave_room,json=leaveRoom,proto3" json:"leave_room,omitempty"`
	PlainText            *MsgPlainText `protobuf:"bytes,8,opt,name=plain_text,json=plainText,proto3" json:"plain_text,omitempty"`
	XXX_NoUnkeyedLiteral struct{}      `json:"-"`
	XXX_unrecognized     []byte        `json:"-"`
	XXX_sizecache        int32         `json:"-"`
}

聊天室消息

func (*RoomMessage) Descriptor

func (*RoomMessage) Descriptor() ([]byte, []int)

func (*RoomMessage) GetEnterRoom

func (m *RoomMessage) GetEnterRoom() *MsgEnterRoom

func (*RoomMessage) GetLeaveRoom

func (m *RoomMessage) GetLeaveRoom() *MsgLeaveRoom

func (*RoomMessage) GetPlainText

func (m *RoomMessage) GetPlainText() *MsgPlainText

func (*RoomMessage) GetRoom

func (m *RoomMessage) GetRoom() string

func (*RoomMessage) GetSendAt

func (m *RoomMessage) GetSendAt() int64

func (*RoomMessage) GetSeq

func (m *RoomMessage) GetSeq() uint64

func (*RoomMessage) GetType

func (m *RoomMessage) GetType() RoomMessage_Type

func (*RoomMessage) GetUid

func (m *RoomMessage) GetUid() string

func (*RoomMessage) ProtoMessage

func (*RoomMessage) ProtoMessage()

func (*RoomMessage) Reset

func (m *RoomMessage) Reset()

func (*RoomMessage) String

func (m *RoomMessage) String() string

func (*RoomMessage) XXX_DiscardUnknown

func (m *RoomMessage) XXX_DiscardUnknown()

func (*RoomMessage) XXX_Marshal

func (m *RoomMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RoomMessage) XXX_Merge

func (m *RoomMessage) XXX_Merge(src proto.Message)

func (*RoomMessage) XXX_Size

func (m *RoomMessage) XXX_Size() int

func (*RoomMessage) XXX_Unmarshal

func (m *RoomMessage) XXX_Unmarshal(b []byte) error

type RoomMessage_Type

type RoomMessage_Type int32

消息类型

const (
	RoomMessage_UNSPECIFIED RoomMessage_Type = 0
	RoomMessage_ENTER_ROOM  RoomMessage_Type = 1
	RoomMessage_LEAVE_ROOM  RoomMessage_Type = 2
	RoomMessage_PLAIN_TEXT  RoomMessage_Type = 3
)

func (RoomMessage_Type) EnumDescriptor

func (RoomMessage_Type) EnumDescriptor() ([]byte, []int)

func (RoomMessage_Type) String

func (x RoomMessage_Type) String() string

type RoomService

type RoomService interface {
	// 进入聊天室
	Enter(ctx context.Context, in *EnterReq, opts ...client.CallOption) (*EnterRes, error)
	// 在聊天室里,发送消息
	Send(ctx context.Context, in *SendReq, opts ...client.CallOption) (*SendRes, error)
	// 收取聊天室里的未读消息。
	// 这是一个 long-polling 机制的方法,需要指定 `Request-Timeout` 头,
	// 表示当聊天室里没有未读消息时,轮询多少秒。当聊天室里有未读消息时,立刻返回。
	Recv(ctx context.Context, in *RecvReq, opts ...client.CallOption) (*RecvRes, error)
	// 退出聊天室
	Leave(ctx context.Context, in *LeaveReq, opts ...client.CallOption) (*LeaveRes, error)
}

func NewRoomService

func NewRoomService(name string, c client.Client) RoomService

type SendReq

type SendReq struct {
	Room                 string   `protobuf:"bytes,1,opt,name=room,proto3" json:"room,omitempty"`
	Text                 string   `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*SendReq) Descriptor

func (*SendReq) Descriptor() ([]byte, []int)

func (*SendReq) GetRoom

func (m *SendReq) GetRoom() string

func (*SendReq) GetText

func (m *SendReq) GetText() string

func (*SendReq) ProtoMessage

func (*SendReq) ProtoMessage()

func (*SendReq) Reset

func (m *SendReq) Reset()

func (*SendReq) String

func (m *SendReq) String() string

func (*SendReq) XXX_DiscardUnknown

func (m *SendReq) XXX_DiscardUnknown()

func (*SendReq) XXX_Marshal

func (m *SendReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SendReq) XXX_Merge

func (m *SendReq) XXX_Merge(src proto.Message)

func (*SendReq) XXX_Size

func (m *SendReq) XXX_Size() int

func (*SendReq) XXX_Unmarshal

func (m *SendReq) XXX_Unmarshal(b []byte) error

type SendRes

type SendRes struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*SendRes) Descriptor

func (*SendRes) Descriptor() ([]byte, []int)

func (*SendRes) ProtoMessage

func (*SendRes) ProtoMessage()

func (*SendRes) Reset

func (m *SendRes) Reset()

func (*SendRes) String

func (m *SendRes) String() string

func (*SendRes) XXX_DiscardUnknown

func (m *SendRes) XXX_DiscardUnknown()

func (*SendRes) XXX_Marshal

func (m *SendRes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SendRes) XXX_Merge

func (m *SendRes) XXX_Merge(src proto.Message)

func (*SendRes) XXX_Size

func (m *SendRes) XXX_Size() int

func (*SendRes) XXX_Unmarshal

func (m *SendRes) XXX_Unmarshal(b []byte) error

type Server

type Server struct {
	Namespace          string   `json:"namespace"`
	Production         bool     `json:"production"`
	LogOutputPaths     []string `json:"logging_output_paths"`
	RedisServerAddress string   `json:"redis_server_address"`
	NatsServerAddress  string   `json:"nats_server_address"`
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) Name

func (s *Server) Name() string

func (*Server) Run

func (s *Server) Run()

Jump to

Keyboard shortcuts

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