Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
max_android_panel
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Zhang Xin
max_android_panel
Commits
46daa5f4
Commit
46daa5f4
authored
Dec 06, 2018
by
Zhang Xin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix getip by socket not by http
parent
d14515d4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
69 deletions
+114
-69
client/containers/PageContainer/PageContainer.jsx
+1
-1
client/index.js
+2
-1
client/util/socket.js
+111
-67
No files found.
client/containers/PageContainer/PageContainer.jsx
View file @
46daa5f4
...
...
@@ -595,7 +595,7 @@ class PageContainer extends React.Component {
if
(
userInfo
.
employeeId
&&
storeInfo
.
id
){
this
.
changePages
(
CONFIG
.
showPage
[
page
]);
}
else
{
this
.
showError
(
"没有用户信息或门店信息 ip:"
+
commonInfo
.
ip
);
this
.
showError
(
"没有用户信息或门店信息 ip:"
+
commonInfo
.
ip
+
" storeId:"
+
(
commonInfo
.
storeInfo
?
commonInfo
.
storeInfo
.
id
:
0
)
);
}
}
else
{
...
...
client/index.js
View file @
46daa5f4
...
...
@@ -29,7 +29,7 @@ function renderPage(store) {
let
store
=
activateVendor
();
// UTILPATH.socket.init(129,17);
UTILPATH
.
socket
.
getIp
();
UTILPATH
.
socket
.
getIp
1
();
// UTILPATH.socket.getIp();
renderPage
(
store
);
\ No newline at end of file
client/util/socket.js
View file @
46daa5f4
...
...
@@ -10,6 +10,7 @@ let totalCount = 0;
let
getIpING
=
false
;
//正在获取IP
let
currentIpIndex
=
255
;
let
ws
=
null
;
let
storeId
=
0
const
checkStatus
=
(
response
)
=>
{
if
(
response
.
status
>=
200
&&
response
.
status
<
300
)
{
...
...
@@ -24,89 +25,129 @@ const parseJson = (response)=>{
return
response
.
json
();
};
socket
.
getIp
=
()
=>
{
console
.
log
(
"getIp "
,
getIpING
,
currentIpIndex
);
if
(
!
getIpING
){
// socket.getIp = ()=>{
// console.log("getIp ",getIpING,currentIpIndex);
// if(!getIpING){
// getIpING = true;
// for(let i = 0; i < 255 ; i ++){
// let url = 'http://' + domainIp + i + ':9999/getmyid';
// if(currentIpIndex === 255 && getIpING){
// fetch( url ,{
// // credentials : 'include',
// method : 'GET',
// mode : 'cors',
// }).then(checkStatus)
// .then(parseJson)
// .then((data) => {
// console.error("data :",data,currentIpIndex,i);
// if(data.storeId && currentIpIndex === 255){
// init(i,data.storeId);
// }
// })
// .catch((err) =>{
// console.error("Err:",err);
// totalCount++;
// if(totalCount >= 255){
// totalCount = 0;
// currentIpIndex = 255;
// getIpING = false;
// socket.getIp();
// }
//
// });
// }
//
// }
// }
//
// };
socket
.
getIp1
=
()
=>
{
if
(
!
getIpING
)
{
getIpING
=
true
;
for
(
let
i
=
0
;
i
<
255
;
i
++
){
let
url
=
'http://'
+
domainIp
+
i
+
':9999/getmyid'
;
if
(
currentIpIndex
===
255
&&
getIpING
){
fetch
(
url
,{
// credentials : 'include',
method
:
'GET'
,
mode
:
'cors'
,
}).
then
(
checkStatus
)
.
then
(
parseJson
)
.
then
((
data
)
=>
{
console
.
error
(
"data :"
,
data
,
currentIpIndex
,
i
);
if
(
data
.
storeId
&&
currentIpIndex
===
255
){
init
(
i
,
data
.
storeId
);
}
})
.
catch
((
err
)
=>
{
console
.
error
(
"Err:"
,
err
);
totalCount
++
;
if
(
totalCount
>=
255
){
totalCount
=
0
;
currentIpIndex
=
255
;
getIpING
=
false
;
socket
.
getIp
();
}
});
for
(
let
j
=
0
;
j
<
255
;
j
++
){
let
wsUrl
=
'ws://'
+
domainIp
+
j
+
':7788/notify?from=plant'
;
let
ws1
=
new
WebSocket
(
wsUrl
);
ws1
.
onopen
=
function
()
{
console
.
log
(
"ok "
)
if
(
currentIpIndex
===
255
){
console
.
log
(
"ip "
,
j
);
currentIpIndex
=
j
;
// ws1.close();
}
else
{
ws1
.
close
();
}
};
ws1
.
onmessage
=
(
evt
)
=>
{
if
(
currentIpIndex
!==
255
){
console
.
log
(
'onmessage '
,
currentIpIndex
,
evt
.
data
);
let
info
=
JSON
.
parse
(
evt
.
data
);
if
(
info
.
type
===
'GET_STORE_ID'
&&
info
.
data
){
ws1
.
close
();
init
(
currentIpIndex
,
info
.
data
,
true
);
}
}
};
ws1
.
onerror
=
function
(
err
)
{
totalCount
++
;
console
.
log
(
"totalCount "
,
totalCount
)
if
(
totalCount
>=
255
){
console
.
log
(
"totalCount inin"
)
totalCount
=
0
;
currentIpIndex
=
255
;
getIpING
=
false
;
socket
.
getIp1
();
}
}
}
}
};
socket
.
getStoreIdByIp
=
(
ip
)
=>
{
let
url
=
'http://'
+
domainIp
+
ip
+
':9999/getmyid'
;
fetch
(
url
,{
// credentials : 'include',
method
:
'GET'
,
mode
:
'cors'
,
}).
then
(
checkStatus
)
.
then
(
parseJson
)
.
then
((
data
)
=>
{
console
.
log
(
"socket data "
,
data
);
if
(
data
.
storeId
){
init
(
ip
,
data
.
storeId
,
true
);
}
})
.
catch
((
err
)
=>
{
console
.
error
(
"Err:"
,
err
);
if
(
!
getIpING
){
console
.
log
(
"getStoreIdByIp======="
)
currentIpIndex
=
255
;
totalCount
=
0
;
socket
.
getIp
();
}
});
}
// socket.getStoreIdByIp = (ip) => {
// let url = 'http://' + domainIp + ip + ':9999/getmyid';
// fetch( url ,{
// // credentials : 'include',
// method : 'GET',
// mode : 'cors',
// }).then(checkStatus)
// .then(parseJson)
// .then((data) => {
// console.log("socket data ",data);
// if(data.storeId){
// init(ip,data.storeId,true);
// }
// })
// .catch((err) =>{
// console.error("Err:",err);
// if(!getIpING){
// console.log("getStoreIdByIp=======")
// currentIpIndex = 255;
// totalCount = 0;
// socket.getIp1();
// }
// });
// }
const
getError
=
()
=>
{
console
.
error
(
"socket error"
);
getClose
();
}
const
getClose
=
()
=>
{
const
getClose
=
()
=>
{
console
.
error
(
"socket close "
,
currentIpIndex
);
//如果有currentIp就没有必要再次循环
ws
=
null
;
if
(
currentIpIndex
!==
255
){
//只需再次获取storeId即可,以防storeId有变化
socket
.
getStoreIdByIp
(
currentIpIndex
);
}
else
{
//重新获取IP
if
(
!
getIpING
){
console
.
log
(
"socket close========"
)
currentIpIndex
=
255
;
totalCount
=
0
;
socket
.
getIp
();
}
if
(
!
getIpING
){
console
.
log
(
"socket close========"
);
currentIpIndex
=
255
;
totalCount
=
0
;
storeId
=
0
;
socket
.
getIp1
();
}
}
...
...
@@ -116,7 +157,9 @@ const init = (ip,storeid,from = false)=>{
let
wsUrl
=
'ws://'
+
domainIp
+
ip
+
':7788/notify?from=plant&storeId='
+
storeid
;
console
.
log
(
"init :"
,
wsUrl
);
console
.
log
(
"========= "
,
"WebSocket"
in
window
,
ws
,
ip
,
storeid
,
currentIpIndex
,
from
)
if
(
"WebSocket"
in
window
&&
!
ws
&&
ip
&&
storeid
&&
(
currentIpIndex
===
255
||
from
)){
console
.
log
(
"in websocket"
);
ws
=
new
WebSocket
(
wsUrl
);
ws
.
onopen
=
function
()
...
...
@@ -124,6 +167,7 @@ const init = (ip,storeid,from = false)=>{
// Web Socket 已连接上,使用 send() 方法发送数据
// ws.send("发送数据");
currentIpIndex
=
ip
;
storeId
=
storeid
;
getIpING
=
false
;
console
.
log
(
"open"
);
emit
(
CONFIG
.
socketType
.
GETSTOREINFO
,{
ip
:
domainIp
+
ip
,
storeId
:
storeid
})
...
...
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