Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
im-pool
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoyanbin
im-pool
Commits
48c7ec6d
Commit
48c7ec6d
authored
Dec 08, 2022
by
haoyanbin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Record
parent
2885a2b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
23 deletions
+36
-23
publicApi.go
pool/publicApi.go
+18
-23
ws_server.go
ws_server.go
+18
-0
No files found.
pool/publicApi.go
View file @
48c7ec6d
...
...
@@ -376,13 +376,13 @@ func SaveMsg(msg *SendMsg) {
mqData
.
Participant
=
msg
.
FromClientId
//连接开启信息存入
conversation
:=
&
Conversation
{}
conversation
.
ConversationId
=
msg
.
ConversationId
conversation
.
Promoter
=
msg
.
FromClientId
conversation
.
Participant
=
msg
.
ToClientId
conversation
.
Status
=
3
conversation
.
StartReceiveDate
=
mqData
.
StartReceiveDate
AppendConversation
(
conversation
)
//
conversation := &Conversation{}
//
conversation.ConversationId = msg.ConversationId
//
conversation.Promoter = msg.FromClientId
//
conversation.Participant = msg.ToClientId
//
conversation.Status = 3
//
conversation.StartReceiveDate = mqData.StartReceiveDate
//
AppendConversation(conversation)
}
//结束
...
...
@@ -415,12 +415,13 @@ func SaveMsg(msg *SendMsg) {
mqData
.
Content
=
msg
.
Msg
mqData
.
Sender
=
msg
.
FromClientId
mqData
.
Receiver
=
msg
.
ToClientId
AppendConversationRecord
(
msg
)
}
if
msg
.
ProcedureType
==
8
{
mqData
.
Finish
=
"5"
mqData
.
EndTime
=
msg
.
SendTime
DelConversation
(
msg
.
ConversationId
)
//
DelConversation(msg.ConversationId)
}
if
mqData
.
ProcedureType
!=
0
{
...
...
@@ -459,23 +460,17 @@ func GetAllList(key string) map[string]string {
return
jsonDataAll
}
func
AppendConversation
(
conversation
*
Conversation
)
{
Redis
.
HSetNX
(
convKey
,
strconv
.
Itoa
(
conversation
.
ConversationId
),
string
(
SerializeJson
(
conversation
)))
func
AppendConversation
Record
(
msg
*
SendMsg
)
{
Redis
.
HSetNX
(
"msg:"
+
strconv
.
Itoa
(
msg
.
ConversationId
),
msg
.
FromClientId
+
":"
+
msg
.
ToClientId
,
string
(
SerializeJson
(
msg
)))
return
}
func
DelConversationRecord
(
conversationId
int
)
{
Redis
.
HDel
(
convKey
,
strconv
.
Itoa
(
conversationId
))
return
}
func
AppendConversationRecord
(
conversation
*
SendMsg
)
{
Redis
.
HSetNX
(
convKey
+
":"
+
strconv
.
Itoa
(
conversation
.
ConversationId
),
strconv
.
Itoa
(
conversation
.
ConversationId
),
string
(
SerializeJson
(
conversation
)))
return
func
GetConversationRecord
(
conversationId
int
)
{
//Redis.HGet()
}
func
DelConversation
(
conversationId
int
)
{
Redis
.
HDel
(
convKey
,
strconv
.
Itoa
(
conversationId
))
Redis
.
HDel
(
"msg:"
+
strconv
.
Itoa
(
conversationId
))
return
}
...
...
@@ -509,11 +504,11 @@ func SetEnd() {
}
toMqData
:=
&
SendMsg
{
ProcedureType
:
8
,
ProcedureType
:
8
,
ConversationId
:
conversationData
.
ConversationId
,
ToClientId
:
conversationData
.
Participant
,
FromClientId
:
conversationData
.
Promoter
,
SendTime
:
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
ToClientId
:
conversationData
.
Participant
,
FromClientId
:
conversationData
.
Promoter
,
SendTime
:
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
),
}
_
,
isSet
=
wsSever
.
hub
.
clients
[
conversationData
.
Participant
]
if
isSet
==
true
{
...
...
ws_server.go
View file @
48c7ec6d
...
...
@@ -61,6 +61,8 @@ func main() {
mux
.
HandleFunc
(
"/ws"
,
ws
)
mux
.
HandleFunc
(
"/ws-list"
,
GetClientList
)
mux
.
HandleFunc
(
"/ws-conv-list"
,
GetConversationList
)
mux
.
HandleFunc
(
"/ws-record-list"
,
GetConversationRecordList
)
err
:=
http
.
ListenAndServe
(
":11001"
,
mux
)
if
err
!=
nil
{
fmt
.
Printf
(
"ListenAndServe: %s"
,
err
.
Error
())
...
...
@@ -179,6 +181,22 @@ func GetClientList(w http.ResponseWriter, r *http.Request) {
resp
(
w
,
reply
)
}
func
GetConversationList
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
//data := r.URL.Query()
reply
:=
pool
.
GetAllList
(
"msg:*"
)
resp
(
w
,
reply
)
}
func
GetConversationRecordList
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
data
:=
r
.
URL
.
Query
()
reply
:=
pool
.
GetAllList
(
"msg:"
+
data
[
"conversationId"
][
0
])
resp
(
w
,
reply
)
}
func
resp
(
w
http
.
ResponseWriter
,
data
interface
{})
{
w
.
Header
()
.
Set
(
"content-type"
,
"text/json"
)
w
.
WriteHeader
(
200
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment