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

advancedsocket

v1.0.3

Published

AdvancedSocket aims to help handling connectivity issues from the client side when using ColdFusion WebSocket solution.

Downloads

10

Readme

AdvancedSocket

AdvancedSockets aims to help handling connectivity issues from the client side when using ColdFusion WebSocket solution.

Below is a simple example of how to implement. The data attributes defined in the body are the default values and do not have to be set but can be overridden. For more information on how and where they are set refer to the Attributes / Properties section.

	<body 	data-auto-connect="true"
			data-name="ws"
			data-channels="channelname"
			data-debug="true"
			data-do-message="doMessage"
			data-online-timer="30"
			data-offline-timer="5"
			data-reconnect-timer=".5"
			data-ping-url="ping.cfm">
	<div id="status-message" class="hide"></div>
	<script src="advanced.js"></script>
   <cfwebsocket 	name		="ws"
   				onMessage	="AdvancedSocket.onMessage"
   				onOpen		="AdvancedSocket.onOpen"
   				onClose		="AdvancedSocket.onClose"
   				onError		="AdvancedSocket.onError">
   <script>
   	function doMessage(obj){
   		console.log(obj);
   	}
   </script>
   </body>

Properties / Attributes

  • autoConnect Controls the auto connect feature of the AdvancedSocket. Defaults to true but can be managed by the data-auto-connect attribute in the body tag. It also requires a pingURL to be defined.
  • name The name of your global websocket variable name. Defaults to ws but can be managed by the data-name attribute in the body tag.
  • channels<br/ > Comma separated list of channels to subscribe to. Managed by the data-channels attribute in the body tag.
  • clientID The subscriber ID returned from ColdFusion on a succesful connection. This is used when the autoConnect feature is enabled to make sure that we are still an active subscriber.
  • clientInfo This is a key-value object that is passed when creating a connection. By default AdvancedSocket uses a third party request to find out additional geo-based data of the request. This is also used to pass in a username and any additional info you may want to.
  • doMessage Defines the global function to run on a succesful message. Defaults to doMessage. If the function is not defined or does not exists a log message will be displayed (if debug is enabled). Defaults to doMessage but can be managed by the data-do-message attribute in the body tag.
  • timer Used for the check AdvancedSocket.checkConnection setTimeout
  • pingURL The URL that will be used to ping if we are still a good connection. Should return a JSON object with a success value of true or false. Managed by the data-ping-url attribute in the body tag.
  • onlineTimer The timeout value to ping if autoConnect is enabled while we have a good connection. Defaults to 30 seconds but can be managed by the data-online-timer attribute in the body tag.
  • offlineTimer The timeout value to ping if autoConnect is enabled while we have a bad connection. Defaults to 5 seconds but can be managed by the data-offline-timer attribute in the body tag.
  • reconnectTimer The timeout value call a reconnect attempt when a FORCE-RECONNECT value is received from the server. Defaults to 500ms but can be managed by the data-reconnect-timer attribute in the body tag.
  • timerCount The timeout value that is used on reconnect calls. It is automally updated to either the online or offline value based on current state.
  • debug Boolean value to display log messages. Defaults to false but can be managed by the data-debug attribute in the body tag.
  • statusLabel The status document element defined by an id of status-message. Defaults to status-message but can be managed by the data-status-label attribute in the body tag.

Functions

  • init Sets up all required EventListeners to handle window connection events (connectionerror, goodconnection, requireconnection, offline, online). Sets up the timerCount to the onlineCount and then request the checkConnection() function.
  • checkConnection Sets up timer and request first ping() call if autoConnect is enabled.
  • fireEvent Creates and dispatches custom events.
  • ping Polls request to the server to check if connection is still valid.
  • onMessage Handles messages returned. On welcome, authenticate and/or subscribe messages it auto fires the AdvancedSocket.connected() function. On FORCE-RECONNECT messages fires the AdvancedSocket.forceReconnect() funciton based on the reconnectCount. On a regular messages passes to the Global Function that will handle your message.
  • onOpen Fired onced the connection is open. If authentication is required, it calls the authenticate() WS function if not passes to the AdvancedSocket.getIPInfo() function, which is the last step before subscribing.
  • onClose Fired on connection close
  • onError Fired on connection errors
  • getIPInfo Makes a request to ip-api.com to request Geo Based IP data. On response or if jQuery is not available it will call AdvancedSocket.connectWS(), the final step which handles all connections.
  • connectWS Loops thru your defined channels and calls the WS subscribe() function.
  • forceReconnect Fired when a FORCE-RECONNECT message is received. Calls the WS closeConnection() and openConnection() functions which in turn when the socket is open again fires the AdvancedSocket.onOpen() function.
  • setTimer Handles setting the timer that fires off the check connection event using window.setTimeout
  • doLog Outputs console logs if debug is set to true. This can be defined with the body data-debug attribute.
  • disconnected :metal: (overwrite to customize) Fired when a socket is disconnected. Updates the status label.
  • connecting :metal: (overwrite to customize) Fired when the socket is connecting. Updates the status label.
  • connected :metal: (overwrite to customize) Fired when the socket is connected. Updates the status label.