Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cuttlefish
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
squidworks
cuttlefish
Commits
305e98e8
Commit
305e98e8
authored
5 years ago
by
Jake Read
Browse files
Options
Downloads
Patches
Plain Diff
nice pipe template
parent
06394575
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
cf.js
+6
-1
6 additions, 1 deletion
cf.js
hunks/pipes/pipetemplate.js
+55
-10
55 additions, 10 deletions
hunks/pipes/pipetemplate.js
pipes/pipetemplate.js
+17
-1
17 additions, 1 deletion
pipes/pipetemplate.js
with
78 additions
and
12 deletions
cf.js
+
6
−
1
View file @
305e98e8
...
...
@@ -79,6 +79,7 @@ app.post('/save/systems/:file', (req, res) => {
// we also want to institute some pipes: this is a holdover for a better system
// more akin to nautilus, where server-side graphs are manipulated
// for now, we just want to dive down to a usb port, probably, so this shallow link is OK
let
workers
=
[]
app
.
get
(
'
/pipeHookup/:file
'
,
(
req
,
res
)
=>
{
// we can assume that the file is a reciprocal pipe-type in our local pipes/file.js location
// we'll open that can as a spawn, can assume it's hosting a websocket (it will tell us the port?)
...
...
@@ -98,7 +99,11 @@ app.get('/pipeHookup/:file', (req, res) => {
console
.
log
(
'
worker err
'
,
err
)
})
piper
.
on
(
'
exit
'
,
(
code
)
=>
{
console
.
log
(
'
worker exit code
'
,
code
)
if
(
code
!==
0
){
console
.
log
(
'
worker exist with nonzero code
'
,
code
)
}
else
{
console
.
log
(
'
worker exits OK
'
)
}
})
// then this (or similar) should be all we really need to add here, and we can do local-dev of the pipes in hunks/pipes/pipename.js and pipes/pipename.js
// so, do we spawn, or do we use workers ?
...
...
This diff is collapsed.
Click to expand it.
hunks/pipes/pipetemplate.js
+
55
−
10
View file @
305e98e8
...
...
@@ -12,23 +12,44 @@ import {
State
}
from
'
../hunks.js
'
const
STATUS_OPENING
=
'
opening...
'
const
STATUS_OPEN
=
'
open
'
const
STATUS_CLOSED
=
'
closed
'
const
STATUS_ERROR
=
'
error
'
export
default
function
Pipe
()
{
Hunkify
(
this
)
let
debug
=
tru
e
let
debug
=
fals
e
let
statusMessage
=
new
State
(
'
string
'
,
'
status
'
,
'
closed
'
)
let
statusMessage
=
new
State
(
'
string
'
,
'
status
'
,
STATUS_CLOSED
)
let
retryButton
=
new
State
(
'
boolean
'
,
'
retry
'
,
false
)
this
.
states
.
push
(
statusMessage
,
retryButton
)
let
echoButton
=
new
State
(
'
boolean
'
,
'
echo
'
,
false
)
this
.
states
.
push
(
statusMessage
,
retryButton
,
echoButton
)
retryButton
.
onChange
=
(
value
)
=>
{
startWsConnection
()
}
echoButton
.
onChange
=
(
value
)
=>
{
send
(
JSON
.
stringify
({
type
:
'
echo
'
}))
}
// coming merge of init and onload, however:
this
.
init
=
()
=>
{
// force closed at startup; else program state can make us confused,
statusMessage
.
set
(
STATUS_CLOSED
)
startWsConnection
()
}
let
ws
=
{}
// I think this is nearly there, just need to test the reset button
// and check that it is 'onchange' not 'change' ... ? write that down ?
// and then hide this hunk with the list-getter ... then vfpt
let
startWsConnection
=
()
=>
{
// hijack ajax to ask for a websocket
// only attempt reconnect if we're not already opening, or opened
if
(
statusMessage
.
value
===
STATUS_OPEN
||
statusMessage
.
value
===
STATUS_OPENING
)
return
// ask the server to instantiate the reciprocal process,
statusMessage
.
set
(
STATUS_OPENING
)
jQuery
.
get
(
'
pipeHookup/pipetemplate.js
'
,
(
data
)
=>
{
if
(
data
.
startup
)
{
console
.
log
(
'
serverside launched, starting client
'
)
...
...
@@ -36,22 +57,46 @@ export default function Pipe() {
// have data.ip and data.port
ws
=
new
WebSocket
(
`ws://
${
data
.
ip
}
:
${
data
.
port
}
`
)
ws
.
onopen
=
(
evt
)
=>
{
console
.
log
(
'
vfpt opens
'
,
evt
)
if
(
debug
)
console
.
log
(
this
.
name
,
'
opens
'
)
statusMessage
.
set
(
STATUS_OPEN
)
}
ws
.
onerror
=
(
evt
)
=>
{
console
.
log
(
'
vfpt error
'
,
evt
)
ws
.
onerror
=
(
err
)
=>
{
if
(
debug
)
console
.
log
(
this
.
name
,
'
error
'
,
err
)
statusMessage
.
set
(
STATUS_ERROR
)
}
ws
.
onclose
=
(
evt
)
=>
{
console
.
log
(
'
vfpt close
'
,
evt
)
if
(
debug
)
console
.
log
(
this
.
name
,
'
closes
'
)
statusMessage
.
set
(
STATUS_CLOSED
)
}
ws
.
onmessage
=
(
msg
)
=>
{
console
.
log
(
'
vfpt recv
'
,
msg
)
if
(
debug
)
console
.
log
(
this
.
name
,
'
recvs
'
,
msg
)
recv
(
msg
)
}
}
else
{
console
.
log
(
'
pipe received non-startup response from server
'
)
statusMessage
.
set
(
STATUS_ERROR
)
}
})
}
// write ur handler,
let
recv
=
(
msg
)
=>
{
let
data
=
JSON
.
parse
(
msg
.
data
)
console
.
log
(
'
pipe template recvs in placeholder
'
,
data
)
}
// send wrapper
let
send
=
(
msg
)
=>
{
if
(
ws
&&
ws
.
readyState
===
1
)
{
ws
.
send
(
msg
)
return
true
}
else
{
console
.
error
(
'
attempt to send on a closed ws
'
)
return
false
}
}
this
.
loop
=
()
=>
{
//
ws status, ws messages ...
//
handle your io
}
}
This diff is collapsed.
Click to expand it.
pipes/pipetemplate.js
+
17
−
1
View file @
305e98e8
...
...
@@ -14,5 +14,21 @@ const WSS = new WebSocketServer({port: port}, () => {
WSS
.
on
(
'
connection
'
,
(
ws
)
=>
{
console
.
log
(
'
ws connects
'
)
// ...
ws
.
onmessage
=
(
msg
)
=>
{
// always .data is what we sent,
let
data
=
JSON
.
parse
(
msg
.
data
)
// the template-writer will want to update these ...
if
(
data
.
type
===
'
echo
'
){
console
.
log
(
'
msg echo
'
,
msg
.
data
)
ws
.
send
(
msg
.
data
)
}
else
{
console
.
log
(
'
msg non echo
'
)
console
.
log
(
msg
.
data
)
}
}
ws
.
onclose
=
(
evt
)
=>
{
// shutdown,
console
.
log
(
'
ws closes, pipe exiting
'
)
process
.
exit
()
}
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment