0.3.2 • Published 3 years ago

wsdebug v0.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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()
0.3.0

3 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.8

3 years ago

0.3.2

3 years ago

0.2.3

4 years ago

0.3.1

3 years ago

0.2.2

4 years ago

0.1.3

4 years ago

0.2.5

3 years ago

0.2.4

4 years ago

0.0.20

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.14

4 years ago

0.0.15

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago