Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
WarstekHUN committed Oct 7, 2023
1 parent bb22f1b commit aec60f1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
19 changes: 2 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
- Fixed an issue importing the library.

## Breaking Changes

### New importing
From now on, there is no default export.

ESM

```ts
import { connectTo } from "zilaws-client";
```

CommonJS
```ts
const { connectTo } = require("zilaws-client");
```
- Fixed an issue that made ZilaWS uncompatible with browsers.
- Fixed an issue that because of VSCode wanted to import the types by default.
4 changes: 4 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ module.exports = {
new TerserPlugin()
]
},
externalsType: 'self',
externals: {
ws: 'WebSocket'
},
resolve: {
extensions: ['.ts', '.js', '.tsx', '.jsx'],
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"$schema": "https://json.schemastore.org/package",
"name": "zilaws-client",
"version": "1.1.0",
"version": "1.1.1",
"description": "ZilaWS is a blazingly fast and very lightweight library that provides an extremely easy-to-use way to transmit data via websockets between clientside and serverside using eventhandlers and async waiters.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"umd:main": "dist/umd/index.js",
"types": "dist/types/index.d.js",
"types": "dist/types/index.d.ts",
"browser": "dist/umd/index.js",
"scripts": {
"build": "npm run format:fix && npm run test:cov-build && npm run format:fix && npm run build:cjs && npm run build:esm && npm run build:umd && npm run build:types",
Expand Down
27 changes: 16 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ZilaConnection {
private localEventCallbacks: {
[K in keyof ICallableLocalEvents]?: Array<ICallableLocalEvents[K]>;
} = {};
private connection: WebSocket | undefined;
private connection: WebSocket | globalThis.WebSocket | undefined;
private errorCallback: errorCallbackType | undefined;
private _status: WSStatus = WSStatus.OPENING;

Expand Down Expand Up @@ -90,12 +90,17 @@ export class ZilaConnection {
allowSelfSignedCert = false
): Promise<ZilaConnection> {
return new Promise(async (resolve, reject) => {
let ws: WebSocket | undefined;
let ws: WebSocket | globalThis.WebSocket | undefined;

try {
ws = new WebSocket(wsUrl, {
rejectUnauthorized: !allowSelfSignedCert,
});
/* istanbul ignore next */
if (typeof window !== "undefined" && typeof window.document !== "undefined") {
ws = new window.WebSocket(wsUrl);
} else {
ws = new WebSocket(wsUrl, {
rejectUnauthorized: !allowSelfSignedCert,
});
}
} catch (error) {
const errorMessage = (error as Error).stack?.split("\n")[0];
if (error && errorCallback) errorCallback(errorMessage);
Expand All @@ -114,12 +119,12 @@ export class ZilaConnection {
});
}

private constructor(ws: WebSocket, errorCallback?: errorCallbackType) {
private constructor(ws: WebSocket | globalThis.WebSocket, errorCallback?: errorCallbackType) {
this.connection = ws;
this.errorCallback = errorCallback;
this._status = WSStatus.OPENING;

this.connection.onerror = async (event) => {
this.connection.onerror = async () => {
this.status = WSStatus.ERROR;

this.errorCallback?.call(undefined);
Expand All @@ -131,15 +136,15 @@ export class ZilaConnection {
this.status = WSStatus.OPEN;
};

this.connection.onclose = (ev) => {
if (ev.code == CloseCodes.BANNED) {
this.connection.onclose = ({ code, reason }: { code: number; reason: string }) => {
if (code == CloseCodes.BANNED) {
console.error("ZilaWS: The client is banned from the WebSocket server.");
} else if (ev.code == CloseCodes.KICKED) {
} else if (code == CloseCodes.KICKED) {
console.error("ZilaWS: The client got disconnected from the server.");
}

this.status = WSStatus.CLOSED;
if (this.errorCallback) this.errorCallback(ev.reason);
if (this.errorCallback) this.errorCallback(reason);
};

this.connection.onmessage = (ev: any) => {
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connectTo, WSStatus, ZilaConnection } from "../src/index";
import {ZilaServer, ZilaClient } from "zilaws-server";
import { ZilaServer, ZilaClient } from "zilaws-server";

var client: ZilaConnection;
var server: ZilaServer;
Expand Down

0 comments on commit aec60f1

Please sign in to comment.