@@ -41,11 +41,11 @@ const routeAlias = computed(() => {
4141 return requestsStore .currentRequest ?.meta .params .controller + " #" + requestsStore .currentRequest ?.meta .params .action
4242})
4343
44- let debugbarChannel
44+ let debugbarChannel = null
4545
46- if (configStore .config .mode == " ws" ) {
46+ if (configStore .config .mode === " ws" ) {
4747 debugbarChannel = createConsumer (configStore .config .actionCableUrl ).subscriptions .create (
48- { channel: configStore .config .channelName },
48+ { channel: configStore .config .cable . channelName },
4949 {
5050 connected() {
5151 console .log (" 🟢 Connected to channel" )
@@ -72,21 +72,45 @@ if (configStore.config.mode == "ws") {
7272 },
7373 }
7474 )
75+ } else if (configStore .config .mode === " poll" ) {
76+ console .log (
77+ ` Using debugbar in "polling mode". Consider using "ws" mode for better performance (requires ActionCable). `
78+ )
79+ setInterval (() => {
80+ fetch (configStore .config .pollUrl )
81+ .then ((response ) => response .json ())
82+ .then ((data ) => {
83+ if (data .length == 0 ) {
84+ return
85+ }
86+
87+ console .log (data )
88+
89+ const ids = requestsStore .addRequests (data )
90+
91+ if (! isActive .value ) {
92+ requestsStore .setCurrentRequestById (ids [ids .length - 1 ])
93+ }
94+
95+ fetch (configStore .config .pollUrl + " /confirm" , {
96+ // mode: "no-cors",
97+ method: " POST" ,
98+ headers: {
99+ " Content-Type" : " application/json" ,
100+ },
101+ body: JSON .stringify ({ ids: ids }),
102+ })
103+ })
104+ }, configStore .config .poll .interval )
75105} else {
76- console .log (` Using debugbar in "offline mode", ideal for demoing with fixtures. ` )
77- debugbarChannel = {
78- send : (data ) => {
79- // No-op
80- console .log (" Ignoring `send` call" , data )
81- },
82- }
106+ console .log (` Using debugbar in "offline mode", ideal for demos using fixtures. ` )
83107}
84108
85109const clearRequests = () => {
86110 console .log (" Clearing requests" )
87111 state .activeTab = " "
88112 requestsStore .clearRequests ()
89- debugbarChannel .send ({ clear: true })
113+ debugbarChannel ? .send ({ clear: true })
90114}
91115
92116// Resizing the debugbar
0 commit comments