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

wsdebug

v0.3.2

Published

使用websocket对远程页面进行debug调试

Downloads

9

Readme

wsdebug

Travis CI Codecov 使用websocket对远程页面进行debug调试。

step1. server

// mkdir ./logs
// mkdir ./store
// vim ./store/auth.json

const server = require('wsdebug');
server(8081);

step2. client

import { Client } from 'wsdebug/es';
// import { Client } from 'wsdebug/lib';

function dosomething (arg) {
  // do something
  console.log('do something', arg);
  return Date.now();
}
const client = new Client('127.0.0.1', 8081, false, 3);
client.setId(`uid_123456`);
client.on('connect', (data) => {
  console.log('master connected', data);
})
client.register('dosomething', dosomething);
client.register('doasync', () => {
  return new Promise()
});
window.test = function () {
  console.log('test');
  return 'window.test';
}

step3. master

import { Master } from 'wsdebug/es';
// import { Master } from 'wsdebug/lib';

const master = new Master('127.0.0.1', 8081, false, 3);
master.name = 'admin1';
master.password = '123456';
master.connect('uid_123456');
// arr: [{ name: 'string', list: ['string', ...]}, ...], opt: undefined|0|1, 0: decrease, 1: increase
master.on('connect', (arr, opt) => {
  console.log(arr, opt);
  if (arr.length) {
    master.run('dosomething("test")', (error, msg) => {
      console.log('result', msg);
    })
    master.run('window.test()', (error, msg) => {
      console.log('result', msg);
    })
  }
})

API

server

@param {String} port
@param {Number} timeout 30
server()

client

@description: constructor
@param {String} host
@param {Number} port
@param {Boolean} ssl
@param {Number} timeout
@param {Function} onerror
Client()

@description: addEventListener
@param {String} type
@param {Function} func
on()

@description: get session id
@return {String}
sessionId()

@description: send data
@param {String} msg
@return {String}
send()

@description: send data
@param {String} msg
@param {Number} timeout
@return {Promise}
send2()

@description: close websocket
close()

@description: get websocket readyState
@return {Number}
readyState()

@description: client id
@param {String} id
@param {Number} opt 1: add 0: remove
setId()

@return {Array}
getId()

@description: query master
@return {Promise<String>}
query()

@description: register function
@param {String} name
@param {Function} func
register()

@description: remove function
@param {String} name
@param {Function} func
remove()

@description: bind register function context
@param {Object} self
bind()

master

@description: constructor
@param {String} host
@param {Number} port
@param {Boolean} ssl
@param {Number} timeout
@param {Function} onerror
Master()

@description: addEventListener
@param {String} type
@param {Function} func
on()

@description: get session id
@return {String}
sessionId()

@description: set role & name & password
@return {Promise<Boolean>} success or fail
setRole()

@description: send data
@param {String} msg
send()

@description: send data
@param {String} msg
@param {Number} timeout
@return {Promise}
send2()

@description: close websocket
close()

@description: get websocket readyState
@return {Number}
readyState()

@description: client id
@param {String} id
@param {Number} opt 1: add 0: remove
setId()

@return {Array}
getId()

@description: query master
@return {Promise<String>}
query()

@description: eval client scripts
@param {String} script
@param {Function} callback
@param {Number} timeout
run()

@description: setId
@param {String} id
connect()