Skip to content

Commit

Permalink
refactor(whole package): name changed to "lab-gui-wechsocket"
Browse files Browse the repository at this point in the history
the name of the package has changed to "lab-gui-wechsocket" due to the name change of "lab-ui" to
"lab-gui", since "lab-ui" was allready taken on npmjs.com

BREAKING CHANGE: package was renamed to "lab-gui-wechsocket"
  • Loading branch information
s-weigand committed Dec 12, 2018
1 parent e0d96be commit 67e6933
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 62 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[![npm latest version](https://img.shields.io/npm/v/lab-ui-websocket.svg)](https://www.npmjs.com/package/lab-ui-websocket)
[![Build Status](https://travis-ci.org/MicroControlLab/lab-ui-websocket.svg?branch=master)](https://travis-ci.org/MicroControlLab/lab-ui-websocket)
[![Coverage Status](https://coveralls.io/repos/github/MicroControlLab/lab-ui-websocket/badge.svg?branch=master)](https://coveralls.io/github/MicroControlLab/lab-ui-websocket?branch=master)
[![Apache 2.0 licensed](https://img.shields.io/hexpm/l/plug.svg)](https://raw.githubusercontent.com/MicroControlLab/lab-ui-websocket/master/LICENSE)
[![Dev Dependencies](https://david-dm.org/MicroControlLab/lab-ui-websocket/dev-status.svg)](https://david-dm.org/MicroControlLab/lab-ui-websocket?type=dev)
[![Greenkeeper badge](https://badges.greenkeeper.io/MicroControlLab/lab-ui-websocket.svg)](https://greenkeeper.io/)
[![npm latest version](https://img.shields.io/npm/v/lab-gui-websocket.svg)](https://www.npmjs.com/package/lab-gui-websocket)
[![Build Status](https://travis-ci.org/MicroControlLab/lab-gui-websocket.svg?branch=master)](https://travis-ci.org/MicroControlLab/lab-gui-websocket)
[![Coverage Status](https://coveralls.io/repos/github/MicroControlLab/lab-gui-websocket/badge.svg?branch=master)](https://coveralls.io/github/MicroControlLab/lab-gui-websocket?branch=master)
[![Apache 2.0 licensed](https://img.shields.io/hexpm/l/plug.svg)](https://raw.githubusercontent.com/MicroControlLab/lab-gui-websocket/master/LICENSE)
[![Dev Dependencies](https://david-dm.org/MicroControlLab/lab-gui-websocket/dev-status.svg)](https://david-dm.org/MicroControlLab/lab-gui-websocket?type=dev)
[![Greenkeeper badge](https://badges.greenkeeper.io/MicroControlLab/lab-gui-websocket.svg)](https://greenkeeper.io/)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Documentation](https://img.shields.io/badge/docs-gh--pages-brightgreen.svg)](https://microcontrollab.github.io/lab-ui-websocket/index.html)
[![Documentation](https://img.shields.io/badge/docs-gh--pages-brightgreen.svg)](https://microcontrollab.github.io/lab-gui-websocket/index.html)

[![NPM](https://nodei.co/npm/lab-ui-websocket.png)](https://npmjs.org/package/lab-ui-websocket)
[![NPM](https://nodei.co/npm/lab-gui-websocket.png)](https://npmjs.org/package/lab-gui-websocket)

# lab-ui-websocket
# lab-gui-websocket

Reconnecting WebSocket interface for [LabUI](https://github.com/MicroControlLab/lab-ui), with specialliced methods to simplify the generalized usage with the LabUi uiGenerator class.
Reconnecting WebSocket interface for [lab-gui](https://github.com/MicroControlLab/lab-gui), with specialliced methods to simplify the generalized usage with the LabUi uiGenerator class.

## Development

See [Contibuting](https://github.com/MicroControlLab/lab-ui-websocket/blob/master/CONTRIBUTING.md)
See [Contibuting](https://github.com/MicroControlLab/lab-gui-websocket/blob/master/CONTRIBUTING.md)

## Credits

Expand Down
50 changes: 36 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
{
"name": "lab-ui-websocket",
"name": "lab-gui-websocket",
"version": "1.0.0",
"description": "",
"keywords": ["typescript", "websocket", "reconnecting", "lab-ui", "MicroControlLab"],
"main": "dist/lab-ui-websocket.umd.js",
"module": "dist/lab-ui-websocket.es5.js",
"typings": "dist/types/lab-ui-websocket.d.ts",
"files": ["dist"],
"keywords": [
"typescript",
"websocket",
"reconnecting",
"lab-ui",
"MicroControlLab"
],
"main": "dist/lab-gui-websocket.umd.js",
"module": "dist/lab-gui-websocket.es5.js",
"typings": "dist/types/lab-gui-websocket.d.ts",
"files": [
"dist"
],
"author": "Sebastian Weigand <s.weigand.phy@gmail.com>",
"repository": {
"type": "git",
"url": "https://github.com/MicroControlLab/lab-ui-websocket.git"
"url": "https://github.com/MicroControlLab/lab-gui-websocket.git"
},
"bugs": {
"url": "https://github.com/MicroControlLab/lab-ui-websocket.git/issues"
"url": "https://github.com/MicroControlLab/lab-gui-websocket.git/issues"
},
"homepage": "https://github.com/MicroControlLab/lab-ui-websocket.git",
"homepage": "https://github.com/MicroControlLab/lab-gui-websocket.git",
"license": "Apache License 2.0",
"engines": {
"node": ">=6.0.0"
Expand All @@ -37,7 +45,10 @@
"precommit": "lint-staged"
},
"lint-staged": {
"{src,test}/**/*.ts": ["prettier --write", "git add"]
"{src,test}/**/*.ts": [
"prettier --write",
"git add"
]
},
"config": {
"commitizen": {
Expand All @@ -50,8 +61,15 @@
},
"testEnvironment": "node",
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": ["ts", "tsx", "js"],
"coveragePathIgnorePatterns": ["/node_modules/", "/test/"],
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/test/"
],
"coverageThreshold": {
"global": {
"branches": 85,
Expand All @@ -60,14 +78,18 @@
"statements": 90
}
},
"collectCoverageFrom": ["src/*.{js,ts}"]
"collectCoverageFrom": [
"src/*.{js,ts}"
]
},
"prettier": {
"semi": false,
"singleQuote": true
},
"commitlint": {
"extends": ["@commitlint/config-conventional"]
"extends": [
"@commitlint/config-conventional"
]
},
"devDependencies": {
"@commitlint/cli": "^7.1.2",
Expand Down
10 changes: 5 additions & 5 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import json from 'rollup-plugin-json'

const pkg = require('./package.json')

const libraryName = 'lab-ui-websocket'
const libraryName = 'lab-gui-websocket'

export default {
input: `src/${libraryName}.ts`,
output: [
{ file: pkg.main, name: camelCase(libraryName), format: 'umd', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external: [],
watch: {
include: 'src/**',
include: 'src/**'
},
plugins: [
// Allow json resolution
Expand All @@ -33,6 +33,6 @@ export default {
resolve(),

// Resolve source maps to the original source
sourceMaps(),
],
sourceMaps()
]
}
30 changes: 15 additions & 15 deletions src/lab-ui-websocket.ts → src/lab-gui-websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* It is API compatible, so when you have:
* ws = new WebSocket('ws://....');
* you can replace with:
* ws = new LabUiWebsocketSettings('ws://....');
* ws = new LabGuiWebsocketSettings('ws://....');
*
* The event stream will typically look like:
* onconnecting
Expand All @@ -29,18 +29,18 @@
* - David Doran
*/

/** Object style to be sent with LabUiWebsocket.send() */
/** Object style to be sent with LabGuiWebsocket.send() */
export interface SendData {
status: string
data?: object
}

export interface LabUiWebsocketSettings extends LabUiWebsocketOptions {
export interface LabGuiWebsocketSettings extends LabGuiWebsocketOptions {
/** Protocolls to be used */
protocols: string[]
}

export interface LabUiWebsocketOptions {
export interface LabGuiWebsocketOptions {
/** Whether this instance should log debug messages. */
debug?: boolean

Expand Down Expand Up @@ -70,7 +70,7 @@ export interface LabUiWebsocketOptions {
binaryType?: 'blob' | 'arraybuffer'
}

export class LabUiWebsocket {
export class LabGuiWebsocket {
private debugAll: boolean = false

// The underlying WebSocket
Expand All @@ -96,7 +96,7 @@ export class LabUiWebsocket {
public onerror: (event: Event) => void = event => {}

// Default settings
settings: LabUiWebsocketSettings = {
settings: LabGuiWebsocketSettings = {
debug: false,
protocols: [],
automaticOpen: true,
Expand All @@ -108,7 +108,7 @@ export class LabUiWebsocket {
binaryType: 'blob'
}

constructor(url: string, options: LabUiWebsocketOptions = {}) {
constructor(url: string, options: LabGuiWebsocketOptions = {}) {
// Overwrite and define settings with options if they exist.
this.settings = { ...this.settings, ...options }
/** The number of attempted reconnects since starting, or the last successful connection. Read only. */
Expand Down Expand Up @@ -142,7 +142,7 @@ export class LabUiWebsocket {
if (typeof event.data === 'string') {
try {
let msgObject: object = JSON.parse(event.data)
this.log('LabUiWebsocket', msgObject)
this.log('LabGuiWebsocket', msgObject)
return msgObject
} catch (err) {
this.log(err, 'Error parsing the message string: ', event.data)
Expand Down Expand Up @@ -178,11 +178,11 @@ export class LabUiWebsocket {
}

this.onconnecting()
this.log('LabUiWebsocket', 'attempt-connect', this.url)
this.log('LabGuiWebsocket', 'attempt-connect', this.url)

let localWs = this.ws
let timeout = setTimeout(() => {
this.log('LabUiWebsocket', 'connection-timeout', this.url)
this.log('LabGuiWebsocket', 'connection-timeout', this.url)
this.timedOut = true
localWs.close()
this.timedOut = false
Expand All @@ -193,7 +193,7 @@ export class LabUiWebsocket {
// { target: WebSocket }
) => {
clearTimeout(timeout)
this.log('LabUiWebsocket', 'onopen', this.url)
this.log('LabGuiWebsocket', 'onopen', this.url)
this.readyState = WebSocket.OPEN
reconnectAttempt = false
this.onopen(event)
Expand All @@ -209,7 +209,7 @@ export class LabUiWebsocket {
this.readyState = WebSocket.CONNECTING
this.onconnecting()
if (!reconnectAttempt && !this.timedOut) {
this.log('LabUiWebsocket', 'onclose', this.url)
this.log('LabGuiWebsocket', 'onclose', this.url)
this.onclose(event)
}
setTimeout(() => {
Expand All @@ -219,11 +219,11 @@ export class LabUiWebsocket {
}

this.ws.onmessage = (event: MessageEvent): void => {
this.log('LabUiWebsocket', 'onmessage', this.url, event.data)
this.log('LabGuiWebsocket', 'onmessage', this.url, event.data)
this.onmessage(event)
}
this.ws.onerror = (event: Event): void => {
this.log('LabUiWebsocket', 'onerror', this.url, event)
this.log('LabGuiWebsocket', 'onerror', this.url, event)
this.onerror(event)
}
}
Expand All @@ -248,7 +248,7 @@ export class LabUiWebsocket {
throw new TypeError(errrorMsg)
}
if (this.ws) {
this.log('LabUiWebsocket', 'send', this.url, data)
this.log('LabGuiWebsocket', 'send', this.url, data)
return this.ws.send(dataString)
} else {
throw new Error('INVALID_STATE_ERR : Pausing to reconnect websocket')
Expand Down
33 changes: 16 additions & 17 deletions tests/lab-ui-websocket.test.ts → tests/lab-gui-websocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*/

import { WebSocket as mockWebSocket, Server, CloseOptions } from 'mock-socket'
import { LabUiWebsocket, LabUiWebsocketOptions, SendData } from '../src/lab-ui-websocket'
import { LabGuiWebsocket, LabGuiWebsocketOptions, SendData } from '../src/lab-gui-websocket'

const getMockLabUiWebsocket = (
const getMockLabGuiWebsocket = (
url: string,
debug: boolean = false,
options?: LabUiWebsocketOptions
): LabUiWebsocket => {
const wsClient = new LabUiWebsocket(url, {
options?: LabGuiWebsocketOptions
): LabGuiWebsocket => {
const wsClient = new LabGuiWebsocket(url, {
debug,
websocketClass: mockWebSocket,
...options
Expand All @@ -31,7 +31,7 @@ const getDelay = (time: number): Promise<{}> => {
return delay
}

describe('Testing LabUiWebsocket', () => {
describe('Testing LabGuiWebsocket', () => {
const url: string = 'ws://localhost:8080'
// the diffentiation between object and string array is needed to to
// a problem with call signatures of union types
Expand All @@ -40,12 +40,12 @@ describe('Testing LabUiWebsocket', () => {
let msgObjectArray: object[]

describe('imports and implementations', () => {
it('LabUiWebsocket class exists with that name', () => {
expect(LabUiWebsocket).toBeDefined()
it('LabGuiWebsocket class exists with that name', () => {
expect(LabGuiWebsocket).toBeDefined()
})

it('WebSocket of LabUiWebsocket is mocked properly', () => {
const wsClient = getMockLabUiWebsocket(url)
it('WebSocket of LabGuiWebsocket is mocked properly', () => {
const wsClient = getMockLabGuiWebsocket(url)
expect(wsClient.wsInstance).toBeInstanceOf(mockWebSocket)
})
})
Expand All @@ -63,7 +63,7 @@ describe('Testing LabUiWebsocket', () => {
socket.send('connected')
})

const wsClient = getMockLabUiWebsocket(url)
const wsClient = getMockLabGuiWebsocket(url)

wsClient.onmessage = (msg: MessageEvent) => {
msgStringArray.push(msg.data)
Expand All @@ -89,7 +89,7 @@ describe('Testing LabUiWebsocket', () => {
})
})

const wsClient = getMockLabUiWebsocket(url)
const wsClient = getMockLabGuiWebsocket(url)

wsClient.onopen = (event: Event) => {
wsClient.send('onopen response from client')
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('Testing LabUiWebsocket', () => {
})
})

const wsClient = getMockLabUiWebsocket(url)
const wsClient = getMockLabGuiWebsocket(url)

const messageObject = { status: 'test respone from string' }

Expand Down Expand Up @@ -150,7 +150,7 @@ describe('Testing LabUiWebsocket', () => {

const messageObject = { status: 'test respone from SentData object' }

const wsClient = getMockLabUiWebsocket(url)
const wsClient = getMockLabGuiWebsocket(url)

wsClient.onopen = (event: Event) => {
wsClient.send(messageObject)
Expand All @@ -175,7 +175,7 @@ describe('Testing LabUiWebsocket', () => {

it('wait 3sec to create server and let the client autoconnect', done => {
let mockServer: Server
const wsClient = getMockLabUiWebsocket(url)
const wsClient = getMockLabGuiWebsocket(url)

wsClient.onopen = (event: Event) => {
msgStringArray.push('connected')
Expand All @@ -195,7 +195,7 @@ describe('Testing LabUiWebsocket', () => {
})
})
describe('Wanted exceptions', () => {
const wsClient = getMockLabUiWebsocket(url, false, {
const wsClient = getMockLabGuiWebsocket(url, false, {
automaticOpen: false
})
it('get_message_object of not a JSON parsable string msg.data', () => {
Expand Down Expand Up @@ -252,6 +252,5 @@ describe('Testing LabUiWebsocket', () => {
it("message_logic wasn't overwritten", () => {
expect(wsClient.close()).toBe(false)
})
// end exception testing
})
})

0 comments on commit 67e6933

Please sign in to comment.