diff --git a/CHANGELOG.md b/CHANGELOG.md index 79c33abf..6defde58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Improve following current selected expression - Remove double scrolling in code panes - Make code stack pane jump a double-click + - Support multiple debugger instances running at the same time. Useful for debugging multiple build in cljs. ### Bugs fixed diff --git a/build.clj b/build.clj index a579f7b0..caed39ea 100644 --- a/build.clj +++ b/build.clj @@ -5,7 +5,7 @@ [clojure.spec.alpha :as s])) (def version (or (System/getenv "VERSION") - "3.8.6")) + "3.9.0")) (def target-dir "target") (def class-dir (str target-dir "/classes")) diff --git a/docs/user_guide.adoc b/docs/user_guide.adoc index 4e47e9b2..9f26b5ec 100644 --- a/docs/user_guide.adoc +++ b/docs/user_guide.adoc @@ -237,7 +237,7 @@ First, make your shadow-cljs.edn looks something like this : :http-port 8021}}}} ---- -So, the important parts are you need to tell shadow to apply your deps.edn dev alias, set up a nrepl port, +So, the important parts are: you need to tell shadow to apply your deps.edn dev alias, set up a nrepl port, and also add `flow-storm.storm-preload` to your preloads. If you have other preloads make sure `flow-storm.storm-preload` is the first one. @@ -269,15 +269,18 @@ It is important to configure what namespaces you want to instrument, and you do This is a comma separated list of namespaces prefixes, you normally want your app namespaces plus some libraries, like : `cljs.storm.instrumentOnlyPrefixes=org.my-app,org.my-lib,hiccup` -And this is it. Once you have it configured, run your shadow watch as you normally do, load your app on the browser (or nodejs) and -when your need it, run the debugger ui with your shadow-cljs.edn data : +And this is it. Once you have it configured, run your shadow watch as you normally do, load your app on the browser (or nodejs). + +Whenever your need the debugger, on a terminal run the ui with your shadow-cljs.edn data : [,bash] ---- clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port 9000 :repl-type :shadow :build-id :my-app ---- -Now since we started the app with `flowstorm.startRecording=false` you will have to click on the record button once to start recording. +and then reload you page so it connects to it. + +Since we started the app with `flowstorm.startRecording=false` you will have to click on the record button once to start recording. Whenever recording is enable and something executes under an instrumented namespace you should see the recordings appear in the debugger under the main thread. @@ -442,6 +445,83 @@ once it is connected. Here is a repo you can use if you want to try _FlowStorm_ with shadow-cljs https://github.com/flow-storm/shadow-flow-storm-basic +==== Multiple ClojureScript builds + +You can setup FlowStorm to debug multiple ClojureScript builds. This can be useful when your application is made up of multiple parts, +like when you have web workers. + +Debugging multiple builds require multiple debugger instances, one per build. + +The FlowStorm UI will start a websocket server, by default on 7722, so if you want to run multiple instances of it, you need +to run each instance under a different port. You can do this by providing a `:ws-port` to the startup command. + +So let's say you want to run two debuggers, one for your page and one for a webworker, your can run them like this : + +[,bash] +---- +# on one terminal start your app debugger instance +clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port 9000 :repl-type :shadow :build-id :my-app :ws-port 7722 + +# on a second terminal start your webworker debugger instance +clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port 9000 :repl-type :shadow :build-id :my-web-worker :ws-port 7733 +---- + +Now you also need to configure your builds to tell them what port they should connect to. +You do this by writing different preloads for each of your builds, and then using them instead of your `flow-storm.storm-preload`, like: + +`my_app.main_storm_preload.cljs` + +[,clojure] +---- +(ns my-app.main-storm-preload + (:require [cljs.storm.tracer] + [flow-storm.tracer :as tracer] + [flow-storm.runtime.debuggers-api :as dbg-api])) + +(tracer/hook-clojurescript-storm) +(dbg-api/setup-runtime) +(dbg-api/remote-connect {:debugger-ws-host "localhost" :debugger-ws-port 7722}) +---- + +`my_app.webworker_storm_preload.cljs` + +[,clojure] +---- +(ns my-app.webworker-storm-preload + (:require [cljs.storm.tracer] + [flow-storm.tracer :as tracer] + [flow-storm.runtime.debuggers-api :as dbg-api])) + +(tracer/hook-clojurescript-storm) +(dbg-api/setup-runtime) +(dbg-api/remote-connect {:debugger-ws-host "localhost" :debugger-ws-port 7733}) +---- + +They are the same as `flow-storm.storm-preload` just with different port numbers. + +Now you can configure your shadow-cljs.edn like this : +[,clojure] +---- +{... + :builds + {:app + {:target :browser + ... + :modules + {:my-app {:init-fn my.app/init + :preloads [my-app.main-storm-preload]} + :my-webworker {:init-fn my.app.worker/init + :preloads [my-app.webworker-storm-preload] + :web-worker true}}}}} +---- + +[NOTE] +.Multiple debuggers tips +==== +You can change the theme or customize the styles of different instances to make it easier to +know which debugger instance is connected to which application. +==== + === Babashka You can debug your babashka scripts with FlowStorm using the JVM. The process is quite simple. @@ -485,37 +565,37 @@ After the server has started, you can use the app from the browser and everythin == Remote debugging You can remotely debug any Clojure application the exposes a nrepl server. -You can do remote Clojure debugging in two ways (the same as local debugging), with and without _ClojureStorm_. -The debuggee side should be setup the same as a normal local setup with the optional change that you can use -`flow-storm-inst` instead of `flow-storm-dbg` being the former a slimmed down version of the later one that +In terms of dependencies, the debuggee side should be setup the same as a normal local setup, with the optional change that you can use +`flow-storm-inst` instead of `flow-storm-dbg`, being the former a slimmed down version of the later one that doesn't contain some libraries used only by the UI, but using the full `flow-storm-dbg` is also ok. -Once you have on your remote box your debuggee running and exposing a nrepl server you can connect to it by running : +The easiest way to debug a remote application is via a ssh tunnel. You can create it from your dev box like this : [,bash] ---- -clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port 9000 :runtime-host '"YOUR-REPL-IP-ADDRESS"' :debugger-host '"YOUR-IP-ADDRESS"' +ssh -L 9000:localhost:9000 -R 7722:localhost:7722 my-debuggee-box.com ---- -assuming your nrepl server is listening on port 9000. +assuming your remote process at my-debuggee-box.com has started a nrepl server listening on port 9000 and +that the debugger websocket server is running on the default port. -If your application is running in a different box you can also provide two extra keys : +After the tunnel is established, you can run you debugger UI like this : - - `:runtime-host` should be the ip of the debuggee (defaults to localhost) - - `:debugger-host` should be the ip where the debugger is running, since the debuggee needs to connect back to it (defaults to localhost)" +[,bash] +---- +clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port 9000 +---- -=== SSH tunnel +and that is it. -You can debug remote process through a ssh tunnel by creating a tunnel like this : +If you need to connect the debugger to a remote process without a ssh tunnel or you need to configure the websocket server port you can do it like this : [,bash] ---- -ssh -L 9000:localhost:9000 -R 7722:localhost:7722 my-debuggee-box.com +clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port NREPL-PORT :runtime-host '"YOUR-APP-BOX-IP-ADDRESS"' :debugger-host '"YOUR-BOX-IP-ADDRESS"' :ws-port WS-SERVER-PORT ---- -assuming your remote process at my-debuggee-box.com has started a nrepl server listening on port 9000. - === Docker If you run you process inside a docker container, here is a basic template for using _FlowStorm_ with it diff --git a/docs/user_guide.html b/docs/user_guide.html index 72725574..709efee6 100644 --- a/docs/user_guide.html +++ b/docs/user_guide.html @@ -674,6 +674,7 @@

