Documentation ¶
Index ¶
- Constants
- Variables
- type BatchNotification
- type Connection
- type HideEvent
- type IncomingEvent
- type MessageEvent
- type Notification
- type NotifyHub
- func (hub *NotifyHub) HasRecord(userUuid string) (bool, error)
- func (hub *NotifyHub) Hide(hideEvent *HideEvent) error
- func (hub *NotifyHub) HideNotification(notification *HideEvent) error
- func (hub *NotifyHub) LookUpAndSend(userUuid string)
- func (hub *NotifyHub) OpenSocket(ctx context.Context, w http.ResponseWriter, r *http.Request, uuid, orgn string) error
- func (hub *NotifyHub) PersistInitRecord(conn *Connection) error
- func (hub *NotifyHub) Remove(removeEvent *RemoveEvent) error
- func (hub *NotifyHub) SaveEvent(userUuid string, event *IncomingEvent)
- func (hub *NotifyHub) Stop()
- type OrganizationPool
- func (pool *OrganizationPool) Add(newConn *Connection) error
- func (pool *OrganizationPool) Broadcast(msg *IncomingEvent) error
- func (pool *OrganizationPool) BroadcastOnline(msg *IncomingEvent) error
- func (pool *OrganizationPool) Find(uuid string) *Connection
- func (pool *OrganizationPool) Length() int
- func (pool *OrganizationPool) Remove(delConn *Connection) error
- func (pool *OrganizationPool) Send(receiver string, msg *IncomingEvent) error
- func (pool *OrganizationPool) SendBatch(receiver string, msgs BatchNotification) error
- type RemoveEvent
- type UserNotifications
- type VueMutation
Constants ¶
const ( // indicates that a user has been invited to join an App EventAppInvite MessageEvent = iota // indicated that a user has been reminded to join an app EventAppInviteReminder // indicates that the App has changed and can be synced EventSyncApp EventIsOnline EventIsOffline // MutationAppInvite maps to the corresponding Vue function // when the client socket receives a new message MutationAppInvite VueMutation = "APP_INVITE" MutationLoadFromDB VueMutation = "INIT_LOAD" MutationIsOnline VueMutation = "IS_ONLINE" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type BatchNotification ¶
type BatchNotification struct { Mutation VueMutation `json:"mutation"` Messages []Notification `json:"notifications"` }
type Connection ¶
func (*Connection) Health ¶
func (conn *Connection) Health(hub *NotifyHub)
Health checks periodically if the connection is still alive if not conn signals to hub that connection can be removed since the client should never send any messages Health will block at conn.ReadMessage which will interrupt if the connection breaks
type IncomingEvent ¶
type IncomingEvent struct { UserUuid string `json:"receiver_uuid"` Organization string `json:"receiver_orgn"` Timestamp int64 `json:"timestamp"` Mutation VueMutation `json:"mutation"` Event MessageEvent `json:"event"` Value map[string]interface{} `json:"value"` }
type MessageEvent ¶
type MessageEvent int
type Notification ¶
type Notification struct { Hidden bool `bson:"hidden"` Timestamp int64 `json:"timestamp"` Mutation VueMutation `json:"mutation" bson:"mutation"` Event MessageEvent `json:"event" bson:"event"` Value map[string]interface{} `json:"value" bson:"value"` }
Message represents a message as it will be streamed to the client socket
type NotifyHub ¶
type NotifyHub struct { Notify chan *IncomingEvent RemoveNotify chan *RemoveEvent HideNotify chan *HideEvent // key is the organization name the client registered with Organizations map[string]*OrganizationPool // contains filtered or unexported fields }
func (*NotifyHub) HideNotification ¶
func (*NotifyHub) LookUpAndSend ¶
LookUpAndSend looks up all stored notifications of a given user and sends them to the hub.Notify channel
func (*NotifyHub) OpenSocket ¶
func (*NotifyHub) PersistInitRecord ¶
func (hub *NotifyHub) PersistInitRecord(conn *Connection) error
PersistInitRecord stores an empty UserNotification if the user dose not yet hold a record in the database
func (*NotifyHub) Remove ¶
func (hub *NotifyHub) Remove(removeEvent *RemoveEvent) error
Remove removes one notification form a user notification array
func (*NotifyHub) SaveEvent ¶
func (hub *NotifyHub) SaveEvent(userUuid string, event *IncomingEvent)
type OrganizationPool ¶
type OrganizationPool []*Connection
func (*OrganizationPool) Add ¶
func (pool *OrganizationPool) Add(newConn *Connection) error
Add adds a new connection to its pool if the connection dose not already exists
func (*OrganizationPool) Broadcast ¶
func (pool *OrganizationPool) Broadcast(msg *IncomingEvent) error
func (*OrganizationPool) BroadcastOnline ¶
func (pool *OrganizationPool) BroadcastOnline(msg *IncomingEvent) error
func (*OrganizationPool) Find ¶
func (pool *OrganizationPool) Find(uuid string) *Connection
func (*OrganizationPool) Length ¶
func (pool *OrganizationPool) Length() int
func (*OrganizationPool) Remove ¶
func (pool *OrganizationPool) Remove(delConn *Connection) error
Remove removes a connection form its pool
func (*OrganizationPool) Send ¶
func (pool *OrganizationPool) Send(receiver string, msg *IncomingEvent) error
Send iterate over the pool and sends the message to the connection which uuid matches with the receiver ones. If not receiver is found Send returns an ErrNoRecevierFound
func (*OrganizationPool) SendBatch ¶
func (pool *OrganizationPool) SendBatch(receiver string, msgs BatchNotification) error
type RemoveEvent ¶
type UserNotifications ¶
type UserNotifications struct { UserUuid string `bson:"_id"` Organization string `bson:"organization"` Notifications []Notification `bson:"notifications"` }
Notification represents one notification as it will be stored in the database. Each user will have its own information with a slice of messages
type VueMutation ¶
type VueMutation string
VueMutation represents the actual function names on the vuejs client side. The "mutation" in a message will trigger the function on the client side