Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cmu
Overview
Overview
Details
Activity
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
李维杰
cmu
Commits
ff491e70
Commit
ff491e70
authored
Jun 22, 2020
by
李维杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加请求解析
parent
0da033fc
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
9 deletions
+93
-9
cmd_processer_server.cc
cmu/src/cmd_processer_server.cc
+60
-0
cmd_processer_server.h
cmu/src/cmd_processer_server.h
+3
-0
mqtt_request.cc
thirdparty/mqtt/mqtt_request.cc
+27
-6
mqtt_wrapper.cc
thirdparty/mqtt/mqtt_wrapper.cc
+3
-3
No files found.
cmu/src/cmd_processer_server.cc
View file @
ff491e70
...
...
@@ -53,5 +53,64 @@ namespace offcn
void
CmdProcesserServer
::
OnServerMessageArrived
(
std
::
string
topic
,
std
::
string
message
)
{
printf
(
"
\n
receive message : topic = %s, context : %s
\n
"
,
topic
.
c_str
(),
message
.
c_str
());
std
::
string
path
;
ReqValue
values
;
if
(
!
MqttRequest
::
ParseRequest
(
message
,
path
,
values
))
{
printf
(
"Error : Parse request error
\n
"
);
return
;
}
std
::
string
fid
=
values
[
"fid"
];
std
::
string
pull_type
;
if
(
path
.
compare
(
"join"
)
==
0
)
{
pull_type
=
values
[
"pull_type"
];
OnRequstJoin
(
fid
,
pull_type
);
}
}
void
CmdProcesserServer
::
OnRequstJoin
(
std
::
string
fid
,
std
::
string
pull_type
)
{
if
(
client_lists_
.
find
(
fid
)
!=
client_lists_
.
end
())
{
printf
(
"Waring : fid = %s already exist
\n
"
,
fid
.
c_str
());
return
;
}
std
::
string
dest_id
;
std
::
map
<
std
::
string
,
std
::
string
>::
iterator
itor
;
for
(
itor
=
client_lists_
.
begin
();
itor
!=
client_lists_
.
end
();
itor
++
)
{
if
(
itor
->
second
.
compare
(
"rtmp"
)
==
0
)
{
dest_id
=
itor
->
first
;
break
;
}
}
std
::
string
response
;
if
(
itor
!=
client_lists_
.
end
())
{
client_lists_
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
fid
,
"kcp"
));
response
=
MqttRequest
::
JoinResponse
(
dest_id
,
"success"
);
}
else
{
client_lists_
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
fid
,
"rtmp"
));
response
=
MqttRequest
::
JoinResponse
(
""
,
"success"
);
}
mqtt_wrapper_
->
SendRequest
(
fid
,
response
);
printf
(
"
\n
------------------------------------
\n
"
);
for
(
itor
=
client_lists_
.
begin
();
itor
!=
client_lists_
.
end
();
itor
++
)
{
printf
(
"id = %s, pull type = %s
\n
"
,
itor
->
first
.
c_str
(),
itor
->
second
.
c_str
());
}
printf
(
"------------------------------------
\n
"
);
}
}
\ No newline at end of file
cmu/src/cmd_processer_server.h
View file @
ff491e70
...
...
@@ -26,6 +26,9 @@ namespace offcn
virtual
void
OnServerMessageArrived
(
std
::
string
topic
,
std
::
string
message
);
private
:
void
OnRequstJoin
(
std
::
string
fid
,
std
::
string
pull_type
);
private
:
MqttWrapper
*
mqtt_wrapper_
;
private
:
...
...
thirdparty/mqtt/mqtt_request.cc
View file @
ff491e70
...
...
@@ -6,7 +6,7 @@ namespace offcn
/*
{
"path": "join",
"
r
id" : "xxxid",
"
f
id" : "xxxid",
"data" :
{
"pull_type" : "null"
...
...
@@ -19,7 +19,7 @@ namespace offcn
Json
::
StreamWriterBuilder
wBuilder
;
root
[
"path"
]
=
"join"
;
root
[
"
r
id"
]
=
local_id
;
root
[
"
f
id"
]
=
local_id
;
Json
::
Value
data
;
data
[
"pull_type"
]
=
"null"
;
...
...
@@ -31,7 +31,7 @@ namespace offcn
/*
{
"path": "update",
"
r
id" : "xxxid",
"
f
id" : "xxxid",
"data" :
{
"pull_type" : "rtmp" or "null" or "kcp"
...
...
@@ -44,7 +44,7 @@ namespace offcn
Json
::
StreamWriterBuilder
wBuilder
;
root
[
"path"
]
=
"update"
;
root
[
"
r
id"
]
=
local_id
;
root
[
"
f
id"
]
=
local_id
;
Json
::
Value
data
;
data
[
"pull_type"
]
=
pull_type
;
...
...
@@ -56,7 +56,7 @@ namespace offcn
/*
{
"path": "offer/answer",
"
r
id" : "xxxid",
"
f
id" : "xxxid",
"tid" : "remoteid",
"candidate" : ""
}
...
...
@@ -67,7 +67,7 @@ namespace offcn
Json
::
StreamWriterBuilder
wBuilder
;
root
[
"path"
]
=
type
;
root
[
"
r
id"
]
=
local_id
;
root
[
"
f
id"
]
=
local_id
;
root
[
"tid"
]
=
remote_id
;
root
[
"candidate"
]
=
candidate
;
...
...
@@ -94,6 +94,26 @@ namespace offcn
if
(
!
GetJsonValue
(
req
,
root
))
return
false
;
if
(
!
root
[
"path"
]
||
!
root
[
"fid"
])
return
false
;
path
=
root
[
"path"
].
asString
();
std
::
string
fid
=
root
[
"fid"
].
asString
();
if
(
path
.
compare
(
"join"
)
==
0
||
path
.
compare
(
"update"
)
==
0
)
{
values
[
"fid"
]
=
fid
;
values
[
"pull_type"
]
=
root
[
"pull_type"
].
asString
();
}
else
if
(
path
.
compare
(
"offer"
)
==
0
||
path
.
compare
(
"answer"
)
==
0
)
{
values
[
"fid"
]
=
fid
;
values
[
"tid"
]
=
root
[
"tid"
].
asString
();
values
[
"candidate"
]
=
root
[
"candidate"
].
asString
();
}
return
true
;
}
std
::
string
MqttRequest
::
JoinResponse
(
std
::
string
ids
,
std
::
string
result
)
...
...
@@ -102,6 +122,7 @@ namespace offcn
Json
::
StreamWriterBuilder
wBuilder
;
root
[
"path"
]
=
"join"
;
root
[
"ids"
]
=
ids
;
root
[
"result"
]
=
result
;
return
Json
::
writeString
(
wBuilder
,
root
);
...
...
thirdparty/mqtt/mqtt_wrapper.cc
View file @
ff491e70
...
...
@@ -4,9 +4,9 @@
namespace
offcn
{
static
const
std
::
string
kMqttUrl
=
"192.168.43.12"
;
static
const
std
::
string
kMqttUrl
=
"1
01.200.63.143"
;
//"1
92.168.43.12";
static
const
std
::
string
kUserName
=
"admin"
;
static
const
std
::
string
kPassWord
=
"
admin
"
;
static
const
std
::
string
kPassWord
=
"
public
"
;
static
struct
Options
{
...
...
@@ -59,7 +59,7 @@ namespace offcn
opts
.
onSuccess
=
mqttConnectSuccess
;
opts
.
onFailure
=
mqttConnectFailure
;
opts
.
context
=
this
;
opts
.
connectTimeout
=
10
;
opts
.
connectTimeout
=
5
;
nRet
=
MQTTAsync_connect
(
mqtt_client_
,
&
opts
);
if
(
nRet
!=
MQTTASYNC_SUCCESS
)
...
...
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