Skip to content

weaming/hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hub

  • The global Hub has many Topics.
  • Every Topichas many subscribers and publisher, they are websocket connections.
  • One websocket connection will receive/publish messages from/to other subscribers.
  • Hub will publish Message to Topic.
  • Topic will send Message to all subscribers under it.
    • One subscriber maybe receive same messge for more than one times.
  • Every subscriber will subscribe the "global" Topic.

Core structures

const GlobalTopicID = "global"

// types of internal messages
const (
	MTPlain      string = "PLAIN"
	MTMarkdown   string = "MARKDOWN"
	MTMarkdownV2 string = "MARKDOWNV2"
	MTJSON       string = "JSON"
	MTHTML       string = "HTML"
	MTPhoto      string = "PHOTO"
	MTVideo      string = "VIDEO"
)

// types of websocket messages
const (
	MTFeedback string = "FEEDBACK" // used for async event feedback
	MTResponse string = "RESPONSE" // used for message response
	MTMessage  string = "MESSAGE"  // used for publish messages
)

type RawMessage struct {
	Type    string `json:"type"`    // required
	Data    string `json:"data"`    // required, string or base64 of bytes
	Caption string `json:"caption"` // optional
}

// http client message
type PubMessage struct {
	Type         string        `json:"type"`          // required
	Data         string        `json:"data"`          // required, string or base64 of bytes
	Caption      string        `json:"caption"`       // required
	ExtendedData []RawMessage  `json:"extended_data"` // optional, string or base64 of bytes, for sending multiple photos
}