Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
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
luna
Commits
bef93b03
Commit
bef93b03
authored
Jul 18, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改ws
parent
cc142833
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
61 deletions
+36
-61
ssh-term.component.ts
src/app/elements/ssh-term/ssh-term.component.ts
+34
-33
control.component.ts
src/app/pages/control/control/control.component.ts
+1
-0
socket.ts
src/app/utils/socket.ts
+1
-28
No files found.
src/app/elements/ssh-term/ssh-term.component.ts
View file @
bef93b03
import
{
AfterViewInit
,
Component
,
Input
,
OnInit
,
OnDestroy
}
from
'@angular/core'
;
import
{
Terminal
}
from
'xterm'
;
import
{
NavList
}
from
'../../pages/control/control/control.component'
;
import
{
NavList
,
View
}
from
'../../pages/control/control/control.component'
;
import
{
UUIDService
}
from
'../../app.service'
;
import
{
CookieService
}
from
'ngx-cookie-service'
;
import
{
Socket
,
Room
}
from
'../../utils/socket'
;
import
{
Socket
}
from
'../../utils/socket'
;
import
{
getWsSocket
}
from
'../../globals'
;
...
...
@@ -21,19 +21,26 @@ export class ElementSshTermComponent implements OnInit, AfterViewInit, OnDestroy
term
:
Terminal
;
secret
:
string
;
ws
:
Socket
;
room
:
Room
;
roomID
:
string
;
view
:
View
;
constructor
(
private
_uuid
:
UUIDService
,
private
_cookie
:
CookieService
)
{
}
ngOnInit
()
{
this
.
view
=
NavList
.
List
[
this
.
index
];
this
.
secret
=
this
.
_uuid
.
gen
();
this
.
newTerm
();
getWsSocket
().
then
(
sock
=>
{
this
.
ws
=
sock
;
console
.
log
(
'Connect ok'
);
console
.
log
(
this
.
ws
);
this
.
joinRoom
();
this
.
connectHost
();
});
}
ngAfterViewInit
()
{
}
newTerm
()
{
const
fontSize
=
localStorage
.
getItem
(
'fontSize'
)
||
'14'
;
this
.
term
=
new
Terminal
({
fontFamily
:
'monaco, Consolas, "Lucida Console", monospace'
,
...
...
@@ -43,9 +50,7 @@ export class ElementSshTermComponent implements OnInit, AfterViewInit, OnDestroy
background
:
'#1f1b1b'
}
});
}
ngAfterViewInit
()
{
this
.
view
.
Term
=
this
.
term
;
}
changeWinSize
(
size
:
Array
<
number
>
)
{
...
...
@@ -54,8 +59,7 @@ export class ElementSshTermComponent implements OnInit, AfterViewInit, OnDestroy
}
}
joinRoom
()
{
NavList
.
List
[
this
.
index
].
Term
=
this
.
term
;
connectHost
()
{
if
(
this
.
host
)
{
const
data
=
{
uuid
:
this
.
host
.
id
,
...
...
@@ -72,50 +76,47 @@ export class ElementSshTermComponent implements OnInit, AfterViewInit, OnDestroy
};
this
.
ws
.
emit
(
'token'
,
data
);
}
const
that
=
this
;
this
.
term
.
on
(
'data'
,
data
=>
{
const
d
=
{
'data'
:
data
};
this
.
room
.
emit
(
'data'
,
d
);
const
d
=
{
'data'
:
data
,
'room'
:
this
.
roomID
};
this
.
ws
.
emit
(
'data'
,
d
);
});
this
.
ws
.
on
(
'data'
,
(
roomName
,
msg
)
=>
{
this
.
ws
.
on
(
'data'
,
(
msg
)
=>
{
const
data
=
msg
.
unmarshal
();
const
view
=
NavList
.
List
[
that
.
index
];
if
(
view
&&
roomName
===
view
.
room
)
{
that
.
term
.
write
(
data
[
'data'
]);
if
(
data
.
room
===
this
.
roomID
)
{
this
.
term
.
write
(
data
[
'data'
]);
}
});
// 服务器主动断开
this
.
ws
.
on
(
'disconnect'
,
()
=>
{
th
at
.
close
();
th
is
.
close
();
});
this
.
ws
.
on
(
'logout'
,
(
roomName
,
msg
)
=>
{
this
.
ws
.
on
(
'logout'
,
(
msg
)
=>
{
const
data
=
msg
.
unmarshal
();
if
(
data
.
room
===
NavList
.
List
[
that
.
index
].
room
)
{
NavList
.
List
[
that
.
index
].
connected
=
false
;
if
(
data
.
room
===
this
.
roomID
)
{
console
.
log
(
'On logout: '
,
data
.
room
,
this
.
roomID
);
this
.
view
.
connected
=
false
;
}
});
this
.
ws
.
on
(
'room'
,
(
roomName
,
msg
)
=>
{
this
.
ws
.
on
(
'room'
,
(
msg
)
=>
{
const
data
=
msg
.
unmarshal
();
console
.
log
(
'On room'
,
roomName
,
data
);
if
(
data
.
secret
===
this
.
secret
&&
data
.
room
)
{
this
.
ws
.
JoinRoom
(
data
.
room
).
then
(
room
=>
{
this
.
room
=
room
;
});
NavList
.
List
[
that
.
index
].
room
=
data
.
room
;
console
.
log
(
'On room'
,
data
);
this
.
roomID
=
data
.
room
;
this
.
view
.
room
=
data
.
room
;
}
});
}
// 客户端主动关闭
close
()
{
const
view
=
NavList
.
List
[
this
.
index
];
if
(
view
)
{
NavList
.
List
[
this
.
index
].
connected
=
false
;
console
.
log
(
NavList
.
List
[
this
.
index
].
room
);
this
.
room
.
emit
(
'logout'
,
{
'room'
:
NavList
.
List
[
this
.
index
].
room
});
if
(
this
.
view
&&
(
this
.
view
.
room
===
this
.
roomID
))
{
this
.
view
.
connected
=
false
;
this
.
ws
.
emit
(
'logout'
,
{
'room'
:
this
.
roomID
});
}
}
...
...
src/app/pages/control/control/control.component.ts
View file @
bef93b03
...
...
@@ -52,6 +52,7 @@ export class ControlComponent implements OnInit {
if
(
NavList
.
List
[
id
].
connected
)
{
NavList
.
List
[
id
].
connected
=
false
;
NavList
.
List
[
id
].
Term
.
write
(
'
\
r
\
n
\
x1b[31mBye Bye!
\
x1b[m
\
r
\
n'
);
console
.
log
(
'Terminal disconn'
)
TermWS
.
emit
(
'logout'
,
{
room
:
NavList
.
List
[
id
].
room
});
}
}
...
...
src/app/utils/socket.ts
View file @
bef93b03
...
...
@@ -2,18 +2,6 @@ import {EventEmitter} from 'events/events';
import
{
NSConn
,
marshal
}
from
'neffos.js'
;
import
*
as
neffos
from
'neffos.js'
;
export
class
Room
{
room
:
neffos
.
Room
;
constructor
(
room
:
neffos
.
Room
)
{
this
.
room
=
room
;
}
emit
(
event
:
string
,
obj
:
object
):
boolean
{
const
msg
=
marshal
(
obj
);
return
this
.
room
.
emit
(
event
,
msg
);
}
}
export
class
Socket
{
conn
:
NSConn
;
...
...
@@ -32,21 +20,6 @@ export class Socket {
on
(
type
:
string
,
fn
:
Function
,
opt_scope
?:
any
,
opt_oneshot
?:
boolean
)
{
this
.
emitter
.
on
(
type
,
fn
,
opt_scope
,
opt_oneshot
);
}
async
JoinRoom
(
roomName
:
string
):
Promise
<
Room
>
{
console
.
log
(
'Join room: '
,
roomName
);
const
room
=
await
this
.
conn
.
joinRoom
(
roomName
);
const
wrapper
=
new
Room
(
room
);
return
wrapper
;
}
getRoom
(
roomName
:
string
)
{
const
room
=
this
.
conn
.
rooms
[
roomName
];
if
(
room
)
{
return
new
Room
(
room
);
}
return
null
;
}
}
export
async
function
getWsSock
(
url
:
string
,
namespace
:
string
):
Promise
<
Socket
>
{
...
...
@@ -70,7 +43,7 @@ export async function getWsSock(url: string, namespace: string): Promise<Socket>
},
_OnAnyEvent
:
function
(
ns
,
msg
)
{
emitter
.
emit
(
msg
.
Event
,
msg
.
Room
,
msg
);
emitter
.
emit
(
msg
.
Event
,
msg
);
}
};
const
options
=
{
reconnnect
:
5
};
...
...
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