channel

package
v0.0.0-...-31b6265 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateChannel

func CreateChannel(
	port int,
	channelName string,
	channelType string,
	userName string,
	protector string,
	db *storm.DB,
) error

CreateChannel create a new c to use

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

Jump to

Keyboard shortcuts

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