How to open the XMPP connection in react native throughout the entire app (using xmpp.js)?









up vote
0
down vote

favorite












I am using XMPP.js inside react native and using web socket to connect with the xmpp server. I can successfully connect with the chat server but I have to navigate to different pages inside the App so I have 2 options:



  1. I must open a new XMPP connection to the xmpp chat server everytime I navigate to a new page (using react Navigation for navigating) and close the old connection [I think its not recommended] or


  2. I must open the connection in the starting and use the same connection throughout the entire app. But how to achieve that?


Is there any alternative like services in react native with which I can open the XMPP connection in the backend and it must work throughout the entire app. I need the feasible solution for both Android+IOS










share|improve this question

























    up vote
    0
    down vote

    favorite












    I am using XMPP.js inside react native and using web socket to connect with the xmpp server. I can successfully connect with the chat server but I have to navigate to different pages inside the App so I have 2 options:



    1. I must open a new XMPP connection to the xmpp chat server everytime I navigate to a new page (using react Navigation for navigating) and close the old connection [I think its not recommended] or


    2. I must open the connection in the starting and use the same connection throughout the entire app. But how to achieve that?


    Is there any alternative like services in react native with which I can open the XMPP connection in the backend and it must work throughout the entire app. I need the feasible solution for both Android+IOS










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am using XMPP.js inside react native and using web socket to connect with the xmpp server. I can successfully connect with the chat server but I have to navigate to different pages inside the App so I have 2 options:



      1. I must open a new XMPP connection to the xmpp chat server everytime I navigate to a new page (using react Navigation for navigating) and close the old connection [I think its not recommended] or


      2. I must open the connection in the starting and use the same connection throughout the entire app. But how to achieve that?


      Is there any alternative like services in react native with which I can open the XMPP connection in the backend and it must work throughout the entire app. I need the feasible solution for both Android+IOS










      share|improve this question













      I am using XMPP.js inside react native and using web socket to connect with the xmpp server. I can successfully connect with the chat server but I have to navigate to different pages inside the App so I have 2 options:



      1. I must open a new XMPP connection to the xmpp chat server everytime I navigate to a new page (using react Navigation for navigating) and close the old connection [I think its not recommended] or


      2. I must open the connection in the starting and use the same connection throughout the entire app. But how to achieve that?


      Is there any alternative like services in react native with which I can open the XMPP connection in the backend and it must work throughout the entire app. I need the feasible solution for both Android+IOS







      android ios reactjs react-native xmpp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 2 at 7:42









      Shubham1164

      436




      436






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You must open the connection in the starting and use the same connection throughout the entire app. You need to have some class like singleton or so which will hold an xmpp client, so you will use it across the entire app. Or you even can try to hold a global variable inside App.js with xmll client.



          For example, here at ConnectyCube ReactNative SDK https://developers.connectycube.com/js/react-native there is a simple prototype object which holds an xmpp client. Then this object can be used in a flux container or as a global variable, something like here How to use global variables in React Native?






          share|improve this answer




















          • Hi Ruby, on your reference, I have started using xmpp.js for xmpp chat but I am unable to perform stream management with it. Please read the complete question here [stackoverflow.com/q/53257285/3102733]
            – Shubham1164
            Nov 12 at 7:08










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53114492%2fhow-to-open-the-xmpp-connection-in-react-native-throughout-the-entire-app-using%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You must open the connection in the starting and use the same connection throughout the entire app. You need to have some class like singleton or so which will hold an xmpp client, so you will use it across the entire app. Or you even can try to hold a global variable inside App.js with xmll client.



          For example, here at ConnectyCube ReactNative SDK https://developers.connectycube.com/js/react-native there is a simple prototype object which holds an xmpp client. Then this object can be used in a flux container or as a global variable, something like here How to use global variables in React Native?






          share|improve this answer




















          • Hi Ruby, on your reference, I have started using xmpp.js for xmpp chat but I am unable to perform stream management with it. Please read the complete question here [stackoverflow.com/q/53257285/3102733]
            – Shubham1164
            Nov 12 at 7:08














          up vote
          1
          down vote



          accepted










          You must open the connection in the starting and use the same connection throughout the entire app. You need to have some class like singleton or so which will hold an xmpp client, so you will use it across the entire app. Or you even can try to hold a global variable inside App.js with xmll client.



          For example, here at ConnectyCube ReactNative SDK https://developers.connectycube.com/js/react-native there is a simple prototype object which holds an xmpp client. Then this object can be used in a flux container or as a global variable, something like here How to use global variables in React Native?






          share|improve this answer




















          • Hi Ruby, on your reference, I have started using xmpp.js for xmpp chat but I am unable to perform stream management with it. Please read the complete question here [stackoverflow.com/q/53257285/3102733]
            – Shubham1164
            Nov 12 at 7:08












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You must open the connection in the starting and use the same connection throughout the entire app. You need to have some class like singleton or so which will hold an xmpp client, so you will use it across the entire app. Or you even can try to hold a global variable inside App.js with xmll client.



          For example, here at ConnectyCube ReactNative SDK https://developers.connectycube.com/js/react-native there is a simple prototype object which holds an xmpp client. Then this object can be used in a flux container or as a global variable, something like here How to use global variables in React Native?






          share|improve this answer












          You must open the connection in the starting and use the same connection throughout the entire app. You need to have some class like singleton or so which will hold an xmpp client, so you will use it across the entire app. Or you even can try to hold a global variable inside App.js with xmll client.



          For example, here at ConnectyCube ReactNative SDK https://developers.connectycube.com/js/react-native there is a simple prototype object which holds an xmpp client. Then this object can be used in a flux container or as a global variable, something like here How to use global variables in React Native?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 15:05









          Rubycon

          15.6k83658




          15.6k83658











          • Hi Ruby, on your reference, I have started using xmpp.js for xmpp chat but I am unable to perform stream management with it. Please read the complete question here [stackoverflow.com/q/53257285/3102733]
            – Shubham1164
            Nov 12 at 7:08
















          • Hi Ruby, on your reference, I have started using xmpp.js for xmpp chat but I am unable to perform stream management with it. Please read the complete question here [stackoverflow.com/q/53257285/3102733]
            – Shubham1164
            Nov 12 at 7:08















          Hi Ruby, on your reference, I have started using xmpp.js for xmpp chat but I am unable to perform stream management with it. Please read the complete question here [stackoverflow.com/q/53257285/3102733]
          – Shubham1164
          Nov 12 at 7:08




          Hi Ruby, on your reference, I have started using xmpp.js for xmpp chat but I am unable to perform stream management with it. Please read the complete question here [stackoverflow.com/q/53257285/3102733]
          – Shubham1164
          Nov 12 at 7:08

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53114492%2fhow-to-open-the-xmpp-connection-in-react-native-throughout-the-entire-app-using%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          What does pagestruct do in Eviews?

          Dutch intervention in Lombok and Karangasem

          Channel Islands