This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os" | |
"github.com/gin-gonic/gin" | |
) | |
var appID, appCertificate string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getBothTokens(c *gin.Context) { | |
log.Printf("dual token\n") | |
// get rtc param values | |
channelName, tokentype, uidStr, role, expireTimestamp, rtcParamErr := parseRtcParams(c) | |
if rtcParamErr != nil { | |
c.Error(rtcParamErr) | |
c.AbortWithStatusJSON(400, gin.H{ | |
"message": "Error Generating RTC token: " + rtcParamErr.Error(), | |
"status": 400, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func parseRtmParams(c *gin.Context) (uidStr string, expireTimestamp uint32, err error) { | |
// get param values | |
uidStr = c.Param("uid") | |
expireTime := c.DefaultQuery("expiry", "3600") | |
expireTime64, parseErr := strconv.ParseUint(expireTime, 10, 64) | |
if parseErr != nil { | |
// if string conversion fails return an error | |
err = fmt.Errorf("failed to parse expireTime: %s, causing error: %s", expireTime, parseErr) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getRtmToken(c *gin.Context) { | |
log.Printf("rtm token\n") | |
// get param values | |
uidStr, expireTimestamp, err := parseRtmParams(c) | |
if err != nil { | |
c.Error(err) | |
c.AbortWithStatusJSON(400, gin.H{ | |
"message": "Error Generating RTC token: " + err.Error(), | |
"status": 400, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func generateRtcToken(channelName, uidStr, tokentype string, role rtctokenbuilder.Role, expireTimestamp uint32) (rtcToken string, err error) { | |
if tokentype == "userAccount" { | |
log.Printf("Building Token with userAccount: %s\n", uidStr) | |
rtcToken, err = rtctokenbuilder.BuildTokenWithUserAccount(appID, appCertificate, channelName, uidStr, role, expireTimestamp) | |
return rtcToken, err | |
} else if tokentype == "uid" { | |
uid64, parseErr := strconv.ParseUint(uidStr, 10, 64) | |
// check if conversion fails |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func parseRtcParams(c *gin.Context) (channelName, tokentype, uidStr string, role rtctokenbuilder.Role, expireTimestamp uint32, err error) { | |
// get param values | |
channelName = c.Param("channelName") | |
roleStr := c.Param("role") | |
tokentype = c.Param("tokentype") | |
uidStr = c.Param("uid") | |
expireTime := c.DefaultQuery("expiry", "3600") | |
if roleStr == "publisher" { | |
role = rtctokenbuilder.RolePublisher |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getRtcToken(c *gin.Context) { | |
log.Printf("rtc token\n") | |
// get param values | |
channelName, tokentype, uidStr, role, expireTimestamp, err := parseRtcParams(c) | |
if err != nil { | |
c.Error(err) | |
c.AbortWithStatusJSON(400, gin.H{ | |
"message": "Error Generating RTC token: " + err.Error(), | |
"status": 400, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os" | |
"github.com/AgoraIO-Community/go-tokenbuilder/rtctokenbuilder" | |
"github.com/gin-gonic/gin" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/gin-gonic/gin" | |
) | |
func main() { | |
api := gin.Default() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get uid | |
let uid = req.query.uid; | |
if(!uid || uid == '') { | |
uid = 0; | |
} | |
// get role | |
let role = RtcRole.SUBSCRIBER; | |
if (req.query.role == 'publisher') { | |
role = RtcRole.PUBLISHER; | |
} |