twitchapon

[Twi]tch [Cha]nnel [Po]ints Rewards Redemption Listener
git clone git://bsandro.tech/twitchapon
Log | Files | Refs | README | LICENSE

listen.go (673B)


      1 package main
      2 
      3 import (
      4 	"fmt"
      5 	"golang.org/x/net/websocket"
      6 )
      7 
      8 type TListenRequest struct {
      9 	MsgType string `json:"type"`
     10 	// Nonce string `json:"nonce"` // optional
     11 	Data struct {
     12 		Topics    []string `json:"topics"`
     13 		AuthToken string   `json:"auth_token"`
     14 	} `json:"data"`
     15 }
     16 
     17 func OnListen(auth_token string, user_id string) interface{} {
     18 	var req TListenRequest
     19 	req.MsgType = "LISTEN"
     20 	req.Data.AuthToken = auth_token
     21 	req.Data.Topics = append(req.Data.Topics, fmt.Sprintf("channel-points-channel-v1.%s", user_id))
     22 	return &req
     23 }
     24 
     25 func RequestListen() error {
     26 	msg := OnListen(App.Auth.AccessToken, App.User.Id)
     27 	websocket.JSON.Send(App.Connection, msg)
     28 	return nil
     29 }