SqueakJS WebSocket test passes; Flow, Lightning, Naiad to follow

Hoi–

Well, this is perverse fun. :) The JavaScript WebSocket client API works from SqueakJS, so I guess I’ll write a WebSocket server to proxy peer-to-peer traffic between SqueakJS clients. This will let me implement the Flow external streaming “primitive” interface, using only the JavaScript bridge and no actual primitives. That will enable the Lightning remote messaging protocol, and then Naiad. I’ll run the server on try.squeak.org and any other site that wants to be a Lightning node.

***

"Test the WebSocket API with an echo server."

| report websocket |

Transcript clear.

report := [:label :data |
   Transcript
   cr;
   nextPutAll: label;
   print: data;
   endEntry].

websocket := (
   (JS Object new)
      at: #newWebSocket
      put: (JS Function new: 'return new WebSocket("ws://echo.websocket.org");');
      newWebSocket).

websocket
   at: #onopen
   put: [:event |
      report value: 'opened: ' value: event.
      websocket send: 'hey there'];
   at: #onclose
   put: [:event | report value: 'closed: ' value: event];
   at: #onmessage
   put: [:event |
      report value: 'data: ' value: event data.
      websocket close];
   at: #onerror
   put: [:event | report value: 'error: ' value: event data]

***

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: