Documentation ¶
Index ¶
- func CreateChannel(port int, channelName string, channelType string, userName string, ...) error
- type Channel
- type ChatChannel
- func (c *ChatChannel) AddPeer(peerID string, peerName string, p2pAddrs []string) error
- func (c *ChatChannel) GetPeers() []string
- func (c *ChatChannel) Leave()
- func (c *ChatChannel) On(event string, handler func(c *ChatChannel, data interface{})) error
- func (c *ChatChannel) Send(content interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Channel ¶
type Channel interface { // will send message to all members of the channel Send(data []byte) error // will leave the current channel(can not receive message anymore) Leave() // will assign handlers to NewMessage, NewPeer, PeerJoin, PeerLeave On(event string, handler func(data interface{})) error // add a peer to my peer list AddPeer(addr string) error // get current peers name list in the channel GetPeers() []string }
Channel is a persistent pubsub channel(have to link to a local db)
type ChatChannel ¶
type ChatChannel struct {
// contains filtered or unexported fields
}
ChatChannel is a persistent pubsub chat channel
func OpenChannel ¶
func OpenChannel( ctx context.Context, channelName string, channelType string, host host.Host, p *pubsub.PubSub, db *storm.DB, ) (*ChatChannel, error)
OpenChannel create a new channel
func (*ChatChannel) AddPeer ¶
func (c *ChatChannel) AddPeer(peerID string, peerName string, p2pAddrs []string) error
AddPeer add a peer to the channel
func (*ChatChannel) GetPeers ¶
func (c *ChatChannel) GetPeers() []string
GetPeers get current peers peer ids in the channel
func (*ChatChannel) Leave ¶
func (c *ChatChannel) Leave()
Leave will leave the current channel(can not receive message anymore)
func (*ChatChannel) On ¶
func (c *ChatChannel) On(event string, handler func(c *ChatChannel, data interface{})) error
On will assign handlers to NewMessage, Sync, NewPeer, PeerJoin, PeerConnected, PeerLeave, UserLeave
func (*ChatChannel) Send ¶
func (c *ChatChannel) Send(content interface{}) error
Send will send message to all members of the channel
Click to show internal directories.
Click to hide internal directories.