Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
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
郑天保
webssh
Commits
38cb22ac
Commit
38cb22ac
authored
Aug 21, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more functions to wssh
parent
4ae2a336
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
10 deletions
+54
-10
main.js
webssh/static/js/main.js
+54
-10
No files found.
webssh/static/js/main.js
View file @
38cb22ac
...
...
@@ -30,12 +30,18 @@ jQuery(function($){
}
wssh
.
window_size
=
function
()
{
var
geo
=
current_geometry
();
console
.
log
(
'Current window size: '
+
geo
.
cols
+
','
+
geo
.
rows
);
wssh
.
window_geometry
=
function
()
{
// for console use
var
geometry
=
current_geometry
();
console
.
log
(
'Current window geometry: '
+
JSON
.
stringify
(
geometry
));
};
function
format_geometry
(
cols
,
rows
)
{
return
JSON
.
stringify
({
'cols'
:
cols
,
'rows'
:
rows
});
}
function
callback
(
msg
)
{
// console.log(msg);
if
(
msg
.
status
)
{
...
...
@@ -67,7 +73,32 @@ jQuery(function($){
term
.
on_resize
(
geometry
.
cols
,
geometry
.
rows
);
}
wssh
.
websocket_send
=
function
(
data
)
{
// for console use
if
(
!
sock
)
{
console
.
log
(
'Websocket was already closed'
);
return
;
}
if
(
typeof
data
!==
'string'
)
{
console
.
log
(
'Only string is allowed'
);
return
;
}
try
{
JSON
.
parse
(
data
);
sock
.
send
(
data
);
}
catch
(
SyntaxError
)
{
sock
.
send
(
JSON
.
stringify
({
'data'
:
data
}));
}
};
wssh
.
set_encoding
=
function
(
new_encoding
)
{
// for console use
if
(
new_encoding
===
undefined
)
{
return
;
}
try
{
test_decoder
=
new
window
.
TextDecoder
(
new_encoding
);
}
catch
(
TypeError
)
{
...
...
@@ -82,12 +113,18 @@ jQuery(function($){
};
wssh
.
reset_encoding
=
function
()
{
// for console use
encoding
=
msg
.
encoding
;
console
.
log
(
'Reset encoding to '
+
msg
.
encoding
);
};
wssh
.
resize_terminal
=
function
(
raw_cols
,
raw_rows
)
{
// for console use
if
(
term
===
undefined
)
{
console
.
log
(
'Terminal was already destroryed'
);
return
;
}
var
cols
=
parseInt
(
raw_cols
,
10
),
rows
=
parseInt
(
raw_rows
,
10
),
valid_args
=
false
;
...
...
@@ -100,15 +137,16 @@ jQuery(function($){
}
if
(
!
valid_args
)
{
console
.
log
(
'
Invalid arguments: '
+
raw_cols
+
','
+
raw_rows
);
console
.
log
(
'
Unable to resize terminal to geometry: '
+
format_geometry
(
cols
,
rows
)
);
}
else
{
term
.
on_resize
(
cols
,
rows
);
}
};
term
.
on_resize
=
function
(
cols
,
rows
)
{
if
(
cols
!==
this
.
geometry
[
0
]
||
rows
!==
this
.
geometry
[
1
])
{
console
.
log
(
'Resizing terminal
size to: '
+
cols
+
','
+
rows
);
console
.
log
(
'Resizing terminal
to geometry: '
+
format_geometry
(
cols
,
rows
)
);
this
.
resize
(
cols
,
rows
);
sock
.
send
(
JSON
.
stringify
({
'resize'
:
[
cols
,
rows
]}));
}
...
...
@@ -132,10 +170,12 @@ jQuery(function($){
var
decoder
=
new
window
.
TextDecoder
(
encoding
);
var
text
=
decoder
.
decode
(
reader
.
result
);
// console.log(text);
term
.
write
(
text
);
if
(
!
term
.
resized
)
{
resize_terminal
(
term
);
term
.
resized
=
true
;
if
(
term
)
{
term
.
write
(
text
);
if
(
!
term
.
resized
)
{
resize_terminal
(
term
);
term
.
resized
=
true
;
}
}
};
...
...
@@ -149,13 +189,17 @@ jQuery(function($){
sock
.
onclose
=
function
(
e
)
{
console
.
log
(
e
);
term
.
destroy
();
term
=
undefined
;
sock
=
undefined
;
$
(
'.container'
).
show
();
status
.
text
(
e
.
reason
);
btn
.
prop
(
'disabled'
,
false
);
};
$
(
window
).
resize
(
function
(){
resize_terminal
(
term
);
if
(
term
)
{
resize_terminal
(
term
);
}
});
}
...
...
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