resp←WebSocketSample args;title;html;obj;ev;wsid;url;data;type;fin;reason;code;fn;show;⎕ML;⎕IO
⍝ general websocket test framework
⍝ use this function in conjunction with ∇Send
⎕ML←⎕IO←1
show←{n←' '(≠⊆⊢)⍺ ⋄ n,⍪{len←≢⍵ ⋄ ↑⍕{⍵⊆⍨~⍵∊⎕UCS 13 10}{(⍕len),'⍴',(200↑⍵),'...'}⍣(200
⍝
⍝
⍝
⍝ WebSocket Sample
⍝
⍝
⍝
⍝
⍝
⍝
⍝
WebSocket Sample
⍝
⍝
⍝
⍝
⍝
⍝
⍝
⍝
⍝
⍝
⍝
⍝
⍝ Click "Open" to create the WebSocket.
⍝ To send to APL, type something in the input area and click "Send"
⍝ To send from APL, in the APL session, use the "Send" function
⍝ Send 'this is a test!'
⍝
⍝
⍝
⍝
⍝
⍝
⍝
⍝
EndHTML:
html←'HTML'(1↓∊(⎕UCS 13),¨{⍵↓⍨⍵⍳'⍝'}¨StartHTML↓EndHTML↑⎕NR fn←⊃⎕XSI)
:If 0∊⍴args
'hr'⎕WC'HTMLRenderer'html('Event' 'All'fn)('InterceptedURLs'(1 2⍴'ws://dyalog_root/' 1))
hr.ShowDevTools 1
:Else
:Select 2⊃args
:Case 'WebSocketUpgrade'
⎕←'obj ev wsid url hdr auto'show args
(obj ev wsid url)←4↑args
resp←args
StartCode:→EndCode
⍝ Send parms;msg;type;segs
⍝ ⍝ send data to currently open HTMLRenderer/websocket
⍝ ⍝ parms [1] msg [2] datatype (1-text, 2-bin)
⍝ (msg type)←'' 0{(≢⍺)↑⍵,(≢⍵)↓⍺},⊆parms
⍝ 2 ⎕NQ _hr 'WebSocketSend' _wsid msg 1 ((1+type=0)⊃type,1+(⎕DR'')≠⎕DR msg)
EndCode: ' function defined',⍨⎕FX('_hr' '_wsid'⎕R('''',obj,'''')('''',wsid,'''')){⍵↓⍨⍵⍳'⍝'}¨(1+StartCode)↓EndCode↑⎕NR fn
:Case 'WebSocketReceive'
⎕←'obj ev wsid data type fin'show args
(obj ev wsid data type fin)←args
:Case 'WebSocketClose'
⎕←'obj ev wsid code reason'show args
(obj ev wsid code reason)←args
:Case 'WebSocketError'
⎕←'obj ev wsid'show args
:EndSelect
:EndIf