mirror of
https://github.com/logos-messaging/docs.waku.org.git
synced 2026-01-03 21:33:05 +00:00
1 line
7.2 KiB
JavaScript
1 line
7.2 KiB
JavaScript
"use strict";(self.webpackChunkwaku_guide=self.webpackChunkwaku_guide||[]).push([[175],{3905:(e,n,t)=>{t.d(n,{Zo:()=>u,kt:()=>m});var i=t(67294);function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);n&&(i=i.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,i)}return t}function a(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(Object(t),!0).forEach((function(n){r(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function s(e,n){if(null==e)return{};var t,i,r=function(e,n){if(null==e)return{};var t,i,r={},o=Object.keys(e);for(i=0;i<o.length;i++)t=o[i],n.indexOf(t)>=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i<o.length;i++)t=o[i],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var c=i.createContext({}),p=function(e){var n=i.useContext(c),t=n;return e&&(t="function"==typeof e?e(n):a(a({},n),e)),t},u=function(e){var n=p(e.components);return i.createElement(c.Provider,{value:n},e.children)},l="mdxType",d={inlineCode:"code",wrapper:function(e){var n=e.children;return i.createElement(i.Fragment,{},n)}},g=i.forwardRef((function(e,n){var t=e.components,r=e.mdxType,o=e.originalType,c=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),l=p(t),g=r,m=l["".concat(c,".").concat(g)]||l[g]||d[g]||o;return t?i.createElement(m,a(a({ref:n},u),{},{components:t})):i.createElement(m,a({ref:n},u))}));function m(e,n){var t=arguments,r=n&&n.mdxType;if("string"==typeof e||r){var o=t.length,a=new Array(o);a[0]=g;var s={};for(var c in n)hasOwnProperty.call(n,c)&&(s[c]=n[c]);s.originalType=e,s[l]="string"==typeof e?e:r,a[1]=s;for(var p=2;p<o;p++)a[p]=t[p];return i.createElement.apply(null,a)}return i.createElement.apply(null,t)}g.displayName="MDXCreateElement"},62093:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>p,default:()=>f,frontMatter:()=>c,metadata:()=>u,toc:()=>d});var i=t(87462),r=(t(67294),t(3905));const o={toc:[]},a="wrapper";function s(e){let{components:n,...t}=e;return(0,r.kt)(a,(0,i.Z)({},o,t,{components:n,mdxType:"MDXLayout"}),(0,r.kt)("mermaid",{value:"graph TD\n A[Start Monitoring Filter Subscriptions] --\x3e B{Check Peer Connection}\n B -- Connected --\x3e C[Send Ping]\n C --\x3e D{Ping Success?}\n D -- Yes --\x3e B\n D -- No --\x3e E[Handle Error/Reinitiate Subscription]\n B -- Disconnected --\x3e F[Check Intentional Disconnection/Unsubscription]\n F -- Yes --\x3e G[Stop Monitoring]\n F -- No --\x3e B\n E --\x3e B"}))}s.isMDXComponent=!0;const c={title:"Manage Your Filter Subscriptions",hide_table_of_contents:!0},p=void 0,u={unversionedId:"guides/js-waku/manage-filter",id:"guides/js-waku/manage-filter",title:"Manage Your Filter Subscriptions",description:"This guide provides detailed steps to manage Filter subscriptions and handle node disconnections in your application. Have a look at the Send and Receive Messages Using Light Push and Filter guide for using the Light Push and Filter protocols.",source:"@site/docs/guides/js-waku/manage-filter.md",sourceDirName:"guides/js-waku",slug:"/guides/js-waku/manage-filter",permalink:"/guides/js-waku/manage-filter",draft:!1,editUrl:"https://github.com/waku-org/docs.waku.org/tree/develop/docs/guides/js-waku/manage-filter.md",tags:[],version:"current",lastUpdatedAt:1704966176,formattedLastUpdatedAt:"11 Jan 2024",frontMatter:{title:"Manage Your Filter Subscriptions",hide_table_of_contents:!0},sidebar:"guides",previous:{title:"Debug Your Waku DApp and WebSocket",permalink:"/guides/js-waku/debug-waku-dapp"}},l={},d=[{value:"Overview",id:"overview",level:2},{value:"Pinging filter subscriptions",id:"pinging-filter-subscriptions",level:2}],g={toc:d},m="wrapper";function f(e){let{components:n,...t}=e;return(0,r.kt)(m,(0,i.Z)({},g,t,{components:n,mdxType:"MDXLayout"}),(0,r.kt)("p",null,"This guide provides detailed steps to manage ",(0,r.kt)("a",{parentName:"p",href:"/learn/concepts/protocols#filter"},"Filter")," subscriptions and handle node disconnections in your application. Have a look at the ",(0,r.kt)("a",{parentName:"p",href:"/guides/js-waku/light-send-receive"},"Send and Receive Messages Using Light Push and Filter")," guide for using the ",(0,r.kt)("inlineCode",{parentName:"p"},"Light Push")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"Filter")," protocols."),(0,r.kt)("h2",{id:"overview"},"Overview"),(0,r.kt)("p",null,"Occasionally, your ",(0,r.kt)("inlineCode",{parentName:"p"},"Filter")," subscriptions might disconnect from the Waku Network, resulting in messages not being received by your application. To manage your subscriptions, periodically ping peers to check for an active connection. The error message ",(0,r.kt)("inlineCode",{parentName:"p"},'"peer has no subscriptions"')," indicates a failed ping due to disconnection. You can stop the pings if the disconnection/unsubscription is deliberate."),(0,r.kt)(s,{mdxType:"FilterPingFlow"}),(0,r.kt)("h2",{id:"pinging-filter-subscriptions"},"Pinging filter subscriptions"),(0,r.kt)("p",null,"The ",(0,r.kt)("inlineCode",{parentName:"p"},"@waku/sdk")," package provides a ",(0,r.kt)("inlineCode",{parentName:"p"},"Filter.ping()")," function to ping subscriptions and check for an active connection. To begin, create a ",(0,r.kt)("inlineCode",{parentName:"p"},"Filter")," subscription:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-js"},"// Create a Filter subscription\nconst subscription = await node.filter.createSubscription();\n\n// Subscribe to content topics and process new messages\nawait subscription.subscribe([decoder], callback);\n")),(0,r.kt)("p",null,"Next, create a function to ping and reinitiate the subscription:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-js"},'const pingAndReinitiateSubscription = async () => {\n try {\n // Ping the subscription\n await subscription.ping();\n } catch (error) {\n if (\n // Check if the error message includes "peer has no subscriptions"\n error instanceof Error &&\n error.message.includes("peer has no subscriptions")\n ) {\n // Reinitiate the subscription if the ping fails\n await subscription.subscribe([decoder], callback);\n } else {\n throw error;\n }\n }\n};\n\n// Periodically ping the subscription\nawait pingAndReinitiateSubscription();\n')),(0,r.kt)("admonition",{type:"info"},(0,r.kt)("p",{parentName:"admonition"},"Pings will fail when there are temporary network degradations or reachability issues. This does not mean that the underlying connection has been closed.")),(0,r.kt)("admonition",{title:"Congratulations!",type:"success"},(0,r.kt)("p",{parentName:"admonition"},"You have successfully managed your ",(0,r.kt)("inlineCode",{parentName:"p"},"Filter")," subscriptions to handle node disconnections in your application.")))}f.isMDXComponent=!0}}]); |