Commit a4c43c34 authored by hujiebin's avatar hujiebin

feat:动态初始化trtc房间

parent 4e497849
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"git.hilo.cn/hilo-common/utils" "git.hilo.cn/hilo-common/utils"
"github.com/bluele/gcache" "github.com/bluele/gcache"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause"
"hilo-group/_const/enum/group_e" "hilo-group/_const/enum/group_e"
"hilo-group/myerr" "hilo-group/myerr"
"hilo-group/myerr/bizerr" "hilo-group/myerr/bizerr"
...@@ -575,3 +576,17 @@ func IsUseTRTC(model *domain.Model, imGroupId string) bool { ...@@ -575,3 +576,17 @@ func IsUseTRTC(model *domain.Model, imGroupId string) bool {
} }
return count > 0 return count > 0
} }
type GroupTrtc struct {
mysql.Entity
ImGroupId mysql.Str
}
// 初始化trtc房间
func InitTRTC(model *domain.Model, imGroupId string) error {
if err := model.DB().Model(GroupTrtc{}).Clauses(clause.OnConflict{DoNothing: true}).Create(&GroupTrtc{ImGroupId: imGroupId}).Error; err != nil {
model.Log.Errorf("InitTRTC err:%v, groupId:%s", err, imGroupId)
return err
}
return nil
}
...@@ -1753,6 +1753,20 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -1753,6 +1753,20 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) {
provider := group_e.GroupProvider_SW provider := group_e.GroupProvider_SW
if group_m.IsUseTRTC(model, groupId) { if group_m.IsUseTRTC(model, groupId) {
provider = group_e.GroupProvider_TRTC
} else {
if time.Now().Unix() > 1683820800 { // todo 1683820800=5月2号,等过审再修改
roomUser, err := group_m.GetRoomOnlineUser(myContext, groupId)
if err == nil && roomUser.Total == 0 {
if err := group_m.InitTRTC(model, groupId); err != nil {
return myContext, err
}
provider = group_e.GroupProvider_TRTC
model.Log.Infof("auto shift trtc room groupId:%v,%+v-%v", groupId, roomUser, err)
}
}
}
if provider == group_e.GroupProvider_TRTC {
// 版本升级提示,旧版本(3.6.0以下),提示升级 // 版本升级提示,旧版本(3.6.0以下),提示升级
_, major, minor, _, err := req.GetAppVersion(c) _, major, minor, _, err := req.GetAppVersion(c)
if err != nil { if err != nil {
...@@ -1761,10 +1775,6 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -1761,10 +1775,6 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) {
if (major < 3) || (major == 3 && minor < 6) { if (major < 3) || (major == 3 && minor < 6) {
return myContext, bizerr.UpgradeRequired return myContext, bizerr.UpgradeRequired
} }
provider = group_e.GroupProvider_TRTC
} else {
roomUser, err := group_m.GetRoomOnlineUser(myContext, groupId)
model.Log.Infof("group_m.GetRoomOnlineUser %+v-%v", roomUser, err)
} }
if channelId, token, err := group_s.NewGroupService(myContext).GroupIn(userId, externalId, groupId, password, imei, ip, provider); err != nil { if channelId, token, err := group_s.NewGroupService(myContext).GroupIn(userId, externalId, groupId, password, imei, ip, provider); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment