diff --git a/internal/msg_gateway/gate/logic.go b/internal/msg_gateway/gate/logic.go index a78c075c7..50ac457ad 100644 --- a/internal/msg_gateway/gate/logic.go +++ b/internal/msg_gateway/gate/logic.go @@ -200,7 +200,7 @@ func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) { nReply := new(pbChat.SendMsgResp) isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendSignalMsg) log.NewInfo(m.OperationID, "args is ", pData.(*sdk_ws.SignalReq)) - isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq)) + isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq), m.OperationID) if isPass && isPass2 { pbData := pbChat.SendMsgReq{ Token: m.Token, diff --git a/internal/msg_gateway/gate/open_im_media/room.go b/internal/msg_gateway/gate/open_im_media/room.go index 76356d886..498bc23c0 100644 --- a/internal/msg_gateway/gate/open_im_media/room.go +++ b/internal/msg_gateway/gate/open_im_media/room.go @@ -1,9 +1,18 @@ package open_im_media +import ( + pbRtc "Open_IM/pkg/proto/rtc" + "context" + "errors" + "google.golang.org/grpc" +) + const ( MediaAddress = "ws://43.128.5.63:7880" ApiKey = "APIGPW3gnFTzqHH" ApiSecret = "23ztfSqsfQ8hKkHzHTl3Z4bvaxro0snjk5jwbp5p6Q3" + // Address gRPC服务地址 + Address = "127.0.0.1:11300" ) //var roomClient *lksdk.RoomServiceClient @@ -22,8 +31,23 @@ func NewMedia() *Media { func (m *Media) GetUrl() string { return m.MediaAddress } -func (m *Media) GetJoinToken(room, identity string) (string, error) { - return identity, nil + +func (m *Media) GetJoinToken(room, identity string, operationID string) (string, error) { + conn, err := grpc.Dial(Address, grpc.WithInsecure()) + if err != nil { + return "", err + } + defer conn.Close() + c := pbRtc.NewRtcServiceClient(conn) + req := &pbRtc.GetJoinTokenReq{ApiKey: m.ApiKey, ApiSecret: m.ApiSecret, Room: room, OperationID: operationID, Identity: identity} + resp, err := c.GetJoinToken(context.Background(), req) + if err != nil { + return "", err + } + if resp.CommonResp.ErrCode != 0 { + return "", errors.New(resp.CommonResp.ErrMsg) + } + return resp.Jwt, nil //at := auth.NewAccessToken(m.ApiKey, m.ApiSecret) //grant := &auth.VideoGrant{ // RoomJoin: true, diff --git a/internal/msg_gateway/gate/validate.go b/internal/msg_gateway/gate/validate.go index b5c8dd504..dd8ea022e 100644 --- a/internal/msg_gateway/gate/validate.go +++ b/internal/msg_gateway/gate/validate.go @@ -117,7 +117,7 @@ func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, er } -func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq) (isPass bool, errCode int32, errMsg string, r *open_im_sdk.SignalResp, msgData *open_im_sdk.MsgData) { +func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq, operationID string) (isPass bool, errCode int32, errMsg string, r *open_im_sdk.SignalResp, msgData *open_im_sdk.MsgData) { var msg open_im_sdk.MsgData var resp open_im_sdk.SignalResp media := open_im_media.NewMedia() @@ -139,12 +139,13 @@ func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq) (isPass bool, msg.Options = options switch payload := s.Payload.(type) { case *open_im_sdk.SignalReq_Invite: - _, err := media.CreateRoom(payload.Invite.Invitation.RoomID) - if err != nil { - return false, 201, err.Error(), nil, nil + //_, err := media.CreateRoom(payload.Invite.Invitation.RoomID) + //if err != nil { + // return false, 201, err.Error(), nil, nil + // + //} - } - token, err2 := media.GetJoinToken(payload.Invite.Invitation.RoomID, payload.Invite.Invitation.InviterUserID) + token, err2 := media.GetJoinToken(payload.Invite.Invitation.RoomID, payload.Invite.Invitation.InviterUserID, operationID) if err2 != nil { return false, 201, err2.Error(), nil, nil } @@ -166,12 +167,12 @@ func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq) (isPass bool, msg.ClientMsgID = utils.GetMsgID(payload.Invite.Invitation.InviterUserID) return true, 0, "", &resp, &msg case *open_im_sdk.SignalReq_InviteInGroup: - _, err := media.CreateRoom(payload.InviteInGroup.Invitation.RoomID) - if err != nil { - return false, 201, err.Error(), nil, nil - - } - token, err2 := media.GetJoinToken(payload.InviteInGroup.Invitation.RoomID, payload.InviteInGroup.Invitation.InviterUserID) + //_, err := media.CreateRoom(payload.InviteInGroup.Invitation.RoomID) + //if err != nil { + // return false, 201, err.Error(), nil, nil + // + //} + token, err2 := media.GetJoinToken(payload.InviteInGroup.Invitation.RoomID, payload.InviteInGroup.Invitation.InviterUserID, operationID) if err2 != nil { return false, 201, err2.Error(), nil, nil } @@ -213,7 +214,7 @@ func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq) (isPass bool, msg.ClientMsgID = utils.GetMsgID(payload.Cancel.OpUserID) return true, 0, "", &resp, &msg case *open_im_sdk.SignalReq_Accept: - token, err2 := media.GetJoinToken(payload.Accept.Invitation.RoomID, payload.Accept.OpUserID) + token, err2 := media.GetJoinToken(payload.Accept.Invitation.RoomID, payload.Accept.OpUserID, operationID) if err2 != nil { return false, 201, err2.Error(), nil, nil }