You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/msg_gateway/gate/open_im_media/room.go

68 lines
1.6 KiB

package open_im_media
3 years ago
import (
pbRtc "Open_IM/pkg/proto/rtc"
3 years ago
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
3 years ago
"context"
"errors"
3 years ago
"github.com/jinzhu/copier"
3 years ago
"google.golang.org/grpc"
)
const (
3 years ago
// Address gRPC服务地址
Address = "127.0.0.1:11300"
)
3 years ago
//var roomClient *lksdk.RoomServiceClient
type Media struct {
}
func NewMedia() *Media {
3 years ago
return &Media{}
}
3 years ago
3 years ago
func (m *Media) GetJoinToken(room, identity string, operationID string, data *open_im_sdk.ParticipantMetaData) (string, string, error) {
var newData pbRtc.ParticipantMetaData
copier.Copy(&newData, data)
3 years ago
conn, err := grpc.Dial(Address, grpc.WithInsecure())
if err != nil {
3 years ago
return "", "", err
3 years ago
}
defer conn.Close()
c := pbRtc.NewRtcServiceClient(conn)
3 years ago
req := &pbRtc.GetJoinTokenReq{Room: room, OperationID: operationID, Identity: identity, MetaData: &newData}
3 years ago
resp, err := c.GetJoinToken(context.Background(), req)
if err != nil {
3 years ago
return "", "", err
3 years ago
}
if resp.CommonResp.ErrCode != 0 {
3 years ago
return "", "", errors.New(resp.CommonResp.ErrMsg)
3 years ago
}
3 years ago
return resp.Jwt, resp.LiveURL, nil
3 years ago
//at := auth.NewAccessToken(m.ApiKey, m.ApiSecret)
//grant := &auth.VideoGrant{
// RoomJoin: true,
// Room: room,
//}
//at.AddGrant(grant).
// SetIdentity(identity).
// SetValidFor(time.Hour)
//
//return at.ToJWT()
}
func init() {
3 years ago
//roomClient = lksdk.NewRoomServiceClient(MediaAddress, ApiKey, ApiSecret)
}
3 years ago
func (m *Media) CreateRoom(roomName string) (error, error) {
3 years ago
return nil, nil
//return roomClient.CreateRoom(context.Background(), &livekit.CreateRoomRequest{
// Name: roomName,
// EmptyTimeout: 60 * 3,
//})
}