This commit is contained in:
wangchuxiao
2022-03-16 14:59:15 +08:00
parent fb815c0be0
commit fa21ae6161
3 changed files with 187 additions and 296 deletions
+10 -3
View File
@@ -1,10 +1,12 @@
package rtc
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
pbRtc "Open_IM/pkg/proto/rtc"
"Open_IM/pkg/utils"
"context"
"encoding/json"
"time"
"github.com/livekit/protocol/auth"
@@ -12,7 +14,6 @@ import (
)
type RtcService struct {
}
func (r *RtcService) GetJoinToken(_ context.Context, req *pbRtc.GetJoinTokenReq) (resp *pbRtc.GetJoinTokenResp, err error) {
@@ -27,11 +28,17 @@ func (r *RtcService) GetJoinToken(_ context.Context, req *pbRtc.GetJoinTokenReq)
CanPublish: &canPublish,
CanSubscribe: &canSubscribe,
}
byte, err := json.Marshal(req.MetaData)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "json marshal failed", err.Error())
resp.CommonResp = &pbRtc.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}
return
}
at.AddGrant(grant).
SetIdentity(req.Identity).
// optional
SetName("participant-name").
SetValidFor(time.Hour)
SetValidFor(time.Hour).SetMetadata(string(byte))
jwt, err := at.ToJWT()
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "toJwt failed", err.Error(), "jwt: ", jwt)
@@ -40,4 +47,4 @@ func (r *RtcService) GetJoinToken(_ context.Context, req *pbRtc.GetJoinTokenReq)
resp.CommonResp = &pbRtc.CommonResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, err
}
}