@@ -6,13 +6,17 @@ import (
6
6
"Open_IM/pkg/common/log"
7
7
"Open_IM/pkg/grpc-etcdv3/getcdv3"
8
8
pbChat "Open_IM/pkg/proto/chat"
9
+ pbRtc "Open_IM/pkg/proto/rtc"
9
10
sdk_ws "Open_IM/pkg/proto/sdk_ws"
11
+ "Open_IM/pkg/utils"
10
12
"bytes"
11
13
"context"
12
14
"encoding/gob"
13
15
"github.com/golang/protobuf/proto"
14
16
"github.com/gorilla/websocket"
17
+ "google.golang.org/grpc"
15
18
"runtime"
19
+ "strconv"
16
20
"strings"
17
21
)
18
22
@@ -200,38 +204,61 @@ func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) {
200
204
nReply := new (pbChat.SendMsgResp )
201
205
isPass , errCode , errMsg , pData := ws .argsValidate (m , constant .WSSendSignalMsg )
202
206
if isPass {
203
- isPass2 , errCode2 , errMsg2 , signalResp , msgData := ws .signalMessageAssemble (pData .(* sdk_ws.SignalReq ), m .OperationID )
204
- if isPass2 {
207
+ signalResp := pbRtc.SignalResp {}
208
+ //isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq), m.OperationID)
209
+ connGrpc , err := grpc .Dial (config .Config .Rtc .Address + ":" + strconv .Itoa (config .Config .Rtc .Port ), grpc .WithInsecure ())
210
+ if err != nil {
211
+ log .NewError (m .OperationID , utils .GetSelfFuncName (), "grpc.Dial failed" , err .Error ())
212
+ ws .sendSignalMsgResp (conn , 204 , "create grpc failed" + err .Error (), m , nil )
213
+ return
214
+ }
215
+ rtcClient := pbRtc .NewRtcServiceClient (connGrpc )
216
+ req := & pbRtc.SignalMessageAssembleReq {
217
+ SignalReq : pData .(* pbRtc.SignalReq ),
218
+ OperationID : m .OperationID ,
219
+ }
220
+ respPb , err := rtcClient .SignalMessageAssemble (context .Background (), req )
221
+ if err != nil {
222
+ log .NewError (m .OperationID , utils .GetSelfFuncName (), "SignalMessageAssemble" , err .Error (), config .Config .Rtc .Address + ":" + strconv .Itoa (config .Config .Rtc .Port ))
223
+ ws .sendSignalMsgResp (conn , 204 , "grpc SignalMessageAssemble failed: " + err .Error (), m , & signalResp )
224
+ return
225
+ }
226
+ signalResp .Payload = respPb .SignalResp .Payload
227
+ msgData := sdk_ws.MsgData {}
228
+ utils .CopyStructFields (& msgData , respPb .MsgData )
229
+ log .NewInfo (m .OperationID , utils .GetSelfFuncName (), respPb .String ())
230
+ if respPb .IsPass {
205
231
pbData := pbChat.SendMsgReq {
206
232
Token : m .Token ,
207
233
OperationID : m .OperationID ,
208
- MsgData : msgData ,
234
+ MsgData : & msgData ,
209
235
}
236
+ log .NewInfo (m .OperationID , utils .GetSelfFuncName (), "pbData: " , pbData )
210
237
log .NewInfo (m .OperationID , "Ws call success to sendSignalMsgReq middle" , m .ReqIdentifier , m .SendID , m .MsgIncr , msgData )
211
238
etcdConn := getcdv3 .GetConn (config .Config .Etcd .EtcdSchema , strings .Join (config .Config .Etcd .EtcdAddr , "," ), config .Config .RpcRegisterName .OpenImOfflineMessageName )
212
239
client := pbChat .NewChatClient (etcdConn )
213
240
reply , err := client .SendMsg (context .Background (), & pbData )
214
241
if err != nil {
215
- log .NewError (pbData .OperationID , "rpc sendMsg err" , err .Error ())
242
+ log .NewError (pbData .OperationID , utils . GetSelfFuncName (), "rpc sendMsg err" , err .Error ())
216
243
nReply .ErrCode = 200
217
244
nReply .ErrMsg = err .Error ()
218
- ws .sendSignalMsgResp (conn , 200 , err .Error (), m , signalResp )
245
+ ws .sendSignalMsgResp (conn , 200 , err .Error (), m , & signalResp )
219
246
} else {
220
247
log .NewInfo (pbData .OperationID , "rpc call success to sendMsgReq" , reply .String ())
221
- ws .sendSignalMsgResp (conn , 0 , "" , m , signalResp )
248
+ ws .sendSignalMsgResp (conn , 0 , "" , m , & signalResp )
222
249
}
223
250
} else {
224
- log .NewError (m .OperationID , isPass2 , errCode2 , errMsg2 )
225
- ws .sendSignalMsgResp (conn , errCode2 , errMsg2 , m , signalResp )
251
+ log .NewError (m .OperationID , utils . GetSelfFuncName (), respPb . IsPass , respPb . CommonResp . ErrCode , respPb . CommonResp . ErrMsg )
252
+ ws .sendSignalMsgResp (conn , respPb . CommonResp . ErrCode , respPb . CommonResp . ErrMsg , m , & signalResp )
226
253
}
227
254
} else {
228
255
ws .sendSignalMsgResp (conn , errCode , errMsg , m , nil )
229
256
}
230
257
231
258
}
232
- func (ws * WServer ) sendSignalMsgResp (conn * UserConn , errCode int32 , errMsg string , m * Req , pb * sdk_ws .SignalResp ) {
259
+ func (ws * WServer ) sendSignalMsgResp (conn * UserConn , errCode int32 , errMsg string , m * Req , pb * pbRtc .SignalResp ) {
233
260
// := make(map[string]interface{})
234
-
261
+ log . Debug ( m . OperationID , "SignalMsgResp is" , pb . String ())
235
262
b , _ := proto .Marshal (pb )
236
263
mReply := Resp {
237
264
ReqIdentifier : m .ReqIdentifier ,
0 commit comments