FlowStorm debugger User’s Guide

  • ClojureScriptStorm with shadow-cljs
  • ClojureScriptStorm with cljs.main
  • ClojureScript vanilla FlowStorm
  • +
  • Multiple ClojureScript builds
  • 1.3. Babashka
  • @@ -681,8 +682,7 @@

    FlowStorm debugger User’s Guide

  • 2. Remote debugging
  • 3. Instrument code @@ -1162,7 +1162,7 @@
    -

    So, the important parts are you need to tell shadow to apply your deps.edn dev alias, set up a nrepl port, +

    So, the important parts are: you need to tell shadow to apply your deps.edn dev alias, set up a nrepl port, and also add flow-storm.storm-preload to your preloads. If you have other preloads make sure flow-storm.storm-preload is the first one.

    @@ -1199,8 +1199,10 @@
    -

    And this is it. Once you have it configured, run your shadow watch as you normally do, load your app on the browser (or nodejs) and -when your need it, run the debugger ui with your shadow-cljs.edn data :

    +

    And this is it. Once you have it configured, run your shadow watch as you normally do, load your app on the browser (or nodejs).

    + +
    +

    Whenever your need the debugger, on a terminal run the ui with your shadow-cljs.edn data :

    +
    +
    Multiple ClojureScript builds
    +
    +

    You can setup FlowStorm to debug multiple ClojureScript builds. This can be useful when your application is made up of multiple parts, +like when you have web workers.

    +
    +
    +

    Debugging multiple builds require multiple debugger instances, one per build.

    +
    +
    +

    The FlowStorm UI will start a websocket server, by default on 7722, so if you want to run multiple instances of it, you need +to run each instance under a different port. You can do this by providing a :ws-port to the startup command.

    +
    +
    +

    So let’s say you want to run two debuggers, one for your page and one for a webworker, your can run them like this :

    +
    +
    +
    +
    # on one terminal start your app debugger instance
    +clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port 9000 :repl-type :shadow :build-id :my-app :ws-port 7722
    +
    +# on a second terminal start your webworker debugger instance
    +clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port 9000 :repl-type :shadow :build-id :my-web-worker :ws-port 7733
    +
    +
    +
    +

    Now you also need to configure your builds to tell them what port they should connect to. +You do this by writing different preloads for each of your builds, and then using them instead of your flow-storm.storm-preload, like:

    +
    +
    +

    my_app.main_storm_preload.cljs

    +
    +
    +
    +
    (ns my-app.main-storm-preload
    +  (:require [cljs.storm.tracer]
    +            [flow-storm.tracer :as tracer]
    +            [flow-storm.runtime.debuggers-api :as dbg-api]))
    +
    +(tracer/hook-clojurescript-storm)
    +(dbg-api/setup-runtime)
    +(dbg-api/remote-connect {:debugger-ws-host "localhost" :debugger-ws-port 7722})
    +
    +
    +
    +

    my_app.webworker_storm_preload.cljs

    +
    +
    +
    +
    (ns my-app.webworker-storm-preload
    +  (:require [cljs.storm.tracer]
    +            [flow-storm.tracer :as tracer]
    +            [flow-storm.runtime.debuggers-api :as dbg-api]))
    +
    +(tracer/hook-clojurescript-storm)
    +(dbg-api/setup-runtime)
    +(dbg-api/remote-connect {:debugger-ws-host "localhost" :debugger-ws-port 7733})
    +
    +
    +
    +

    They are the same as flow-storm.storm-preload just with different port numbers.

    +
    +
    +

    Now you can configure your shadow-cljs.edn like this :

    +
    +
    +
    +
    {...
    + :builds
    + {:app
    +  {:target :browser
    +   ...
    +   :modules
    +   {:my-app {:init-fn my.app/init
    +           :preloads [my-app.main-storm-preload]}
    +    :my-webworker {:init-fn my.app.worker/init
    +                   :preloads [my-app.webworker-storm-preload]
    +                   :web-worker true}}}}}
    +
    +
    +
    + + + + + +
    +
    Note
    +
    +
    Multiple debuggers tips
    +
    +

    You can change the theme or customize the styles of different instances to make it easier to +know which debugger instance is connected to which application.

    +
    +
    +
    +

    1.3. Babashka

    @@ -1504,54 +1606,46 @@

    2. Remote debugging

    -

    You can remotely debug any Clojure application the exposes a nrepl server. -You can do remote Clojure debugging in two ways (the same as local debugging), with and without ClojureStorm.

    +

    You can remotely debug any Clojure application the exposes a nrepl server.

    -

    The debuggee side should be setup the same as a normal local setup with the optional change that you can use -flow-storm-inst instead of flow-storm-dbg being the former a slimmed down version of the later one that +

    In terms of dependencies, the debuggee side should be setup the same as a normal local setup, with the optional change that you can use +flow-storm-inst instead of flow-storm-dbg, being the former a slimmed down version of the later one that doesn’t contain some libraries used only by the UI, but using the full flow-storm-dbg is also ok.

    -

    Once you have on your remote box your debuggee running and exposing a nrepl server you can connect to it by running :

    +

    The easiest way to debug a remote application is via a ssh tunnel. You can create it from your dev box like this :

    -
    clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port 9000 :runtime-host '"YOUR-REPL-IP-ADDRESS"' :debugger-host '"YOUR-IP-ADDRESS"'
    +
    ssh -L 9000:localhost:9000 -R 7722:localhost:7722 my-debuggee-box.com
    -

    assuming your nrepl server is listening on port 9000.

    +

    assuming your remote process at my-debuggee-box.com has started a nrepl server listening on port 9000 and +that the debugger websocket server is running on the default port.

    -

    If your application is running in a different box you can also provide two extra keys :

    -
    -
    -
      -
    • -

      :runtime-host should be the ip of the debuggee (defaults to localhost)

      -
    • -
    • -

      :debugger-host should be the ip where the debugger is running, since the debuggee needs to connect back to it (defaults to localhost)"

      -
    • -
    -
    -
    -

    2.1. SSH tunnel

    -
    -

    You can debug remote process through a ssh tunnel by creating a tunnel like this :

    +

    After the tunnel is established, you can run you debugger UI like this :

    -
    ssh -L 9000:localhost:9000 -R 7722:localhost:7722 my-debuggee-box.com
    +
    clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port 9000
    -

    assuming your remote process at my-debuggee-box.com has started a nrepl server listening on port 9000.

    +

    and that is it.

    +
    +
    +

    If you need to connect the debugger to a remote process without a ssh tunnel or you need to configure the websocket server port you can do it like this :

    +
    +
    +
    +
    clj -Sforce -Sdeps '{:deps {com.github.flow-storm/flow-storm-dbg {:mvn/version "RELEASE"}}}' -X flow-storm.debugger.main/start-debugger :port NREPL-PORT :runtime-host '"YOUR-APP-BOX-IP-ADDRESS"' :debugger-host '"YOUR-BOX-IP-ADDRESS"' :ws-port WS-SERVER-PORT
    -

    2.2. Docker

    +

    2.1. Docker

    If you run you process inside a docker container, here is a basic template for using FlowStorm with it https://github.com/flow-storm/docker-flow-storm-basic

    @@ -3348,7 +3442,7 @@

    diff --git a/src-dbg/flow_storm/debugger/main.clj b/src-dbg/flow_storm/debugger/main.clj index efedd58f..9ae5d375 100644 --- a/src-dbg/flow_storm/debugger/main.clj +++ b/src-dbg/flow_storm/debugger/main.clj @@ -115,10 +115,8 @@ ;; But we need to skip this the first time the ws connection comes up ;; since maybe the system ins't fully started yet, we maybe don't even have a UI (when @fully-started - (when-let [{:keys [:repl/port]} (dbg-state/repl-config)] - (repl-core/init-repl (dbg-state/env-kind) - (:debugger-host (dbg-state/debugger-config)) - port)) + (when (dbg-state/repl-config) + (repl-core/init-repl (dbg-state/env-kind))) (ui-main/setup-ui-from-runtime-config))) :on-repl-down (fn [] diff --git a/src-dbg/flow_storm/debugger/repl/core.clj b/src-dbg/flow_storm/debugger/repl/core.clj index 10e2cdad..56f18c6f 100644 --- a/src-dbg/flow_storm/debugger/repl/core.clj +++ b/src-dbg/flow_storm/debugger/repl/core.clj @@ -99,37 +99,30 @@ :cause e})))) (utils/log-error "No cljs repl available"))))) -(defn make-cljs-repl-init-sequence [debugger-host port] - (let [remote-opts {:port port - :debugger-host debugger-host}] +(defn make-cljs-repl-init-sequence [] + [{:code "(do (in-ns 'shadow.user) nil)" :ns nil :repl-kind :clj} + {:code "(require '[flow-storm.runtime.debuggers-api :include-macros true])" :ns "cljs.user" :repl-kind :cljs}]) - [{:code "(do (in-ns 'shadow.user) nil)" :ns nil :repl-kind :clj} - {:code "(require '[flow-storm.runtime.debuggers-api :as dbg-api :include-macros true])" :ns "cljs.user" :repl-kind :cljs} - {:code (format "(dbg-api/remote-connect %s)" (pr-str remote-opts)) :ns "cljs.user" :repl-kind :cljs}])) - -(defn make-clj-repl-init-sequence [debugger-host port] - (let [remote-opts {:port port - :debugger-host debugger-host}] - - [{:code "(do (in-ns 'user) nil)" :ns nil :repl-kind :clj} - {:code "(require '[flow-storm.runtime.debuggers-api :as dbg-api])" :ns "user" :repl-kind :clj} - {:code (format "(dbg-api/remote-connect %s)" (pr-str remote-opts)) :ns "user" :repl-kind :clj}])) +(defn make-clj-repl-init-sequence [] + (let [opts (select-keys (dbg-state/debugger-config) [:debugger-host :debugger-ws-port])] + [{:code "(do (in-ns 'user) nil)" :ns nil :repl-kind :clj} + {:code "(require '[flow-storm.runtime.debuggers-api])" :ns "user" :repl-kind :clj} + {:code (format "(flow-storm.runtime.debuggers-api/remote-connect %s)" (pr-str opts)) :ns "user" :repl-kind :clj}])) (defn init-repl - ([env-kind debugger-host port] (init-repl env-kind debugger-host port (:repl-eval repl) (:repl-eval-cljs repl))) - ([env-kind debugger-host port repl-eval repl-eval-cljs] + ([env-kind] (init-repl env-kind (:repl-eval repl) (:repl-eval-cljs repl))) + ([env-kind repl-eval repl-eval-cljs] (let [repl-init-sequence (case env-kind - :clj (make-clj-repl-init-sequence debugger-host port) - :cljs (make-cljs-repl-init-sequence debugger-host port))] + :clj (make-clj-repl-init-sequence) + :cljs (make-cljs-repl-init-sequence))] (doseq [{:keys [code ns repl-kind]} repl-init-sequence] (case repl-kind :clj (repl-eval code ns) :cljs (repl-eval-cljs code ns)))))) -(defn- connect-and-init [{:keys [repl-type runtime-host debugger-host port build-id on-repl-up]}] +(defn- connect-and-init [{:keys [repl-type runtime-host port build-id on-repl-up]}] (let [runtime-host (or runtime-host "localhost") - debugger-host (or debugger-host "localhost") env-kind (if (#{:shadow} repl-type) :cljs :clj) ;; HACKY, this logic is replicated in `state` repl-kind :nrepl ;; HACKY, this logic is replicated in `state` log-file (io/file log-file-path) @@ -172,7 +165,7 @@ (utils/log "Initializing repl...") (try - (init-repl env-kind debugger-host port eval-clj eval-cljs) + (init-repl env-kind eval-clj eval-cljs) (catch Exception e (utils/log-error "There was a problem initializing the remote runtime via repl" e))) diff --git a/src-dbg/flow_storm/debugger/state.clj b/src-dbg/flow_storm/debugger/state.clj index e2a1cdcb..0bed4eff 100644 --- a/src-dbg/flow_storm/debugger/state.clj +++ b/src-dbg/flow_storm/debugger/state.clj @@ -133,12 +133,15 @@ :repl/type :repl/port :repl.cljs/build-id]))) + (s/def :config/debugger-host string?) +(s/def :config/debugger-ws-port int?) (s/def :config/runtime-host string?) (s/def :config/debug-mode? boolean?) (s/def ::debugger-config (s/keys :req-un [:config/repl :config/debugger-host + :config/debugger-ws-port :config/runtime-host :config/debug-mode?])) @@ -156,7 +159,7 @@ ::debugger-config] :opt-un [:ui/selected-flow-id])) -(defn initial-state [{:keys [theme styles local? port repl-type debugger-host runtime-host] :as config}] +(defn initial-state [{:keys [theme styles local? port repl-type debugger-host ws-port runtime-host] :as config}] {:flows {} :selected-flow-id nil :printers {} @@ -181,6 +184,7 @@ :repl/port port} (#{:shadow} repl-type) (assoc :repl.cljs/build-id (:build-id config)))) :debugger-host (or debugger-host "localhost") + :debugger-ws-port (or ws-port 7722) :runtime-host (or runtime-host "localhost") :debug-mode? false}}) diff --git a/src-dbg/flow_storm/debugger/websocket.clj b/src-dbg/flow_storm/debugger/websocket.clj index b7bfc346..d907cf14 100644 --- a/src-dbg/flow_storm/debugger/websocket.clj +++ b/src-dbg/flow_storm/debugger/websocket.clj @@ -128,10 +128,11 @@ nil) (defn start-websocket-server [{:keys [on-ws-event on-ws-up on-ws-down]}] - (let [remote-connection (atom nil) + (let [{:keys [debugger-ws-port]} (dbg-state/debugger-config) + remote-connection (atom nil) ws-ready (promise) ws-server (create-ws-server - {:port 7722 + {:port debugger-ws-port :on-start (fn [] (deliver ws-ready true)) :on-open (fn [conn] (reset! remote-connection conn) diff --git a/src-inst/flow_storm/preload.cljs b/src-inst/flow_storm/preload.cljs index 52d59eca..9b5a0ffc 100644 --- a/src-inst/flow_storm/preload.cljs +++ b/src-inst/flow_storm/preload.cljs @@ -2,8 +2,4 @@ (:require [flow-storm.runtime.debuggers-api :as dbg-api])) (dbg-api/setup-runtime) -;; automatically try to make a "remote" connection -;; to localhost:7722 (the default) -;; Keep this is for the case where no repl is going to be available -;; so we fire remote connect con preload (dbg-api/remote-connect {}) diff --git a/src-inst/flow_storm/remote_websocket_client.clj b/src-inst/flow_storm/remote_websocket_client.clj index 90266e1f..d8a49f12 100644 --- a/src-inst/flow_storm/remote_websocket_client.clj +++ b/src-inst/flow_storm/remote_websocket_client.clj @@ -26,10 +26,11 @@ (let [ser-packet (serializer/serialize [:event ev-packet])] (send ser-packet))) -(defn start-remote-websocket-client [{:keys [debugger-host on-connected api-call-fn] - :or {debugger-host "localhost"}}] - (let [port 7722 - uri-str (format "ws://%s:%s/ws" debugger-host port) +(defn start-remote-websocket-client [{:keys [debugger-host debugger-ws-port on-connected api-call-fn]}] + (let [debugger-host (or debugger-host "localhost") + debugger-ws-port (or debugger-ws-port 7722) + uri-str (format "ws://%s:%s/ws" debugger-host debugger-ws-port) + _ (println "About to connect to " uri-str) ^WebSocketClient ws-client (proxy [WebSocketClient] [(URI. uri-str)] diff --git a/src-inst/flow_storm/remote_websocket_client.cljs b/src-inst/flow_storm/remote_websocket_client.cljs index 7b994f50..f7e9aab8 100644 --- a/src-inst/flow_storm/remote_websocket_client.cljs +++ b/src-inst/flow_storm/remote_websocket_client.cljs @@ -30,7 +30,7 @@ (js/console.error "websocket node dependency not installed. Please npm install websocket to use flowstorm with nodejs" e)))] (.-w3cwebsocket ^js obj)) - js/window.WebSocket) + js/globalThis.WebSocket) ws-client (WebSocket. uri-str)] ws-client)) @@ -42,15 +42,20 @@ (let [ser-packet (serializer/serialize [:event ev-packet])] (send ser-packet))) -(defn start-remote-websocket-client [{:keys [debugger-host on-connected api-call-fn] - :or {debugger-host "localhost"}}] +(defn start-remote-websocket-client [{:keys [debugger-host debugger-ws-port on-connected api-call-fn]}] + (if (remote-connected?) (js/console.warn "Websocket already connected. Skipping.") - (let [port 7722 - uri-str (utils/format "ws://%s:%s/ws" debugger-host port) - ws-client (web-socket-client-object uri-str)] + (let [debugger-host (or debugger-host "localhost") + debugger-ws-port (or debugger-ws-port 7722) + uri-str (utils/format "ws://%s:%s/ws" debugger-host debugger-ws-port) + _ (println "About to connect to " uri-str) + ws-client (try + (web-socket-client-object uri-str) + (catch js/Error e + (js/console.error (str "Can't connect to " uri-str) e)))] (set! (.-onerror ws-client) (fn [] (log-error (utils/format "WebSocket error connection %s" uri-str)))) diff --git a/src-inst/flow_storm/runtime/debuggers_api.cljc b/src-inst/flow_storm/runtime/debuggers_api.cljc index a65198b9..75ee8d88 100644 --- a/src-inst/flow_storm/runtime/debuggers_api.cljc +++ b/src-inst/flow_storm/runtime/debuggers_api.cljc @@ -577,14 +577,11 @@ :cljs ;;---------------------------------------------------------------------------------------------- (defn remote-connect [config] - - (println "Connecting with the debugger with config : " config) - ;; connect to the remote websocket (try (remote-websocket-client/start-remote-websocket-client - (assoc config + (assoc config :api-call-fn call-by-name :on-connected (fn [] ;; subscribe and automatically push all events thru the websocket diff --git a/src-inst/flow_storm/storm_preload.cljs b/src-inst/flow_storm/storm_preload.cljs index dcae7199..e6754481 100644 --- a/src-inst/flow_storm/storm_preload.cljs +++ b/src-inst/flow_storm/storm_preload.cljs @@ -7,8 +7,4 @@ (tracer/hook-clojurescript-storm) (dbg-api/setup-runtime) -;; automatically try to make a "remote" connection -;; to localhost:7722 (the default) -;; Keep this is for the case where no repl is going to be available -;; so we fire remote connect con preload (dbg-api/remote-connect {})