Toggle navigation
Toggle navigation
This project
Loading...
Sign in
조인화
/
Probability Death
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
unknown
2018-12-05 21:22:21 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9f8139a3d7eded606fea65a2e1727228a656e853
9f8139a3
1 parent
3de51060
api calling part developing
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
lib/api_option.js
lib/socketio.js
lib/api_option.js
0 → 100644
View file @
9f8139a
module
.
exports
=
{
key
=
""
}
\ No newline at end of file
lib/socketio.js
View file @
9f8139a
const
passport_IO
=
require
(
'./passport+socketio.js'
),
passportSocketIo
=
require
(
"passport.socketio"
),
db
=
require
(
'../lib/db.js'
);
const
db
=
require
(
'../lib/db.js'
);
const
requesting
=
require
(
'request'
);
const
secret_key
=
require
(
'./api_option'
).
key
;
module
.
exports
=
(
server
,
app
)
=>
{
const
io
=
require
(
'socket.io'
,
)(
server
,
{
transports
:
[
'websocket'
]
});
const
API_CALL
=
setInterval
(()
=>
{
requesting
.
get
({
// api를 요청할 주소 -- 시크릿키,위도,경도 입력
url
:
`https://api2.sktelecom.com/weather/current/minutely?appKey=
${
secret_key
}
&lat=37.239795&lon=127.083240`
,
json
:
true
},
//api에게 응답 받았을때 실행되는 callback func
function
(
err
,
api_res
,
api_body
)
{
if
(
err
)
throw
err
;
// api의 대답이 있을경우 실행
if
(
api_res
)
{
const
sql
=
`INSERT INTO dataset (question,option_1,option_2,option_3,option_4,answer,user_id) VALUES (?,?,?,?,?,?,?)`
;
db
.
query
(
sql
,
[
question
,
option
[
0
],
option
[
1
],
option
[
2
],
option
[
3
],
machine_body
.
answer
,
user_id
],
function
(
err
,
result
)
{
if
(
err
)
throw
err
;
console
.
log
(
"dataset successfully inserted into DB"
)
});
return
response
.
send
(
{
answer
:
machine_body
.
answer
}
);
}
});
},
60
*
1000
);
//1분마다 호출
io
.
on
(
'connection'
,
(
socket
)
=>
{
//네임스페이스 연결시 루프 동작
io
.
on
(
'connection'
,
(
socket
)
=>
{
//웹 페이지 연결시 루프 동작
socket
.
on
(
'disconnecting'
,
(
reason
)
=>
{
clearInterval
(
API_CALL
);
//연결 종료시 해제
})
socket
.
on
(
"connection"
,
(
roomnum
)
=>
{
//방 접속시에 현재 방번호 room에 저장
socket
.
on
(
"connection"
,
(
roomnum
)
=>
{
API_CALL
();
})
})
...
...
Please
register
or
login
to post a comment