Merge remote-tracking branch 'origin/tuoyun' into tuoyun

pull/218/head
Gordon 3 years ago
commit ca9ac35eb5

@ -0,0 +1,43 @@
package rtc
import (
"Open_IM/pkg/common/log"
pbRtc "Open_IM/pkg/proto/rtc"
"Open_IM/pkg/utils"
"context"
"time"
"github.com/livekit/protocol/auth"
//lksdk "github.com/livekit/server-sdk-go"
)
type RtcService struct {
}
func (r *RtcService) GetJoinToken(_ context.Context, req *pbRtc.GetJoinTokenReq) (resp *pbRtc.GetJoinTokenResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbRtc.GetJoinTokenResp{}
canPublish := true
canSubscribe := true
at := auth.NewAccessToken(req.ApiKey, req.ApiSecret)
grant := &auth.VideoGrant{
RoomJoin: true,
Room: req.Room,
CanPublish: &canPublish,
CanSubscribe: &canSubscribe,
}
at.AddGrant(grant).
SetIdentity(req.Identity).
// optional
SetName("participant-name").
SetValidFor(time.Hour)
jwt, err := at.ToJWT()
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "toJwt failed", err.Error(), "jwt: ", jwt)
}
resp.Jwt = jwt
resp.CommonResp = &pbRtc.CommonResp{}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, err
}

@ -17,10 +17,8 @@ type CommonCallbackReq struct {
}
type CommonCallbackResp struct {
ActionCode int `json:"actionCode"`
ErrCode int `json:"errCode"`
ErrMsg string `json:"errMsg"`
ActionCode int `json:"actionCode"`
ErrCode int `json:"errCode"`
ErrMsg string `json:"errMsg"`
OperationID string `json:"operationID"`
}

@ -1,14 +1,15 @@
all_proto=(
#message_cms/message_cms.proto
#admin_cms/admin_cms.proto
#statistics/statistics.proto
#auth/auth.proto
#friend/friend.proto
#group/group.proto
message_cms/message_cms.proto
admin_cms/admin_cms.proto
statistics/statistics.proto
auth/auth.proto
friend/friend.proto
group/group.proto
user/user.proto
#chat/chat.proto
#push/push.proto
#relay/relay.proto
#sdk_ws/ws.proto
rtc/rtc.proto
chat/chat.proto
push/push.proto
relay/relay.proto
sdk_ws/ws.proto
)

