@oox/socketio-client 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/adapter.js +47 -0
- package/browser.js +4150 -0
- package/browser.js.map +1 -0
- package/index.js +3 -0
- package/package.json +34 -0
- package/socket.js +2 -0
- package/types/adapter.d.ts +19 -0
- package/types/index.d.ts +3 -0
- package/types/socket.d.ts +2 -0
- package/types/utils.d.ts +14 -0
- package/utils.js +44 -0
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oox/socketio-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "OOX SocketIO Client Module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org/"
|
|
8
|
+
},
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"types": "./types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./index.js",
|
|
14
|
+
"require": "./index.js",
|
|
15
|
+
"types": "./types/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./browser": "./browser.js"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"oox",
|
|
21
|
+
"socketio",
|
|
22
|
+
"module",
|
|
23
|
+
"websocket",
|
|
24
|
+
"client"
|
|
25
|
+
],
|
|
26
|
+
"author": "lipingruan",
|
|
27
|
+
"email": "hello@ruanmail.com",
|
|
28
|
+
"homepage": "https://gitee.com/lipingruan/oox/tree/main/packages/oox-socketio-client",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"type": "module",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"socket.io-client": "^4.8.3"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/socket.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SampleKeepAliveConnectionAdapter, KeepAliveConnectionData, KeepAliveConnection } from '@oox/client';
|
|
2
|
+
import { Socket } from './socket.js';
|
|
3
|
+
export declare class SocketIOAdapter extends SampleKeepAliveConnectionAdapter<Socket> {
|
|
4
|
+
name: string;
|
|
5
|
+
OOXEvent: {
|
|
6
|
+
CONNECT: string;
|
|
7
|
+
DISCONNECT: string;
|
|
8
|
+
ERROR: string;
|
|
9
|
+
CALL: string;
|
|
10
|
+
READY: string;
|
|
11
|
+
ENABLED: string;
|
|
12
|
+
DISABLED: string;
|
|
13
|
+
REGISTRY_SYNC_CONNECTIONS: string;
|
|
14
|
+
REGISTRY_SUBSCRIBE: string;
|
|
15
|
+
REGISTRY_NOTIFY: string;
|
|
16
|
+
};
|
|
17
|
+
private connectionId;
|
|
18
|
+
newConnection(identify: string | URL | KeepAliveConnectionData): KeepAliveConnection<Socket>;
|
|
19
|
+
}
|
package/types/index.d.ts
ADDED
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const OOXEvent: {
|
|
2
|
+
CONNECT: string;
|
|
3
|
+
DISCONNECT: string;
|
|
4
|
+
ERROR: string;
|
|
5
|
+
CALL: string;
|
|
6
|
+
READY: string;
|
|
7
|
+
ENABLED: string;
|
|
8
|
+
DISABLED: string;
|
|
9
|
+
REGISTRY_SYNC_CONNECTIONS: string;
|
|
10
|
+
REGISTRY_SUBSCRIBE: string;
|
|
11
|
+
REGISTRY_NOTIFY: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function isWebSocketURL(url: string | URL): boolean;
|
|
14
|
+
export declare function genWebSocketURL(url: string): URL;
|
package/utils.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const OOXEvent = {
|
|
2
|
+
CONNECT: 'connect',
|
|
3
|
+
DISCONNECT: 'disconnect',
|
|
4
|
+
ERROR: 'connect_error',
|
|
5
|
+
CALL: 'call',
|
|
6
|
+
READY: 'oox:ready',
|
|
7
|
+
ENABLED: 'oox:enabled',
|
|
8
|
+
DISABLED: 'oox:disabled',
|
|
9
|
+
REGISTRY_SYNC_CONNECTIONS: 'oox:registry:sync_connections',
|
|
10
|
+
REGISTRY_SUBSCRIBE: 'oox:registry:subscribe',
|
|
11
|
+
REGISTRY_NOTIFY: 'oox:registry:notify',
|
|
12
|
+
};
|
|
13
|
+
export function isWebSocketURL(url) {
|
|
14
|
+
if ('string' === typeof url) {
|
|
15
|
+
return /^wss?:\/\/.+$/.test(url);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return url.protocol === 'ws:' || url.protocol === 'wss:';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function genWebSocketURL(url) {
|
|
22
|
+
// :6000
|
|
23
|
+
if (url.startsWith(':'))
|
|
24
|
+
url = 'ws://localhost' + url;
|
|
25
|
+
// 127.0.0.1:6000
|
|
26
|
+
if (!/^\w+?:\/.+$/.test(url))
|
|
27
|
+
url = 'ws://' + url;
|
|
28
|
+
const urlObject = new URL(url);
|
|
29
|
+
// :8000 => :8000/ws
|
|
30
|
+
const notSetPath = !urlObject.pathname || (urlObject.pathname === '/'
|
|
31
|
+
&& !url.endsWith('/')
|
|
32
|
+
&& !urlObject.search
|
|
33
|
+
&& !urlObject.hash);
|
|
34
|
+
if (notSetPath) {
|
|
35
|
+
urlObject.pathname = '/socket.io';
|
|
36
|
+
}
|
|
37
|
+
if (urlObject.protocol !== 'wss:') {
|
|
38
|
+
if (urlObject.port === '443')
|
|
39
|
+
urlObject.protocol = 'wss:';
|
|
40
|
+
else
|
|
41
|
+
urlObject.protocol = 'ws:';
|
|
42
|
+
}
|
|
43
|
+
return urlObject;
|
|
44
|
+
}
|