Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/tuoyun' into tuoyun
Browse files Browse the repository at this point in the history
  • Loading branch information
FGadvancer committed Nov 4, 2021
2 parents 83545f9 + a053627 commit 92ec944
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 26 deletions.
1 change: 0 additions & 1 deletion open_im_sdk/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ func (u *UserRelated) initBasicInfo(message *MsgStruct, msgFrom, contentType int
userInfo, _ := u.getLoginUserInfoFromLocal()
message.SenderFaceURL = userInfo.Icon
message.SenderNickName = userInfo.Name
//Generate client message primary key
ClientMsgID := getMsgID(message.SendID)
message.ClientMsgID = ClientMsgID
message.MsgFrom = msgFrom
Expand Down
6 changes: 5 additions & 1 deletion open_im_sdk/open_im_sdk_conversation_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ func (u *UserRelated) CreateFileMessage(filePath string, fileName string) string
}
s.FileElem.FileSize = fi.Size()
s.AtElem.AtUserList = []string{}

sdkLog("CreateForwardMessage new input: ", structToJsonString(s))
return structToJsonString(s)
}
func (u *UserRelated) CreateMergerMessage(messageList, title, summaryList string) string {
Expand All @@ -707,7 +709,8 @@ func (u *UserRelated) CreateMergerMessage(messageList, title, summaryList string
s := MsgStruct{}
err := json.Unmarshal([]byte(messageList), &messages)
if err != nil {
fmt.Println("CreateMergerMessage err:", err.Error())
sdkLog("CreateMergerMessage err:", err.Error())
return ""
}
_ = json.Unmarshal([]byte(summaryList), &summaries)
u.initBasicInfo(&s, UserMsgType, Merger)
Expand All @@ -718,6 +721,7 @@ func (u *UserRelated) CreateMergerMessage(messageList, title, summaryList string
return structToJsonString(s)
}
func (u *UserRelated) CreateForwardMessage(m string) string {
sdkLog("CreateForwardMessage input: ", m)
s := MsgStruct{}
err := json.Unmarshal([]byte(m), &s)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions open_im_sdk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,12 @@ func (u *UserRelated) writeBinaryMsg(msg GeneralWsReq) (error, *websocket.Conn)
if err != nil {
sdkLog("SetWriteDeadline failed ", err.Error())
}

err = u.conn.WriteMessage(websocket.BinaryMessage, buff.Bytes())
sdkLog("send ws BinaryMessage len: ", len(buff.Bytes()))
if len(buff.Bytes()) > MaxTotalMsgLen {
LogFReturn("msg too long", len(buff.Bytes()), MaxTotalMsgLen)
return errors.New("msg too long"), connSended
}
err = u.conn.WriteMessage(websocket.BinaryMessage, buff.Bytes())
if err != nil {
LogFReturn(err.Error(), msg.OperationID)
} else {
Expand Down
52 changes: 52 additions & 0 deletions open_im_sdk/ws_wrapper/open_im_sdk_my.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
** description("").
** copyright('open-im,www.open-im.io').
** author("fg,Gordon@tuoyun.net").
** time(2021/9/8 14:35).
*/
package main

import (
"flag"
"fmt"
"open_im_sdk/open_im_sdk"
"open_im_sdk/open_im_sdk/ws_wrapper/utils"
"open_im_sdk/open_im_sdk/ws_wrapper/ws_local_server"
"runtime"
"sync"
)

func main() {
var sdkWsPort, openIMApiPort, openIMWsPort *int
var openIMWsAddress, openIMApiAddress *string
APIADDR := "http://47.112.160.66:10000"
WSADDR := "ws://47.112.160.66:17778"

sysType := runtime.GOOS
switch sysType {
case "darwin":
ws_local_server.InitServer(&open_im_sdk.IMConfig{IpApiAddr: *openIMApiAddress,
IpWsAddr: *openIMWsAddress, Platform: utils.OSXPlatformID, DbDir: "./"})
case "linux":

//sdkDBDir:= flag.String("sdk_db_dir","","openIMSDK initialization path")
ws_local_server.InitServer(&open_im_sdk.IMConfig{IpApiAddr: "http://" + utils.ServerIP + ":" + utils.IntToString(*openIMApiPort),
IpWsAddr: "ws://" + utils.ServerIP + ":" + utils.IntToString(*openIMWsPort), Platform: utils.WebPlatformID, DbDir: "../db/sdk/"})

case "windows":
sdkWsPort = flag.Int("sdk_ws_port", 7799, "openIM ws listening port")
flag.Parse()
ws_local_server.InitServer(&open_im_sdk.IMConfig{IpApiAddr: APIADDR,
IpWsAddr: WSADDR, Platform: utils.WebPlatformID, DbDir: "./"})
default:
fmt.Println("this os not support", sysType)

}
var wg sync.WaitGroup
wg.Add(1)
fmt.Println("ws server is starting")
ws_local_server.WS.OnInit(*sdkWsPort)
ws_local_server.WS.Run()
wg.Wait()

}
11 changes: 7 additions & 4 deletions open_im_sdk/ws_wrapper/ws_local_server/ws_conversation_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (wsRouter *WsFuncRouter) GetOneConversation(input string, operationID strin
}

userWorker := open_im_sdk.GetUserWorker(wsRouter.uId)
userWorker.GetOneConversation(m["sourceID"].(string), m["sessionType"].(int), &BaseSuccFailed{runFuncName(), operationID, wsRouter.uId})
userWorker.GetOneConversation(m["sourceID"].(string), int(m["sessionType"].(float64)), &BaseSuccFailed{runFuncName(), operationID, wsRouter.uId})
}

func (wsRouter *WsFuncRouter) GetMultipleConversation(conversationIDList string, operationID string) {
Expand Down Expand Up @@ -228,16 +228,19 @@ func CreateCustomMessage(data, extension []byte, description string) string {
*/

func (wsRouter *WsFuncRouter) CreateQuoteMessage(input string, operationID string) {
wrapSdkLog("CreateQuoteMessage", input, operationID)
m := make(map[string]interface{})
if err := json.Unmarshal([]byte(input), &m); err != nil {
wrapSdkLog("unmarshal failed")
wrapSdkLog("unmarshal failed", operationID)
wsRouter.GlobalSendMessage(EventData{cleanUpfuncName(runFuncName()), 1001, "unmarshal failed", "", operationID})
return
}
userWorker := open_im_sdk.GetUserWorker(wsRouter.uId)
if !wsRouter.checkKeysIn(input, operationID, runFuncName(), m, "text", "message") {
wrapSdkLog("key not in, failed", operationID)
return
}
wrapSdkLog("GlobalSendMessage", operationID)
msg := userWorker.CreateQuoteMessage(m["text"].(string), m["message"].(string))
wsRouter.GlobalSendMessage(EventData{cleanUpfuncName(runFuncName()), 0, "", msg, operationID})
}
Expand All @@ -253,7 +256,7 @@ func (wsRouter *WsFuncRouter) CreateVideoMessageFromFullPath(input string, opera
if !wsRouter.checkKeysIn(input, operationID, runFuncName(), m, "videoFullPath", "videoType", "duration", "snapshotFullPath") {
return
}
msg := userWorker.CreateVideoMessageFromFullPath(m["videoFullPath"].(string), m["videoType"].(string), m["duration"].(int64), m["snapshotFullPath"].(string))
msg := userWorker.CreateVideoMessageFromFullPath(m["videoFullPath"].(string), m["videoType"].(string), int64(m["duration"].(float64)), m["snapshotFullPath"].(string))
wsRouter.GlobalSendMessage(EventData{cleanUpfuncName(runFuncName()), 0, "", msg, operationID})
}

Expand Down Expand Up @@ -283,7 +286,7 @@ func (wsRouter *WsFuncRouter) CreateSoundMessageFromFullPath(input string, opera
if !wsRouter.checkKeysIn(input, operationID, runFuncName(), m, "soundPath", "duration") {
return
}
msg := userWorker.CreateSoundMessageFromFullPath(m["soundPath"].(string), m["duration"].(int64))
msg := userWorker.CreateSoundMessageFromFullPath(m["soundPath"].(string), int64(m["duration"].(float64)))
wsRouter.GlobalSendMessage(EventData{cleanUpfuncName(runFuncName()), 0, "", msg, operationID})
}

Expand Down
21 changes: 3 additions & 18 deletions open_im_sdk/ws_wrapper/ws_local_server/ws_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,9 @@ func (wsRouter *WsFuncRouter) JoinGroup(input, operationID string) {
userWorker.JoinGroup(m["groupId"].(string), m["message"].(string), &BaseSuccFailed{runFuncName(), operationID, wsRouter.uId})
}

func (wsRouter *WsFuncRouter) QuitGroup(input, operationID string) {
m := make(map[string]interface{})
if err := json.Unmarshal([]byte(input), &m); err != nil {
wrapSdkLog("unmarshal failed")
wsRouter.GlobalSendMessage(EventData{cleanUpfuncName(runFuncName()), 1001, "unmarshal failed", "", operationID})
return
}
if !wsRouter.checkKeysIn(input, operationID, runFuncName(), m, "groupId") {
return
}
func (wsRouter *WsFuncRouter) QuitGroup(groupId, operationID string) {
userWorker := open_im_sdk.GetUserWorker(wsRouter.uId)
userWorker.QuitGroup(m["groupId"].(string), &BaseSuccFailed{runFuncName(), operationID, wsRouter.uId})
userWorker.QuitGroup(groupId, &BaseSuccFailed{runFuncName(), operationID, wsRouter.uId})
}

func (wsRouter *WsFuncRouter) GetJoinedGroupList(input, operationID string) {
Expand Down Expand Up @@ -166,7 +157,7 @@ func (wsRouter *WsFuncRouter) GetGroupMemberList(input, operationID string) { //
return
}
userWorker := open_im_sdk.GetUserWorker(wsRouter.uId)
userWorker.GetGroupMemberList(m["groupId"].(string), m["filter"].(int32), m["next"].(int32), &BaseSuccFailed{runFuncName(), operationID, wsRouter.uId})
userWorker.GetGroupMemberList(m["groupId"].(string), int32(m["filter"].(float64)), int32(m["next"].(float64)), &BaseSuccFailed{runFuncName(), operationID, wsRouter.uId})
}

func (wsRouter *WsFuncRouter) GetGroupMembersInfo(input, operationID string) { //(groupId string, userList string, callback Base) {
Expand Down Expand Up @@ -226,12 +217,6 @@ func (wsRouter *WsFuncRouter) InviteUserToGroup(input, operationID string) { //(
}

func (wsRouter *WsFuncRouter) GetGroupApplicationList(input, operationID string) { //(callback Base) {
m := make(map[string]interface{})
if err := json.Unmarshal([]byte(input), &m); err != nil {
wrapSdkLog("unmarshal failed")
wsRouter.GlobalSendMessage(EventData{cleanUpfuncName(runFuncName()), 1001, "unmarshal failed", "", operationID})
return
}
userWorker := open_im_sdk.GetUserWorker(wsRouter.uId)
userWorker.GetGroupApplicationList(&BaseSuccFailed{runFuncName(), operationID, wsRouter.uId})

Expand Down
17 changes: 17 additions & 0 deletions test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,26 @@ var (
SENDINTERVAL = 20
)

func int64ToString(i int64) string {
return strconv.FormatInt(i, 10)
}

func getCurrentTimestampByNano() int64 {
return time.Now().UnixNano()
}

func getMsgID(sendID string) string {
t := int64ToString(getCurrentTimestampByNano())
return open_im_sdk.Md5(t + sendID + int64ToString(rand.Int63n(getCurrentTimestampByNano())))
}

// myuid, maxuid, msgnum
func main() {

for {
fmt.Println("id: ", getMsgID("xyz"))
}

/*
myUid1 := 17396220460
strMyUid1 := GenUid(myUid1)
Expand Down

0 comments on commit 92ec944

Please sign in to comment.