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
f4cbc4db
Commit
f4cbc4db
authored
Feb 16, 2022
by
李维杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
为了测试turn 81.70.124.49 及 纯P2P通讯(不走中转)而修改代码
parent
f5787584
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
47 deletions
+44
-47
cmd_processer_server.cc
cmu/src/cmd_processer_server.cc
+34
-34
cmd_processer_server.h
cmu/src/cmd_processer_server.h
+1
-1
mqtt_request.cc
thirdparty/mqtt/mqtt_request.cc
+8
-11
mqtt_wrapper.cc
thirdparty/mqtt/mqtt_wrapper.cc
+1
-1
No files found.
cmu/src/cmd_processer_server.cc
View file @
f4cbc4db
#include "cmd_processer_server.h"
#include "mqtt_request.h"
#include "json/json.h"
namespace
offcn
{
static
const
std
::
string
kGlobalTopic
=
"
kcp_server_mqtt"
;
static
const
std
::
string
kLocalID
=
"
kcp_server_mqtt"
;
static
const
std
::
string
kGlobalTopic
=
"
topic_for_turn_test"
;
static
const
std
::
string
kLocalID
=
"
mqtt_server_for_turn_test"
;
CmdProcesserServer
::
CmdProcesserServer
()
:
mqtt_wrapper_
(
NULL
)
...
...
@@ -63,67 +64,66 @@ namespace offcn
return
;
}
if
(
method
.
compare
(
"
join"
)
==
0
)
if
(
method
.
compare
(
"
login"
)
==
0
)
{
if
(
MqttRequest
::
ParseJoinRequest
(
message
,
values
,
error
))
{
OnParseJoinSuccess
(
values
[
"
message_id"
],
values
[
"from_id"
]);
OnParseJoinSuccess
(
values
[
"
id"
]);
}
else
{
OnParseFailure
(
values
[
"message_id"
],
values
[
"from_id"
],
error
);
}
}
else
if
(
method
.
compare
(
"update"
)
==
0
)
{
if
(
MqttRequest
::
ParseUpdateRequest
(
message
,
values
,
error
))
{
OnParseUpdateSuccess
(
values
[
"message_id"
],
values
[
"from_id"
],
values
[
"pull_type"
]);
}
else
{
OnParseFailure
(
values
[
"message_id"
],
values
[
"from_id"
],
error
);
OnParseFailure
(
values
[
"id"
],
values
[
"id"
],
error
);
}
}
}
void
CmdProcesserServer
::
OnParseJoinSuccess
(
std
::
string
message_id
,
std
::
string
from_id
)
void
CmdProcesserServer
::
OnParseJoinSuccess
(
std
::
string
from_id
)
{
std
::
string
response
;
if
(
client_lists_
.
find
(
from_id
)
!=
client_lists_
.
end
())
{
response
=
MqttRequest
::
BuildResponse
(
message_id
,
"id exist"
);
response
=
MqttRequest
::
BuildResponse
(
from_id
,
"id exist"
);
mqtt_wrapper_
->
SendRequest
(
from_id
,
response
);
return
;
}
else
{
if
(
client_lists_
.
size
()
==
0
)
{
client_lists_
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
from_id
,
"rtmp"
));
}
else
{
client_lists_
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
from_id
,
"null"
));
}
client_lists_
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
from_id
,
from_id
));
//response
response
=
MqttRequest
::
BuildResponse
(
message_id
,
"ok"
);
mqtt_wrapper_
->
SendRequest
(
from_id
,
response
);
Json
::
Value
root
;
Json
::
Value
root1
;
Json
::
Value
ids
;
Json
::
StreamWriterBuilder
wBuilder
;
printf
(
"
\n
------------------------------------
\n
"
);
root
[
"method"
]
=
"publishers"
;
root1
[
"method"
]
=
"online"
;
root1
[
"id"
]
=
from_id
;
printf
(
"
\n
----------------online list--------------------
\n
"
);
std
::
map
<
std
::
string
,
std
::
string
>::
iterator
itor
;
for
(
itor
=
client_lists_
.
begin
();
itor
!=
client_lists_
.
end
();
itor
++
)
{
if
(
itor
->
first
.
compare
(
from_id
)
!=
0
&&
itor
->
second
.
compare
(
"rtmp"
)
==
0
)
if
(
itor
->
first
.
compare
(
from_id
)
!=
0
)
{
response
=
MqttRequest
::
PublishersRequest
(
"sdf"
,
from_id
,
itor
->
first
);
mqtt_wrapper_
->
SendRequest
(
from_id
,
response
);
//response = MqttRequest::PublishersRequest("sdf", from_id, itor->first);
//mqtt_wrapper_->SendRequest(itor->first, response);
ids
.
append
(
itor
->
first
);
}
printf
(
"id = %s, pull type = %s
\n
"
,
itor
->
first
.
c_str
(),
itor
->
second
.
c_str
());
}
printf
(
"------------------------------------
\n
"
);
printf
(
"
\n
-----------------------------------------------
\n
"
);
root
[
"ids"
]
=
ids
;
std
::
string
req
=
Json
::
writeString
(
wBuilder
,
root
);
mqtt_wrapper_
->
SendRequest
(
from_id
,
req
);
//req = Json::writeString(wBuilder, root1);
//std::string topic = kGlobalTopic;
//mqtt_wrapper_->SendRequest(topic, req);
}
}
void
CmdProcesserServer
::
OnParseFailure
(
std
::
string
message_id
,
std
::
string
from_id
,
std
::
string
error
)
...
...
cmu/src/cmd_processer_server.h
View file @
f4cbc4db
...
...
@@ -26,7 +26,7 @@ namespace offcn
virtual
void
OnServerMessageArrived
(
std
::
string
topic
,
std
::
string
message
);
private
:
void
OnParseJoinSuccess
(
std
::
string
message_id
,
std
::
string
from_id
);
void
OnParseJoinSuccess
(
std
::
string
from_id
);
void
OnParseFailure
(
std
::
string
message_id
,
std
::
string
from_id
,
std
::
string
error
);
void
OnParseUpdateSuccess
(
std
::
string
message_id
,
std
::
string
from_id
,
std
::
string
pull_type
);
...
...
thirdparty/mqtt/mqtt_request.cc
View file @
f4cbc4db
...
...
@@ -72,10 +72,8 @@ namespace offcn
Json
::
Value
root
;
Json
::
StreamWriterBuilder
wBuilder
;
root
[
"message_id"
]
=
message_id
;
root
[
"method"
]
=
"publishers"
;
root
[
"publishers_id"
]
=
publisher_id
;
root
[
"to_id"
]
=
to_id
;
root
[
"id"
]
=
message_id
;
return
Json
::
writeString
(
wBuilder
,
root
);
}
...
...
@@ -89,7 +87,7 @@ namespace offcn
return
false
;
}
if
(
!
root
[
"method"
]
&&
!
root
[
"result_code"
])
if
(
!
root
[
"method"
]
)
{
error
=
"param error"
;
return
false
;
...
...
@@ -109,21 +107,20 @@ namespace offcn
goto
Error
;
}
if
(
!
root
[
"me
ssage_id"
]
||
!
root
[
"method"
]
||
!
root
[
"from_id"
])
if
(
!
root
[
"me
thod"
]
||
!
root
[
"id"
])
{
error
=
"param error"
;
goto
Error
;
}
values
[
"message_id"
]
=
root
[
"message_id"
].
asString
();
values
[
"method"
]
=
root
[
"method"
].
asString
();
values
[
"
from_id"
]
=
root
[
"from_id"
].
asString
();
values
[
"
id"
]
=
root
[
"id"
].
asString
();
return
true
;
Error
:
values
[
"message_id"
]
=
""
;
values
[
"method"
]
=
""
;
values
[
"
from_id"
]
=
""
;
values
[
"
id"
]
=
""
;
return
false
;
}
...
...
@@ -205,8 +202,8 @@ namespace offcn
Json
::
Value
root
;
Json
::
StreamWriterBuilder
wBuilder
;
root
[
"method"
]
=
"
response"
;
root
[
"
message_id"
]
=
message_id
;
root
[
"method"
]
=
"
login"
;
root
[
"
id"
]
=
message_id
;
root
[
"result_code"
]
=
result_code
;
return
Json
::
writeString
(
wBuilder
,
root
);
...
...
thirdparty/mqtt/mqtt_wrapper.cc
View file @
f4cbc4db
...
...
@@ -4,7 +4,7 @@
namespace
offcn
{
static
const
std
::
string
kMqttUrl
=
"
101.200.63.143"
;
//"192.168.43.12";
static
const
std
::
string
kMqttUrl
=
"
test-mqq.offcncloud.com"
;
//"192.168.43.12";
static
const
std
::
string
kUserName
=
"admin"
;
static
const
std
::
string
kPassWord
=
"public"
;
...
...
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