...
 
Commits (15)
......@@ -156,3 +156,11 @@ var GROUP_NOBLE4_JOIN_LIMIT uint = 1000
var GROUP_ROLE_PERSONAL_VIEW_LIMIT = 5
var GROUP_MANAGER_LIMIT uint = 30
var GROUP_ADMIN_LIMIT uint = 50
type GroupProvider = uint8
const (
// 群组声音供应商
GroupProvider_SW GroupProvider = 0 // 声网
GroupProvider_TRTC GroupProvider = 1 // 腾讯trtc
)
......@@ -221,6 +221,7 @@ type GroupChannelId struct {
Token string `json:"token"`
AgoraId uint32 `json:"agoraId"`
MicNumType uint8 `json:"micNumType"`
Provider uint8 `json:"provider"` // 供应商 1.声网 2.腾讯trtc
}
//国籍视图
......
......@@ -72,6 +72,9 @@ APP_CERTIFICATE=ff29c100a613433db82324e8411eabc8
CUSTOMER_KEY=6b132c0ff7164560a2bc53fda06ea85a
CUSTOMER_SECRET=eedad2cd16d24834990d5450ace9f1ce
CALLBACK_SECRET=n_ZizS_N8
[TRTC]
APP_ID=1400548270
APP_CERTIFICATE=321bd60f73096b059c7350f1cd97d51028850b34fa58c5c0d26bb4a19e783de8
[CHECKOUT]
AUTHORIZATION=sk_test_9b5e771c-5a3f-4a8d-a4da-31b19bd43d83
URL=https://api.sandbox.checkout.com/hosted-payments
......
......@@ -7,6 +7,7 @@ import (
"git.hilo.cn/hilo-common/utils"
"github.com/bluele/gcache"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"hilo-group/_const/enum/group_e"
"hilo-group/myerr"
"hilo-group/myerr/bizerr"
......@@ -566,3 +567,26 @@ func GetFamilyRooms(model *domain.Model, familyId uint64, pageSize, pageIndex in
return res, nextIdx, hasNext, nil
}
func IsUseTRTC(model *domain.Model, imGroupId string) bool {
var count int64
if err := model.DB().Table("group_trtc").Where("im_group_id=?", imGroupId).Count(&count).Error; err != nil {
model.Log.Errorf("IsUseTRTC err:%v, groupId:%s", err, imGroupId)
return false
}
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
}
......@@ -6,11 +6,13 @@ import (
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/rpc"
"git.hilo.cn/hilo-common/sdk/agora"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"git.hilo.cn/hilo-common/sdk/trtc"
"git.hilo.cn/hilo-common/utils"
"gorm.io/gorm"
"hilo-group/_const/enum/group_e"
......@@ -115,7 +117,7 @@ func (s *GroupService) LeaveGroupMember(model *domain.Model, groupId string, use
}
//进入房间, 返回channelId, err
func (s *GroupService) GroupIn(userId uint64, externalId string, groupUuid string, password, imei, ip string) (string, string, error) {
func (s *GroupService) GroupIn(userId uint64, externalId string, groupUuid string, password, imei, ip string, provider group_e.GroupProvider) (string, string, error) {
var channelId string
var token string
err := s.svc.Transactional(func() error {
......@@ -171,7 +173,13 @@ func (s *GroupService) GroupIn(userId uint64, externalId string, groupUuid strin
if err != nil {
return err
}
if provider == group_e.GroupProvider_TRTC {
channelId = groupInfo.ChannelId
token = trtc.CreateGroupTRTCUserSig(userId, config.GetTRTCConfig())
model.Log.Infof("enter trtc group userId:%v, groupId:%v", userId, groupUuid)
} else {
channelId, token, err = agora.CreateGroupAgora(groupInfo.ChannelId, uint32(userId))
}
if err != nil {
return err
} else {
......
......@@ -72,6 +72,9 @@ APP_CERTIFICATE=ff29c100a613433db82324e8411eabc8
CUSTOMER_KEY=6b132c0ff7164560a2bc53fda06ea85a
CUSTOMER_SECRET=eedad2cd16d24834990d5450ace9f1ce
CALLBACK_SECRET=n_ZizS_N8
[TRTC]
APP_ID=1400548270
APP_CERTIFICATE=321bd60f73096b059c7350f1cd97d51028850b34fa58c5c0d26bb4a19e783de8
[CHECKOUT]
AUTHORIZATION=sk_test_9b5e771c-5a3f-4a8d-a4da-31b19bd43d83
URL=https://api.sandbox.checkout.com/hosted-payments
......
-CREATE TABLE `group_trtc` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`im_group_id` char(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `im_group_id` (`im_group_id`),
KEY `created_time` (`created_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='使用trtc的群组';
\ No newline at end of file
......@@ -72,6 +72,9 @@ APP_ID=6291d069123642d9929a49c734c50719
APP_CERTIFICATE=d5de40350aa54e60bcdce90c71e9598a
CUSTOMER_KEY=6b132c0ff7164560a2bc53fda06ea85a
CUSTOMER_SECRET=eedad2cd16d24834990d5450ace9f1ce
[TRTC]
APP_ID=40000066
APP_CERTIFICATE=3ab68ea5bddc8774d90b8c764ae71188914bd5fd06f30b28790c51e44ca7885c
[CHECKOUT]
AUTHORIZATION=sk_fca6e213-b7df-4bd7-99f4-7c0a9f7c778c
URL=https://api.checkout.com/hosted-payments
......
......@@ -1751,7 +1751,33 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) {
}
model.Log.Infof("GroupIn ip userId:%v,imGroupId:%v,ip:%v,imei:%v", userId, groupId, ip, imei)
if channelId, token, err := group_s.NewGroupService(myContext).GroupIn(userId, externalId, groupId, password, imei, ip); err != nil {
provider := group_e.GroupProvider_SW
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以下),提示升级
_, major, minor, _, err := req.GetAppVersion(c)
if err != nil {
return myContext, err
}
if (major < 3) || (major == 3 && minor < 6) {
return myContext, bizerr.UpgradeRequired
}
}
if channelId, token, err := group_s.NewGroupService(myContext).GroupIn(userId, externalId, groupId, password, imei, ip, provider); err != nil {
return myContext, err
} else {
// 加入房间缓存
......@@ -1767,6 +1793,7 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) {
Token: token,
AgoraId: uint32(userId),
MicNumType: gi.MicNumType,
Provider: provider,
})
// v2.26及以后,客户端自己加TIM群,不再由服务器代加
......
package test
import (
"fmt"
"git.hilo.cn/hilo-common/domain"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m"
"testing"
)
func TestGetAllGroupPowerOwner(t *testing.T) {
owners, err := groupPower_m.BatchGetAllGroupPowerUsers(domain.CreateModelNil())
owners, _, err := groupPower_m.BatchGetAllGroupPowerUsers(domain.CreateModelNil(), 1, 1)
println(owners, err)
}
func TestGetGroupPowerMonthStartTop1(t *testing.T) {
res, err := groupPower_m.GetGroupPowerMonthStartTop1(domain.CreateModelNil(), 250)
println(res,err)
println(res, err)
}
func TestIsUseTRTC(t *testing.T) {
if group_m.IsUseTRTC(domain.CreateModelNil(), "@TGS#3I57DMRIB") {
fmt.Println("true--------------")
}
}