Ejemplo n.º 1
0
func (app *appContext) timeStream(c *gin.Context) {
	recv := app.timeGroup.Join()
	defer recv.Close()
	c.Stream(func(w io.Writer) bool {
		c.SSEvent("message", recv.Recv().(string))
		return true
	})
}
Ejemplo n.º 2
0
func stream(c *gin.Context) {
	roomid := c.Param("roomid")
	listener := openListener(roomid)
	defer closeListener(roomid, listener)

	c.Stream(func(w io.Writer) bool {
		c.SSEvent("message", <-listener)
		return true
	})
}
Ejemplo n.º 3
0
func stream(ctx *gin.Context) {

	ticker := time.NewTicker(500 * time.Millisecond)
	defer func() {
		ticker.Stop()
	}()

	ctx.Stream(func(w io.Writer) bool {
		select {
		case tm := <-ticker.C:

			ctx.SSEvent("", tm)

		}
		return true
	})
}
func streamRoom(c *gin.Context) {
	roomid := c.Param("roomid")
	listener := openListener(roomid)
	ticker := time.NewTicker(1 * time.Second)
	users.Add("connected", 1)
	defer func() {
		closeListener(roomid, listener)
		ticker.Stop()
		users.Add("disconnected", 1)
	}()

	c.Stream(func(w io.Writer) bool {
		select {
		case msg := <-listener:
			messages.Add("outbound", 1)
			c.SSEvent("message", msg)
		case <-ticker.C:
			c.SSEvent("stats", Stats())
		}
		return true
	})
}