Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
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
ops
coco
Commits
737b46f3
Commit
737b46f3
authored
Jul 19, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 修复session串行的问题
parent
c31b22d4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
28 deletions
+32
-28
httpd.py
coco/httpd.py
+32
-28
No files found.
coco/httpd.py
View file @
737b46f3
...
...
@@ -69,19 +69,23 @@ class ProxyNamespace(BaseNamespace):
def
new_connection
(
self
):
self
.
connections
[
request
.
sid
]
=
dict
()
def
new_room
(
self
,
req
=
None
):
def
new_room
(
self
,
current_user
,
cols
=
80
,
rows
=
24
):
room_id
=
str
(
uuid
.
uuid4
())
req
=
self
.
make_coco_request
(
current_user
,
cols
=
cols
,
rows
=
rows
)
room
=
{
"id"
:
room_id
,
"proxy"
:
None
,
"client"
:
None
,
"forwarder"
:
None
,
"request"
:
req
,
"cols"
:
cols
,
"rows"
:
rows
}
self
.
connections
[
request
.
sid
][
room_id
]
=
room
return
room
def
make_coco_request
(
self
,
cols
=
80
,
rows
=
24
):
@staticmethod
def
make_coco_request
(
user
,
cols
=
80
,
rows
=
24
):
x_forwarded_for
=
request
.
headers
.
get
(
"X-Forwarded-For"
,
''
)
.
split
(
','
)
if
x_forwarded_for
and
x_forwarded_for
[
0
]:
remote_ip
=
x_forwarded_for
[
0
]
...
...
@@ -89,11 +93,8 @@ class ProxyNamespace(BaseNamespace):
remote_ip
=
request
.
remote_addr
req
=
Request
((
remote_ip
,
0
))
req
.
user
=
self
.
current_user
req
.
meta
=
{
"width"
:
cols
,
"height"
:
rows
,
}
req
.
user
=
user
req
.
meta
=
{
"width"
:
cols
,
"height"
:
rows
}
return
req
def
on_connect
(
self
):
...
...
@@ -104,21 +105,23 @@ class ProxyNamespace(BaseNamespace):
def
on_host
(
self
,
message
):
# 此处获取主机的信息
logger
.
debug
(
"On host event trigger"
)
current_user
=
self
.
get_current_user
()
self
.
connect_host
(
current_user
,
message
)
def
connect_host
(
self
,
current_user
,
message
):
asset_id
=
message
.
get
(
'uuid'
,
None
)
user_id
=
message
.
get
(
'userid'
,
None
)
system_
user_id
=
message
.
get
(
'userid'
,
None
)
secret
=
message
.
get
(
'secret'
,
None
)
self
.
win_size
=
message
.
get
(
'size'
,
(
80
,
24
))
req
=
self
.
make_coco_request
(
*
self
.
win_size
)
room
=
self
.
new_room
(
req
)
cols
,
rows
=
message
.
get
(
'size'
,
(
80
,
24
))
room
=
self
.
new_room
(
current_user
,
cols
=
cols
,
rows
=
rows
)
self
.
emit
(
'room'
,
{
'room'
:
room
[
"id"
],
'secret'
:
secret
})
join_room
(
room
[
"id"
])
if
not
asset_id
or
not
user_id
:
if
not
asset_id
or
not
system_
user_id
:
return
asset
=
app_service
.
get_asset
(
asset_id
)
system_user
=
app_service
.
get_system_user
(
user_id
)
system_user
=
app_service
.
get_system_user
(
system_
user_id
)
if
not
asset
or
not
system_user
:
return
...
...
@@ -149,10 +152,10 @@ class ProxyNamespace(BaseNamespace):
# 此处获取token含有的主机的信息
logger
.
debug
(
"On token trigger"
)
token
=
message
.
get
(
'token'
,
None
)
secret
=
message
.
get
(
'secret'
,
None
)
secret
=
message
.
get
(
"secret"
,
None
)
win_size
=
message
.
get
(
'size'
,
(
80
,
24
))
room
=
self
.
new_room
()
room
=
self
.
new_room
(
None
)
self
.
emit
(
'room'
,
{
'room'
:
room
[
"id"
],
'secret'
:
secret
})
join_room
(
room
[
'id'
])
...
...
@@ -173,27 +176,28 @@ class ProxyNamespace(BaseNamespace):
return
None
user_id
=
info
.
get
(
'user'
,
None
)
self
.
current_user
=
app_service
.
get_user_profile
(
user_id
)
# room["request"].user = self.current_user
self
.
on_host
({
current_user
=
app_service
.
get_user_profile
(
user_id
)
message
=
{
'secret'
:
secret
,
'uuid'
:
info
[
'asset'
],
'userid'
:
info
[
'system_user'
],
'size'
:
win_size
,
})
}
self
.
connect_host
(
current_user
,
message
)
def
on_resize
(
self
,
message
):
cols
,
rows
=
message
.
get
(
'cols'
,
None
),
message
.
get
(
'rows'
,
None
)
logger
.
debug
(
"On resize event trigger: {}*{}"
.
format
(
cols
,
rows
))
rooms
=
self
.
connections
.
get
(
request
.
sid
,
{})
if
self
.
win_size
!=
(
cols
,
rows
):
logger
.
debug
(
"Start change win size: {}*{}"
.
format
(
cols
,
rows
))
for
room
in
rooms
.
values
():
room
[
"request"
]
.
meta
.
update
({
'width'
:
cols
,
'height'
:
rows
})
room
[
"request"
]
.
change_size_event
.
set
()
room
.
update
({
"cols"
:
cols
,
"rows"
:
rows
})
logger
.
debug
(
"Start change win size: {}*{}"
.
format
(
cols
,
rows
))
for
room
in
rooms
.
values
():
if
(
room
[
"cols"
],
room
[
"rows"
])
==
(
cols
,
rows
):
continue
room
[
"request"
]
.
meta
.
update
({
'width'
:
cols
,
'height'
:
rows
})
room
[
"request"
]
.
change_size_event
.
set
()
room
.
update
({
"cols"
:
cols
,
"rows"
:
rows
})
def
on_disconnect
(
self
):
logger
.
debug
(
"On disconnect event trigger"
)
...
...
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