npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-strophe-hook

v1.0.2

Published

hook wrapper on top of strophe.js

Downloads

2

Readme

What is React-Strophe-hook

Strophe.js is a popular library to handle xmpp requests on browser. When the library is published jquery was the hot thing. So , it follows jquery approaches. This hook is a wrapper on top of strophe.js to make react implementation easier.

a working implementation can be found here

installation

npm i react-strophe-hook

or

yarn add react-strophe-hook

Basic Implementation

import React, { useEffect } from 'react';
import { Strophe } from 'strophe.js';
import { useStrophe } from 'react-strophe-hook';

const BOSH_SERVER = 'wss://boshServer.com';
const connection = new Strophe.Connection(BOSH_SERVER);
const credentials = {
  jabid: [email protected],
  pass: password,
};

function App() {
  const {
    connect,
    connected,
    disconnect,
    connecting,
    disconnecting,
    disconnected,
    domainName,
    resource,
    bareJid,
  } = useStrophe({
    credentials,
    connection,
    showLogs: true,
  });

  useEffect(() => {
    connect();
    return () => {
      disconnect('unmounted');
    };
  }, []);


  return (
    <div>
      {connecting && <p>Connecting...</p>}
      {disconnecting && <p>Disconnecting...</p>}
      <div>
        <p>The server is {connected ? 'connected' : 'disconnected'}</p>
      </div>

      <div>
        {connected && (
          <button type="button" onClick={() => disconnect('TESTING')}>
            Disconnect
          </button>
        )}
        {disconnected && (
          <button type="button" onClick={connect}>
            Connect
          </button>
        )}
      </div>
    </div>
  );
}

export default App;

Parameters

| name | type |required| default | description | |--|--|--|--|--| | credentials | {jabid: string; pass: string;} | true |undefined | creddentials of jabb user and password | |onConnect | (reason?: string) => void | false | undefined | Executes when xmpp connection is established. |onConnecting | (reason?: string) => void | false | undefined | Executes when xmpp connection is being established | onDisconnect | (reason?: string) => void | false | undefined | Executes when xmpp connection is Disconnected | onDisconnecting | (reason?: string) => void | false | undefined | Executes when xmpp connection is being Disconnected | onConnFail | (reason?: string) => void | false | undefined | Executes when failed to establish xmpp connection | connection |Strophe.Connection | true | null | Strophe connection object | onMessage | (msg: Element) => boolean | false | null | Catches message stanzas, if the function returns false, it'll catch single message and the handler will be deleted, if true is returned it will catch all catch call message stanzas.If the function is not passed and showLogs is set to true, it'll console log the messages. |onPresence | (presence: Element) => boolean| false | null | Catches presence stanzas, if the function returns false, it'll catch single presence and the handler will be deleted, if true is returned it will catch all catch call presence stanzas. If the function is not passed and showLogs is set to true, it'll console log the presences. |onIq | (iq: Element) => boolean | false | null | Catches iq stanzas, if the function returns false, it'll catch single iq and the handler will be deleted, if true is returned it will catch all catch iq stanzas.If the function is not passed and showLogs is set to true, it'll console log the iqs. handlers | { handlerFunc: (_payload: Element) => boolean; matcher:{ namespace?: string; name: 'message' | 'iq' | 'presence'; type?: string; id?: string; from?: string; }; }[] | false | [] | takes array of objects. Each object has two key,value pair. handlerFunc same as onMessage, onIq, onStanza functions. matcher an object has five keys namespace?: string; name: 'message' | 'iq' | 'presence'; type?: string; id?: string; from?: string; all the keys are optional. If an matcher is passed as an empty object, it'll match all the stanzas. | showLogs | boolean | false | false | if set to true, it'll show all event logs

Return values

| name | type | description |--|--|--| | connect | () => void | call this function to establish connection | | disconnect | () => void | call this function to gracefully disconnect | | connected | boolean | returns true if connection established successfully | connecting | boolean | returns true if connection is being established, can be used to show a loader | disconnected | boolean | returns true is connection disconnected disconnecting | boolean | returns true if connection is being disconnected, can be used to show a loader connFail | boolean | returns true if connection is failed domainName | string|undefined | returns domain name once connection is established bareJid | string | returns jid without domain name resource | string | returns resource