@ -0,0 +1,418 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.15.5
// source: rtc/rtc.proto
package rtc
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type CommonResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ErrCode int32 `protobuf:"varint,1,opt,name=errCode,proto3" json:"errCode,omitempty"`
ErrMsg string `protobuf:"bytes,2,opt,name=errMsg,proto3" json:"errMsg,omitempty"`
}
func (x *CommonResp) Reset() {
*x = CommonResp{}
if protoimpl.UnsafeEnabled {
mi := &file_rtc_rtc_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *CommonResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CommonResp) ProtoMessage() {}
func (x *CommonResp) ProtoReflect() protoreflect.Message {
mi := &file_rtc_rtc_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CommonResp.ProtoReflect.Descriptor instead.
func (*CommonResp) Descriptor() ([]byte, []int) {
return file_rtc_rtc_proto_rawDescGZIP(), []int{0}
}
func (x *CommonResp) GetErrCode() int32 {
if x != nil {
return x.ErrCode
}
return 0
}
func (x *CommonResp) GetErrMsg() string {
if x != nil {
return x.ErrMsg
}
return ""
}
type GetJoinTokenReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ApiKey string `protobuf:"bytes,1,opt,name=apiKey,proto3" json:"apiKey,omitempty"`
ApiSecret string `protobuf:"bytes,2,opt,name=apiSecret,proto3" json:"apiSecret,omitempty"`
Room string `protobuf:"bytes,3,opt,name=room,proto3" json:"room,omitempty"`
Identity string `protobuf:"bytes,4,opt,name=identity,proto3" json:"identity,omitempty"`
OperationID string `protobuf:"bytes,5,opt,name=operationID,proto3" json:"operationID,omitempty"`
}
func (x *GetJoinTokenReq) Reset() {
*x = GetJoinTokenReq{}
if protoimpl.UnsafeEnabled {
mi := &file_rtc_rtc_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetJoinTokenReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetJoinTokenReq) ProtoMessage() {}
func (x *GetJoinTokenReq) ProtoReflect() protoreflect.Message {
mi := &file_rtc_rtc_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetJoinTokenReq.ProtoReflect.Descriptor instead.
func (*GetJoinTokenReq) Descriptor() ([]byte, []int) {
return file_rtc_rtc_proto_rawDescGZIP(), []int{1}
}
func (x *GetJoinTokenReq) GetApiKey() string {
if x != nil {
return x.ApiKey
}
return ""
}
func (x *GetJoinTokenReq) GetApiSecret() string {
if x != nil {
return x.ApiSecret
}
return ""
}
func (x *GetJoinTokenReq) GetRoom() string {
if x != nil {
return x.Room
}
return ""
}
func (x *GetJoinTokenReq) GetIdentity() string {
if x != nil {
return x.Identity
}
return ""
}
func (x *GetJoinTokenReq) GetOperationID() string {
if x != nil {
return x.OperationID
}
return ""
}
type GetJoinTokenResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
CommonResp *CommonResp `protobuf:"bytes,1,opt,name=CommonResp,proto3" json:"CommonResp,omitempty"`
Jwt string `protobuf:"bytes,2,opt,name=jwt,proto3" json:"jwt,omitempty"`
}
func (x *GetJoinTokenResp) Reset() {
*x = GetJoinTokenResp{}
if protoimpl.UnsafeEnabled {
mi := &file_rtc_rtc_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetJoinTokenResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetJoinTokenResp) ProtoMessage() {}
func (x *GetJoinTokenResp) ProtoReflect() protoreflect.Message {
mi := &file_rtc_rtc_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetJoinTokenResp.ProtoReflect.Descriptor instead.
func (*GetJoinTokenResp) Descriptor() ([]byte, []int) {
return file_rtc_rtc_proto_rawDescGZIP(), []int{2}
}
func (x *GetJoinTokenResp) GetCommonResp() *CommonResp {
if x != nil {
return x.CommonResp
}
return nil
}
func (x *GetJoinTokenResp) GetJwt() string {
if x != nil {
return x.Jwt
}
return ""
}
var File_rtc_rtc_proto protoreflect.FileDescriptor
var file_rtc_rtc_proto_rawDesc = []byte{
0x0a, 0x0d, 0x72, 0x74, 0x63, 0x2f, 0x72, 0x74, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
0x03, 0x72, 0x74, 0x63, 0x22, 0x3e, 0x0a, 0x0a, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x65,
0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x65, 0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x05, 0x52, 0x07, 0x65, 0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06,
0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72,
0x72, 0x4d, 0x73, 0x67, 0x22, 0x99, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x4a, 0x6f, 0x69, 0x6e,
0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x70, 0x69, 0x4b,
0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x70, 0x69, 0x4b, 0x65, 0x79,
0x12, 0x1c, 0x0a, 0x09, 0x61, 0x70, 0x69, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x70, 0x69, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x12, 0x12,
0x0a, 0x04, 0x72, 0x6f, 0x6f, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f,
0x6f, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x04,
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x20,
0x0a, 0x0b, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x18, 0x05, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44,
0x22, 0x55, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4a, 0x6f, 0x69, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e,
0x52, 0x65, 0x73, 0x70, 0x12, 0x2f, 0x0a, 0x0a, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x65,
0x73, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x72, 0x74, 0x63, 0x2e, 0x43,
0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x52, 0x0a, 0x43, 0x6f, 0x6d, 0x6d, 0x6f,
0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x6a, 0x77, 0x74, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x03, 0x6a, 0x77, 0x74, 0x32, 0x49, 0x0a, 0x0a, 0x52, 0x74, 0x63, 0x53, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x4a, 0x6f, 0x69, 0x6e,
0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x14, 0x2e, 0x72, 0x74, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4a,
0x6f, 0x69, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x72, 0x74,
0x63, 0x2e, 0x47, 0x65, 0x74, 0x4a, 0x6f, 0x69, 0x6e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65,
0x73, 0x70, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x72, 0x74, 0x63, 0x3b, 0x72, 0x74, 0x63, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_rtc_rtc_proto_rawDescOnce sync.Once
file_rtc_rtc_proto_rawDescData = file_rtc_rtc_proto_rawDesc
)
func file_rtc_rtc_proto_rawDescGZIP() []byte {
file_rtc_rtc_proto_rawDescOnce.Do(func() {
file_rtc_rtc_proto_rawDescData = protoimpl.X.CompressGZIP(file_rtc_rtc_proto_rawDescData)
})
return file_rtc_rtc_proto_rawDescData
}
var file_rtc_rtc_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_rtc_rtc_proto_goTypes = []interface{}{
(*CommonResp)(nil), // 0: rtc.CommonResp
(*GetJoinTokenReq)(nil), // 1: rtc.GetJoinTokenReq
(*GetJoinTokenResp)(nil), // 2: rtc.GetJoinTokenResp
}
var file_rtc_rtc_proto_depIdxs = []int32{
0, // 0: rtc.GetJoinTokenResp.CommonResp:type_name -> rtc.CommonResp
1, // 1: rtc.RtcService.GetJoinToken:input_type -> rtc.GetJoinTokenReq
2, // 2: rtc.RtcService.GetJoinToken:output_type -> rtc.GetJoinTokenResp
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_rtc_rtc_proto_init() }
func file_rtc_rtc_proto_init() {
if File_rtc_rtc_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_rtc_rtc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*CommonResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_rtc_rtc_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetJoinTokenReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_rtc_rtc_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetJoinTokenResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_rtc_rtc_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_rtc_rtc_proto_goTypes,
DependencyIndexes: file_rtc_rtc_proto_depIdxs,
MessageInfos: file_rtc_rtc_proto_msgTypes,
}.Build()
File_rtc_rtc_proto = out.File
file_rtc_rtc_proto_rawDesc = nil
file_rtc_rtc_proto_goTypes = nil
file_rtc_rtc_proto_depIdxs = nil
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConnInterface
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion6
// RtcServiceClient is the client API for RtcService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type RtcServiceClient interface {
GetJoinToken(ctx context.Context, in *GetJoinTokenReq, opts ...grpc.CallOption) (*GetJoinTokenResp, error)
}
type rtcServiceClient struct {
cc grpc.ClientConnInterface
}
func NewRtcServiceClient(cc grpc.ClientConnInterface) RtcServiceClient {
return &rtcServiceClient{cc}
}
func (c *rtcServiceClient) GetJoinToken(ctx context.Context, in *GetJoinTokenReq, opts ...grpc.CallOption) (*GetJoinTokenResp, error) {
out := new(GetJoinTokenResp)
err := c.cc.Invoke(ctx, "/rtc.RtcService/GetJoinToken", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// RtcServiceServer is the server API for RtcService service.
type RtcServiceServer interface {
GetJoinToken(context.Context, *GetJoinTokenReq) (*GetJoinTokenResp, error)
}
// UnimplementedRtcServiceServer can be embedded to have forward compatible implementations.
type UnimplementedRtcServiceServer struct {
}
func (*UnimplementedRtcServiceServer) GetJoinToken(context.Context, *GetJoinTokenReq) (*GetJoinTokenResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetJoinToken not implemented")
}
func RegisterRtcServiceServer(s *grpc.Server, srv RtcServiceServer) {
s.RegisterService(&_RtcService_serviceDesc, srv)
}
func _RtcService_GetJoinToken_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetJoinTokenReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RtcServiceServer).GetJoinToken(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/rtc.RtcService/GetJoinToken",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RtcServiceServer).GetJoinToken(ctx, req.(*GetJoinTokenReq))
}
return interceptor(ctx, in, info, handler)
}
var _RtcService_serviceDesc = grpc.ServiceDesc{
ServiceName: "rtc.RtcService",
HandlerType: (*RtcServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetJoinToken",
Handler: _RtcService_GetJoinToken_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "rtc/rtc.proto",
}

@ -0,0 +1,26 @@
syntax = "proto3";
option go_package = "./rtc;rtc";
package rtc;
message CommonResp{
int32 errCode = 1;
string errMsg = 2;
}
message GetJoinTokenReq{
string apiKey = 1;
string apiSecret = 2;
string room = 3;
string identity = 4;
string operationID = 5;
}
message GetJoinTokenResp{
CommonResp CommonResp = 1;
string jwt = 2;
}
service RtcService {
rpc GetJoinToken(GetJoinTokenReq) returns(GetJoinTokenResp);
}

@ -442,6 +442,3 @@ message SignalRejectReply {
}

Loading…
Cancel
Save