|
97 | 97 | "Start the REPL server connection."
|
98 | 98 | [url]
|
99 | 99 | (if-let [repl-connection (net/xpc-connection)]
|
100 |
| - (let [connection (net/xhr-connection)] |
| 100 | + (let [connection (net/xhr-connection) |
| 101 | + repl-connected? (atom false) |
| 102 | + try-handshake (fn try-handshake [] |
| 103 | + (when-not @repl-connected? |
| 104 | + (net/transmit repl-connection |
| 105 | + :start-handshake |
| 106 | + nil) |
| 107 | + ;; In case we miss, try again. Parent will only |
| 108 | + ;; ack once. |
| 109 | + (js/setTimeout try-handshake |
| 110 | + 10)))] |
| 111 | + (net/connect repl-connection |
| 112 | + try-handshake) |
| 113 | + |
| 114 | + (net/register-service repl-connection |
| 115 | + :ack-handshake |
| 116 | + (fn [_] |
| 117 | + (when-not @repl-connected? |
| 118 | + (reset! repl-connected? true) |
| 119 | + ;; Now that we're connected to the parent, we can start talking to |
| 120 | + ;; the server. |
| 121 | + (send-result connection |
| 122 | + url |
| 123 | + (wrap-message :ready "ready"))))) |
| 124 | + |
101 | 125 | (event/listen connection
|
102 | 126 | :success
|
103 | 127 | (fn [e]
|
|
115 | 139 | (net/register-service repl-connection
|
116 | 140 | :print
|
117 | 141 | (fn [data]
|
118 |
| - (send-print url (wrap-message :print data)))) |
119 |
| - |
120 |
| - (net/connect repl-connection |
121 |
| - (constantly nil)) |
122 |
| - |
123 |
| - (js/setTimeout #(send-result connection url (wrap-message :ready "ready")) 1000)) |
| 142 | + (send-print url (wrap-message :print data))))) |
124 | 143 | (js/alert "No 'xpc' param provided to child iframe.")))
|
125 | 144 |
|
126 | 145 | (def load-queue nil)
|
|
189 | 208 | connection is made, the REPL will evaluate forms in the context of
|
190 | 209 | the document that called this function."
|
191 | 210 | [repl-server-url]
|
192 |
| - (let [repl-connection |
| 211 | + (let [connected? (atom false) |
| 212 | + repl-connection |
193 | 213 | (net/xpc-connection
|
194 | 214 | {:peer_uri repl-server-url})]
|
195 | 215 | (swap! xpc-connection (constantly repl-connection))
|
| 216 | + (net/register-service repl-connection |
| 217 | + :start-handshake |
| 218 | + (fn [_] |
| 219 | + ;; Child will keep retrying, but we only want |
| 220 | + ;; to ack once. |
| 221 | + (when-not @connected? |
| 222 | + (reset! connected? true) |
| 223 | + (net/transmit repl-connection |
| 224 | + :ack-handshake |
| 225 | + nil)))) |
196 | 226 | (net/register-service repl-connection
|
197 | 227 | :evaluate-javascript
|
198 | 228 | (fn [js]
|
|
0 commit comments