gotchat

package module
v0.0.0-...-faae919 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2015 License: MIT Imports: 15 Imported by: 0

README

gotchat

A Golang chat package

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRoomNotFound = errors.New("room not found")

ErrRoomNotFound when room is not found or doesn't exists

Functions

func NormalizeNic

func NormalizeNic(nic string) string

NormalizeNic return a normalized version of nic cut to 10 char && tolower

Types

type Chat

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

Chat represents a chat

func NewChat

func NewChat(c Config) (chat *Chat, err error)

NewChat returm a new Chat

func (*Chat) AddRoom

func (c *Chat) AddRoom(name string, conf RoomConfig) (err error)

AddRoom add a new room

func (*Chat) GetRoom

func (c *Chat) GetRoom(name string) (room *Room, err error)

GetRoom return a pointer to Room named name

func (*Chat) RoomExists

func (c *Chat) RoomExists(name string) bool

RoomExists checks if room exists

func (*Chat) WebsocketHandler

func (c *Chat) WebsocketHandler(ws *websocket.Conn)

WebsocketHandler handle webssocket conn

type Config

type Config struct {
	// log
	Logger *log.Logger

	// debug
	Debug bool

	// data path for storing data (archives, DB files, template....)
	// default = appPath/data
	DataPath string
}

Config represents global configuration for chat

type Message

type Message struct {
	Action string `json:"action"`
	Txt    string `json:"txt"`
}

Message is the structure used for the dialog between websocket client and server

type Room

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

Room represents a romm

func (*Room) BeatReceivedFrom

func (r *Room) BeatReceivedFrom(nic string)

BeatReceivedFrom handle beat recived from subscriber

func (*Room) GetSubscriber

func (r *Room) GetSubscriber(nic string) (*subscriber, error)

GetSubscriber return subscriber... or not

func (*Room) HaveSubscriber

func (r *Room) HaveSubscriber(nic string) bool

HaveSubscriber check if nic is in chatroom

func (*Room) NewIncomingMessageFrom

func (r *Room) NewIncomingMessageFrom(nic, msg string) error

NewIncomingMessageFrom handle new message from nic

func (*Room) PushArchivesTo

func (r *Room) PushArchivesTo(nic string)

PushArchivesTo send archive to subscriber

func (*Room) PushMessage

func (r *Room) PushMessage(from, msg string) error

PushMessage push msg to all subscribers

func (*Room) PushMessageTo

func (r *Room) PushMessageTo(msg, nic string)

PushMessageTo send a message to nic

func (*Room) Sub

func (r *Room) Sub(nic string, ws *websocket.Conn) error

Sub add nic to chatroom

func (*Room) Unsub

func (r *Room) Unsub(nic string)

Unsub unsubscribe nic from chatroom

func (*Room) Watch

func (r *Room) Watch()

Watch checks if subscribers are always here normaly useless if you do not use proxy

type RoomConfig

type RoomConfig struct {
	// do we have to archive this room
	// Default: false
	Archived bool
	// number of archived Messages server will push to new subscriber
	// Default 0
	ArchivePushMessagesCount uint16
	// if server do not recieve beat from sunscriber after this 2*delay (in sec)
	// subscriber will be unsub
	// Default 0
	HeartRate uint16
}

RoomConfig is used to configure a new room

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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