|
|
|
@ -1,12 +1,7 @@
|
|
|
|
|
package open_im_media
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"github.com/livekit/protocol/livekit"
|
|
|
|
|
lksdk "github.com/livekit/server-sdk-go"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/livekit/protocol/auth"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
@ -15,7 +10,7 @@ const (
|
|
|
|
|
ApiSecret = "23ztfSqsfQ8hKkHzHTl3Z4bvaxro0snjk5jwbp5p6Q3"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var roomClient *lksdk.RoomServiceClient
|
|
|
|
|
//var roomClient *lksdk.RoomServiceClient
|
|
|
|
|
|
|
|
|
|
type Media struct {
|
|
|
|
|
MediaAddress string
|
|
|
|
@ -32,26 +27,28 @@ func (m *Media) GetUrl() string {
|
|
|
|
|
return m.MediaAddress
|
|
|
|
|
}
|
|
|
|
|
func (m *Media) GetJoinToken(room, identity string) (string, error) {
|
|
|
|
|
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()
|
|
|
|
|
return identity, nil
|
|
|
|
|
//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() {
|
|
|
|
|
roomClient = lksdk.NewRoomServiceClient(MediaAddress, ApiKey, ApiSecret)
|
|
|
|
|
//roomClient = lksdk.NewRoomServiceClient(MediaAddress, ApiKey, ApiSecret)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Media) CreateRoom(roomName string) (*livekit.Room, error) {
|
|
|
|
|
return roomClient.CreateRoom(context.Background(), &livekit.CreateRoomRequest{
|
|
|
|
|
Name: roomName,
|
|
|
|
|
EmptyTimeout: 60 * 3,
|
|
|
|
|
})
|
|
|
|
|
return nil, nil
|
|
|
|
|
//return roomClient.CreateRoom(context.Background(), &livekit.CreateRoomRequest{
|
|
|
|
|
// Name: roomName,
|
|
|
|
|
// EmptyTimeout: 60 * 3,
|
|
|
|
|
//})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|