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($){
...
@@ -30,12 +30,18 @@ jQuery(function($){
}
}
wssh
.
window_size
=
function
()
{
wssh
.
window_geometry
=
function
()
{
var
geo
=
current_geometry
();
// for console use
console
.
log
(
'Current window size: '
+
geo
.
cols
+
','
+
geo
.
rows
);
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
)
{
function
callback
(
msg
)
{
// console.log(msg);
// console.log(msg);
if
(
msg
.
status
)
{
if
(
msg
.
status
)
{
...
@@ -67,7 +73,32 @@ jQuery(function($){
...
@@ -67,7 +73,32 @@ jQuery(function($){
term
.
on_resize
(
geometry
.
cols
,
geometry
.
rows
);
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
)
{
wssh
.
set_encoding
=
function
(
new_encoding
)
{
// for console use
if
(
new_encoding
===
undefined
)
{
return
;
}
try
{
try
{
test_decoder
=
new
window
.
TextDecoder
(
new_encoding
);
test_decoder
=
new
window
.
TextDecoder
(
new_encoding
);
}
catch
(
TypeError
)
{
}
catch
(
TypeError
)
{
...
@@ -82,12 +113,18 @@ jQuery(function($){
...
@@ -82,12 +113,18 @@ jQuery(function($){
};
};
wssh
.
reset_encoding
=
function
()
{
wssh
.
reset_encoding
=
function
()
{
// for console use
encoding
=
msg
.
encoding
;
encoding
=
msg
.
encoding
;
console
.
log
(
'Reset encoding to '
+
msg
.
encoding
);
console
.
log
(
'Reset encoding to '
+
msg
.
encoding
);
};
};
wssh
.
resize_terminal
=
function
(
raw_cols
,
raw_rows
)
{
wssh
.
resize_terminal
=
function
(
raw_cols
,
raw_rows
)
{
// for console use
// for console use
if
(
term
===
undefined
)
{
console
.
log
(
'Terminal was already destroryed'
);
return
;
}
var
cols
=
parseInt
(
raw_cols
,
10
),
var
cols
=
parseInt
(
raw_cols
,
10
),
rows
=
parseInt
(
raw_rows
,
10
),
rows
=
parseInt
(
raw_rows
,
10
),
valid_args
=
false
;
valid_args
=
false
;
...
@@ -100,15 +137,16 @@ jQuery(function($){
...
@@ -100,15 +137,16 @@ jQuery(function($){
}
}
if
(
!
valid_args
)
{
if
(
!
valid_args
)
{
console
.
log
(
'
Invalid arguments: '
+
raw_cols
+
','
+
raw_rows
);
console
.
log
(
'
Unable to resize terminal to geometry: '
+
format_geometry
(
cols
,
rows
)
);
}
else
{
}
else
{
term
.
on_resize
(
cols
,
rows
);
term
.
on_resize
(
cols
,
rows
);
}
}
};
};
term
.
on_resize
=
function
(
cols
,
rows
)
{
term
.
on_resize
=
function
(
cols
,
rows
)
{
if
(
cols
!==
this
.
geometry
[
0
]
||
rows
!==
this
.
geometry
[
1
])
{
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
);
this
.
resize
(
cols
,
rows
);
sock
.
send
(
JSON
.
stringify
({
'resize'
:
[
cols
,
rows
]}));
sock
.
send
(
JSON
.
stringify
({
'resize'
:
[
cols
,
rows
]}));
}
}
...
@@ -132,10 +170,12 @@ jQuery(function($){
...
@@ -132,10 +170,12 @@ jQuery(function($){
var
decoder
=
new
window
.
TextDecoder
(
encoding
);
var
decoder
=
new
window
.
TextDecoder
(
encoding
);
var
text
=
decoder
.
decode
(
reader
.
result
);
var
text
=
decoder
.
decode
(
reader
.
result
);
// console.log(text);
// console.log(text);
term
.
write
(
text
);
if
(
term
)
{
if
(
!
term
.
resized
)
{
term
.
write
(
text
);
resize_terminal
(
term
);
if
(
!
term
.
resized
)
{
term
.
resized
=
true
;
resize_terminal
(
term
);
term
.
resized
=
true
;
}
}
}
};
};
...
@@ -149,13 +189,17 @@ jQuery(function($){
...
@@ -149,13 +189,17 @@ jQuery(function($){
sock
.
onclose
=
function
(
e
)
{
sock
.
onclose
=
function
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
term
.
destroy
();
term
.
destroy
();
term
=
undefined
;
sock
=
undefined
;
$
(
'.container'
).
show
();
$
(
'.container'
).
show
();
status
.
text
(
e
.
reason
);
status
.
text
(
e
.
reason
);
btn
.
prop
(
'disabled'
,
false
);
btn
.
prop
(
'disabled'
,
false
);
};
};
$
(
window
).
resize
(
function
(){
$
(
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