@vworlds/dgram-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/dgram-client/src/client/client-socket.d.ts +21 -0
- package/dgram-client/src/client/client-socket.js +61 -0
- package/dgram-client/src/client/client-socket.js.map +1 -0
- package/dgram-client/src/index.d.ts +3 -0
- package/dgram-client/src/index.js +8 -0
- package/dgram-client/src/index.js.map +1 -0
- package/dgram-client/src/webrtc/webrtc-client-connection.d.ts +52 -0
- package/dgram-client/src/webrtc/webrtc-client-connection.js +200 -0
- package/dgram-client/src/webrtc/webrtc-client-connection.js.map +1 -0
- package/dgram-common/src/constants.d.ts +18 -0
- package/dgram-common/src/constants.js +19 -0
- package/dgram-common/src/constants.js.map +1 -0
- package/dgram-common/src/events.d.ts +26 -0
- package/dgram-common/src/events.js +42 -0
- package/dgram-common/src/events.js.map +1 -0
- package/dgram-common/src/index.d.ts +5 -0
- package/dgram-common/src/index.js +4 -0
- package/dgram-common/src/index.js.map +1 -0
- package/dgram-common/src/socket.d.ts +27 -0
- package/dgram-common/src/socket.js +5 -0
- package/dgram-common/src/socket.js.map +1 -0
- package/package.json +17 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Socket } from '../../../dgram-common/src/index.js';
|
|
2
|
+
/** Browser-side dgram socket that exposes a small socket-like API over WebRTC. */
|
|
3
|
+
export declare class ClientSocket extends Socket {
|
|
4
|
+
/** Low-level WebRTC/signaling connection used by this socket. */
|
|
5
|
+
private client;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a browser dgram socket.
|
|
8
|
+
*
|
|
9
|
+
* @param url Signaling API base URL, for example `http://localhost:3000/rtc/v1`.
|
|
10
|
+
* @param rtcConfig Browser `RTCPeerConnection` configuration, usually ICE servers.
|
|
11
|
+
*/
|
|
12
|
+
constructor(url: string, rtcConfig: RTCConfiguration);
|
|
13
|
+
/** Connection id assigned by the signaling server after `connect()` succeeds. */
|
|
14
|
+
get id(): string;
|
|
15
|
+
/** Opens signaling, receives the server offer, sends an answer, and waits for the data channel. */
|
|
16
|
+
connect(): Promise<void>;
|
|
17
|
+
/** Sends one binary payload over the open data channel. */
|
|
18
|
+
send(data: Uint8Array): void;
|
|
19
|
+
/** Closes the browser peer connection and asks the signaling server to close its side. */
|
|
20
|
+
close(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { WebRTCClientConnection } from '../webrtc/webrtc-client-connection.js';
|
|
2
|
+
import { EVENTS, Socket, } from '../../../dgram-common/src/index.js';
|
|
3
|
+
/** Browser-side dgram socket that exposes a small socket-like API over WebRTC. */
|
|
4
|
+
export class ClientSocket extends Socket {
|
|
5
|
+
/** Low-level WebRTC/signaling connection used by this socket. */
|
|
6
|
+
client;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a browser dgram socket.
|
|
9
|
+
*
|
|
10
|
+
* @param url Signaling API base URL, for example `http://localhost:3000/rtc/v1`.
|
|
11
|
+
* @param rtcConfig Browser `RTCPeerConnection` configuration, usually ICE servers.
|
|
12
|
+
*/
|
|
13
|
+
constructor(url, rtcConfig) {
|
|
14
|
+
super();
|
|
15
|
+
this.client = new WebRTCClientConnection(url, 'dgram', rtcConfig);
|
|
16
|
+
this.client.on(EVENTS.DISCONNECTED, (reason) => {
|
|
17
|
+
this.emit('disconnect');
|
|
18
|
+
this.client.removeAllListeners();
|
|
19
|
+
});
|
|
20
|
+
this.client.on(EVENTS.CONNECTION, (status) => {
|
|
21
|
+
this.emit('connect', status);
|
|
22
|
+
});
|
|
23
|
+
this.client.on(EVENTS.MESSAGE, (data) => {
|
|
24
|
+
let bytes;
|
|
25
|
+
if (data instanceof ArrayBuffer) {
|
|
26
|
+
bytes = new Uint8Array(data);
|
|
27
|
+
}
|
|
28
|
+
else if (data instanceof Uint8Array) {
|
|
29
|
+
bytes = data;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log('Invalid data type');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
this.emit('receive', bytes);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Connection id assigned by the signaling server after `connect()` succeeds. */
|
|
39
|
+
get id() {
|
|
40
|
+
return this.client.id;
|
|
41
|
+
}
|
|
42
|
+
/** Opens signaling, receives the server offer, sends an answer, and waits for the data channel. */
|
|
43
|
+
async connect() {
|
|
44
|
+
await this.client.connect();
|
|
45
|
+
this.client.localPeerConnection.onconnectionstatechange = () => {
|
|
46
|
+
if (this.client.localPeerConnection.connectionState === 'disconnected' ||
|
|
47
|
+
this.client.localPeerConnection.connectionState === 'closed') {
|
|
48
|
+
this.client.emit(EVENTS.DISCONNECTED);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Sends one binary payload over the open data channel. */
|
|
53
|
+
send(data) {
|
|
54
|
+
this.client.sendMessage(data);
|
|
55
|
+
}
|
|
56
|
+
/** Closes the browser peer connection and asks the signaling server to close its side. */
|
|
57
|
+
close() {
|
|
58
|
+
this.client.close();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=client-socket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-socket.js","sourceRoot":"","sources":["../../../../src/client/client-socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EACL,MAAM,EACN,MAAM,GAEP,MAAM,oCAAoC,CAAC;AAE5C,kFAAkF;AAClF,MAAM,OAAO,YAAa,SAAQ,MAAM;IACtC,iEAAiE;IACzD,MAAM,CAAyB;IAEvC;;;;;OAKG;IACH,YAAY,GAAW,EAAE,SAA2B;QAClD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,MAAM,GAAG,IAAI,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QAElE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC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,EAC5D,CAAC;gBACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACxC,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAED,2DAA2D;IACpD,IAAI,CAAC,IAAgB;QAC1B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,0FAA0F;IACnF,KAAK;QACV,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// import DgramServer from "./server/dgram-server.js";
|
|
2
|
+
// import { ServerOptions } from "./server/server-options.js";
|
|
3
|
+
// export default DgramServer;
|
|
4
|
+
// export { DgramServer, ServerOptions };
|
|
5
|
+
import { ClientSocket } from './client/client-socket.js';
|
|
6
|
+
export default ClientSocket;
|
|
7
|
+
export { ClientSocket };
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,8DAA8D;AAE9D,8BAA8B;AAC9B,yCAAyC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,eAAe,YAAY,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Events } from '../../../dgram-common/src/index.js';
|
|
2
|
+
/** Response returned by the server when creating a WebRTC connection. */
|
|
3
|
+
interface RTCRemotePeerConnection {
|
|
4
|
+
/** Server-side connection id used by later signaling calls. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Server-created offer that the browser uses as its remote description. */
|
|
7
|
+
localDescription: {
|
|
8
|
+
/** Session description protocol body. */
|
|
9
|
+
sdp: string;
|
|
10
|
+
/** SDP description type, usually `offer`. */
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** Handles browser WebRTC signaling and data channel lifecycle for `ClientSocket`. */
|
|
15
|
+
export declare class WebRTCClientConnection extends Events {
|
|
16
|
+
serverUrl: string;
|
|
17
|
+
label: string;
|
|
18
|
+
rtcConfiguration: RTCConfiguration;
|
|
19
|
+
/** Server-assigned connection id. Empty until `connect()` creates a server peer. */
|
|
20
|
+
id: string;
|
|
21
|
+
/** Browser `RTCPeerConnection` used for the active session. */
|
|
22
|
+
localPeerConnection: RTCPeerConnection;
|
|
23
|
+
/** Server peer metadata and offer returned by the signaling API. */
|
|
24
|
+
remotePeerConnection: RTCRemotePeerConnection;
|
|
25
|
+
/** Browser data channel created by the server and delivered through `datachannel`. */
|
|
26
|
+
dataChannel: RTCDataChannel;
|
|
27
|
+
/**
|
|
28
|
+
* Creates the low-level browser connection wrapper.
|
|
29
|
+
*
|
|
30
|
+
* @param serverUrl Signaling API base URL.
|
|
31
|
+
* @param label Expected WebRTC data channel label.
|
|
32
|
+
* @param rtcConfiguration Browser peer connection configuration.
|
|
33
|
+
*/
|
|
34
|
+
constructor(serverUrl: string, label: string, rtcConfiguration: RTCConfiguration);
|
|
35
|
+
/** Accepts the server-created data channel and wires message/open/close handlers. */
|
|
36
|
+
private onDataChannel;
|
|
37
|
+
/** Fetches newly gathered server ICE candidates and adds them to the browser peer. */
|
|
38
|
+
private fetchAdditionalCandidates;
|
|
39
|
+
/** Resolves after the server-created data channel event arrives. */
|
|
40
|
+
private waitForDataChannel;
|
|
41
|
+
/** Performs HTTP signaling and prepares the browser peer connection. */
|
|
42
|
+
connect(): Promise<{
|
|
43
|
+
error: any;
|
|
44
|
+
} | undefined>;
|
|
45
|
+
/** Sends one payload over the browser data channel when it is open. */
|
|
46
|
+
sendMessage(data: any): Promise<void>;
|
|
47
|
+
/** Returns true when the browser data channel still has buffered bytes to flush. */
|
|
48
|
+
isBuffering(): boolean;
|
|
49
|
+
/** Closes the browser peer connection and notifies the signaling server. */
|
|
50
|
+
close(): void;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ERRORS, EVENTS, Events } from '../../../dgram-common/src/index.js';
|
|
2
|
+
/** Handles browser WebRTC signaling and data channel lifecycle for `ClientSocket`. */
|
|
3
|
+
export class WebRTCClientConnection extends Events {
|
|
4
|
+
serverUrl;
|
|
5
|
+
label;
|
|
6
|
+
rtcConfiguration;
|
|
7
|
+
/** Server-assigned connection id. Empty until `connect()` creates a server peer. */
|
|
8
|
+
id;
|
|
9
|
+
/** Browser `RTCPeerConnection` used for the active session. */
|
|
10
|
+
localPeerConnection;
|
|
11
|
+
/** Server peer metadata and offer returned by the signaling API. */
|
|
12
|
+
remotePeerConnection;
|
|
13
|
+
/** Browser data channel created by the server and delivered through `datachannel`. */
|
|
14
|
+
dataChannel;
|
|
15
|
+
/**
|
|
16
|
+
* Creates the low-level browser connection wrapper.
|
|
17
|
+
*
|
|
18
|
+
* @param serverUrl Signaling API base URL.
|
|
19
|
+
* @param label Expected WebRTC data channel label.
|
|
20
|
+
* @param rtcConfiguration Browser peer connection configuration.
|
|
21
|
+
*/
|
|
22
|
+
constructor(serverUrl, label, rtcConfiguration) {
|
|
23
|
+
super();
|
|
24
|
+
this.serverUrl = serverUrl;
|
|
25
|
+
this.label = label;
|
|
26
|
+
this.rtcConfiguration = rtcConfiguration;
|
|
27
|
+
this.id = '';
|
|
28
|
+
}
|
|
29
|
+
/** Accepts the server-created data channel and wires message/open/close handlers. */
|
|
30
|
+
onDataChannel(ev) {
|
|
31
|
+
const { channel } = ev;
|
|
32
|
+
if (channel.label !== this.label) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
this.dataChannel = channel;
|
|
36
|
+
// set default binaryType to arraybuffer
|
|
37
|
+
// https://github.com/node-webrtc/node-webrtc/issues/441
|
|
38
|
+
this.dataChannel.binaryType = 'arraybuffer';
|
|
39
|
+
this.dataChannel.onmessage = (ev) => {
|
|
40
|
+
this.emit(EVENTS.MESSAGE, ev.data);
|
|
41
|
+
};
|
|
42
|
+
this.dataChannel.onopen = () => {
|
|
43
|
+
this.emit(EVENTS.CONNECTION);
|
|
44
|
+
};
|
|
45
|
+
this.dataChannel.onclose = () => {
|
|
46
|
+
this.emit(EVENTS.DISCONNECTED);
|
|
47
|
+
};
|
|
48
|
+
if (this.dataChannel.readyState === 'open') {
|
|
49
|
+
this.emit(EVENTS.CONNECTION);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Fetches newly gathered server ICE candidates and adds them to the browser peer. */
|
|
53
|
+
async fetchAdditionalCandidates(serverUrl, id) {
|
|
54
|
+
if (this.dataChannel?.readyState === 'closed') {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const res = await fetch(`${serverUrl}/connection/${id}/candidates`, {
|
|
58
|
+
method: 'GET',
|
|
59
|
+
headers: {
|
|
60
|
+
'Content-Type': 'application/json',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
if (res.ok) {
|
|
64
|
+
const candidates = (await res.json());
|
|
65
|
+
candidates.forEach((c) => {
|
|
66
|
+
this.localPeerConnection.addIceCandidate(c);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Resolves after the server-created data channel event arrives. */
|
|
71
|
+
async waitForDataChannel() {
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
this.localPeerConnection?.addEventListener('datachannel', () => {
|
|
74
|
+
resolve();
|
|
75
|
+
}, { once: true });
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** Performs HTTP signaling and prepares the browser peer connection. */
|
|
79
|
+
async connect() {
|
|
80
|
+
const rtcpc = globalThis.RTCPeerConnection;
|
|
81
|
+
if (!rtcpc) {
|
|
82
|
+
this.emit(EVENTS.CONNECTION, {
|
|
83
|
+
status: -1,
|
|
84
|
+
statusText: ERRORS.BROWSER_NOT_SUPPORTED,
|
|
85
|
+
});
|
|
86
|
+
throw new Error(`Connection failed with error ${ERRORS.BROWSER_NOT_SUPPORTED}`);
|
|
87
|
+
}
|
|
88
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
89
|
+
try {
|
|
90
|
+
const res = await fetch(`${this.serverUrl}/connection`, {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
headers,
|
|
93
|
+
});
|
|
94
|
+
if (res.status >= 300) {
|
|
95
|
+
this.emit(EVENTS.CONNECTION, {
|
|
96
|
+
status: -1,
|
|
97
|
+
statusText: `Connection failed with status ${res.status}`,
|
|
98
|
+
});
|
|
99
|
+
throw new Error(`Connection failed with status ${res.status}`);
|
|
100
|
+
}
|
|
101
|
+
this.remotePeerConnection = (await res.json());
|
|
102
|
+
this.id = this.remotePeerConnection.id;
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
console.log(err);
|
|
106
|
+
this.emit(EVENTS.CONNECTION, { status: -1, statusText: err?.toString() });
|
|
107
|
+
throw new Error(`Connection failed with error ${err}`);
|
|
108
|
+
}
|
|
109
|
+
const configuration = {
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
sdpSemantics: 'unified-plan',
|
|
112
|
+
...this.rtcConfiguration,
|
|
113
|
+
};
|
|
114
|
+
// create rtc peer connection
|
|
115
|
+
this.localPeerConnection = new rtcpc(configuration);
|
|
116
|
+
// get additional ice candidates
|
|
117
|
+
// we do still continue to gather candidates even if the connection is established,
|
|
118
|
+
// maybe we get a better connection.
|
|
119
|
+
// So the server is still gathering candidates and we ask for them frequently.
|
|
120
|
+
const showBackOffIntervals = (attempts = 10, initial = 50, factor = 1.8, jitter = 20) => Array(attempts)
|
|
121
|
+
.fill(0)
|
|
122
|
+
.map((_, index) => parseInt((initial * factor ** index).toString()) +
|
|
123
|
+
parseInt((Math.random() * jitter).toString()));
|
|
124
|
+
showBackOffIntervals().forEach((ms) => {
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
this.fetchAdditionalCandidates(this.serverUrl, this.id).catch(() => { });
|
|
127
|
+
}, ms);
|
|
128
|
+
});
|
|
129
|
+
try {
|
|
130
|
+
await this.localPeerConnection.setRemoteDescription(this.remotePeerConnection.localDescription);
|
|
131
|
+
this.localPeerConnection.addEventListener('datachannel', this.onDataChannel.bind(this), { once: true });
|
|
132
|
+
const originalAnswer = await this.localPeerConnection.createAnswer();
|
|
133
|
+
const updatedAnswer = new RTCSessionDescription({
|
|
134
|
+
type: 'answer',
|
|
135
|
+
sdp: originalAnswer.sdp ?? '',
|
|
136
|
+
});
|
|
137
|
+
await this.localPeerConnection.setLocalDescription(updatedAnswer);
|
|
138
|
+
try {
|
|
139
|
+
await fetch(`${this.serverUrl}/connection/${this.id}/remote-desc`, {
|
|
140
|
+
method: 'POST',
|
|
141
|
+
body: JSON.stringify(this.localPeerConnection.localDescription),
|
|
142
|
+
headers: {
|
|
143
|
+
'Content-Type': 'application/json',
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
console.error(error.message);
|
|
149
|
+
return { error };
|
|
150
|
+
}
|
|
151
|
+
if (!this.dataChannel) {
|
|
152
|
+
await this.waitForDataChannel();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
console.error(err?.message);
|
|
157
|
+
this.localPeerConnection.close();
|
|
158
|
+
this.emit(EVENTS.CONNECTION, { status: -1, statusText: err?.toString() });
|
|
159
|
+
throw new Error(`Connection failed with error ${err}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Sends one payload over the browser data channel when it is open. */
|
|
163
|
+
async sendMessage(data) {
|
|
164
|
+
if (!this.dataChannel) {
|
|
165
|
+
throw new Error(ERRORS.DATA_CHANNEL_NOT_CREATED);
|
|
166
|
+
}
|
|
167
|
+
if (this.dataChannel.readyState === 'open' ||
|
|
168
|
+
this.dataChannel.isOpen?.()) {
|
|
169
|
+
try {
|
|
170
|
+
this.dataChannel.send(data);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.log(error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/** Returns true when the browser data channel still has buffered bytes to flush. */
|
|
178
|
+
isBuffering() {
|
|
179
|
+
if (this.dataChannel) {
|
|
180
|
+
return this.dataChannel.bufferedAmount > 0;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
/** Closes the browser peer connection and notifies the signaling server. */
|
|
185
|
+
close() {
|
|
186
|
+
this.localPeerConnection.close();
|
|
187
|
+
try {
|
|
188
|
+
fetch(`${this.serverUrl}/connection/${this.id}/close`, {
|
|
189
|
+
method: 'POST',
|
|
190
|
+
headers: {
|
|
191
|
+
'Content-Type': 'application/json',
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
console.error(error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=webrtc-client-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webrtc-client-connection.js","sourceRoot":"","sources":["../../../../src/webrtc/webrtc-client-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAe5E,sFAAsF;AACtF,MAAM,OAAO,sBAAuB,SAAQ,MAAM;IAkBvC;IACA;IACA;IAnBT,oFAAoF;IAC7E,EAAE,CAAS;IAClB,+DAA+D;IACxD,mBAAmB,CAAqB;IAC/C,oEAAoE;IAC7D,oBAAoB,CAA2B;IACtD,sFAAsF;IAC/E,WAAW,CAAkB;IAEpC;;;;;;OAMG;IACH,YACS,SAAiB,EACjB,KAAa,EACb,gBAAkC;QAEzC,KAAK,EAAE,CAAC;QAJD,cAAS,GAAT,SAAS,CAAQ;QACjB,UAAK,GAAL,KAAK,CAAQ;QACb,qBAAgB,GAAhB,gBAA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I,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,GAAG,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4EAA4E;IACrE,KAAK;QACV,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC;QAEjC,IAAI,CAAC;YACH,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,eAAe,IAAI,CAAC,EAAE,QAAQ,EAAE;gBACrD,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;iBACnC;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const EVENTS: {
|
|
2
|
+
CONNECT: string;
|
|
3
|
+
CONNECTION: string;
|
|
4
|
+
DATA_CHANNEL_IS_OPEN: string;
|
|
5
|
+
DISCONNECTED: string;
|
|
6
|
+
ERROR: string;
|
|
7
|
+
MESSAGE: string;
|
|
8
|
+
};
|
|
9
|
+
declare const ERRORS: {
|
|
10
|
+
BROWSER_NOT_SUPPORTED: string;
|
|
11
|
+
COULD_NOT_PARSE_MESSAGE: string;
|
|
12
|
+
DROPPED_FROM_BUFFERING: string;
|
|
13
|
+
MAX_MESSAGE_SIZE_EXCEEDED: string;
|
|
14
|
+
PEER_CONNECTION_NOT_CREATED: string;
|
|
15
|
+
DATA_CHANNEL_NOT_CREATED: string;
|
|
16
|
+
CONNECTION_CLOSED: string;
|
|
17
|
+
};
|
|
18
|
+
export { EVENTS, ERRORS };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const EVENTS = {
|
|
2
|
+
CONNECT: 'connect',
|
|
3
|
+
CONNECTION: 'connection',
|
|
4
|
+
DATA_CHANNEL_IS_OPEN: 'dataChannelIsOpen',
|
|
5
|
+
DISCONNECTED: 'disconnected',
|
|
6
|
+
ERROR: 'error',
|
|
7
|
+
MESSAGE: 'rawMessage',
|
|
8
|
+
};
|
|
9
|
+
const ERRORS = {
|
|
10
|
+
BROWSER_NOT_SUPPORTED: 'BROWSER_NOT_SUPPORTED',
|
|
11
|
+
COULD_NOT_PARSE_MESSAGE: 'COULD_NOT_PARSE_MESSAGE',
|
|
12
|
+
DROPPED_FROM_BUFFERING: 'DROPPED_FROM_BUFFERING',
|
|
13
|
+
MAX_MESSAGE_SIZE_EXCEEDED: 'MAX_MESSAGE_SIZE_EXCEEDED',
|
|
14
|
+
PEER_CONNECTION_NOT_CREATED: 'PEER_CONNECTION_NOT_CREATED',
|
|
15
|
+
DATA_CHANNEL_NOT_CREATED: 'DATA_CHANNEL_NOT_CREATED',
|
|
16
|
+
CONNECTION_CLOSED: 'CONNECTION_CLOSED',
|
|
17
|
+
};
|
|
18
|
+
export { EVENTS, ERRORS };
|
|
19
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../dgram-common/src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;IACxB,oBAAoB,EAAE,mBAAmB;IACzC,YAAY,EAAE,cAAc;IAC5B,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,YAAY;CACtB,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,qBAAqB,EAAE,uBAAuB;IAC9C,uBAAuB,EAAE,yBAAyB;IAClD,sBAAsB,EAAE,wBAAwB;IAChD,yBAAyB,EAAE,2BAA2B;IACtD,2BAA2B,EAAE,6BAA6B;IAC1D,wBAAwB,EAAE,0BAA0B;IACpD,iBAAiB,EAAE,mBAAmB;CACvC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed eventemitter3 wrapper used by dgram sockets and listener classes.
|
|
3
|
+
* Inspired by @yandeu/events: https://github.com/yandeu/events
|
|
4
|
+
*/
|
|
5
|
+
type ValidEventMap<T = any> = T extends {
|
|
6
|
+
[P in keyof T]: (...args: any[]) => void;
|
|
7
|
+
} ? T : never;
|
|
8
|
+
type Handler<T extends any | ((...args: any[]) => R), R = any> = T;
|
|
9
|
+
export type EventListener<T extends ValidEventMap, K extends EventNames<T>> = T extends string | symbol ? (...args: any[]) => void : K extends keyof T ? Handler<T[K], void> : never;
|
|
10
|
+
type EventArgs<T extends ValidEventMap, K extends EventNames<T>> = Parameters<EventListener<T, K>>;
|
|
11
|
+
export type EventNames<T extends ValidEventMap> = T extends string | symbol ? T : keyof T;
|
|
12
|
+
declare class events<EventMap extends ValidEventMap = any> {
|
|
13
|
+
on<T extends EventNames<EventMap>>(event: T, fn: EventListener<EventMap, T>, context?: any): events<EventMap>;
|
|
14
|
+
emit<T extends EventNames<EventMap>>(event: T, ...args: EventArgs<EventMap, T>): boolean;
|
|
15
|
+
once<T extends EventNames<EventMap>>(event: T, fn: EventListener<EventMap, T>, context?: any): events<EventMap>;
|
|
16
|
+
eventNames(): EventNames<EventMap>[];
|
|
17
|
+
listeners(event: EventNames<EventMap>): any[];
|
|
18
|
+
listenerCount(event: EventNames<EventMap>): any;
|
|
19
|
+
removeListener<T extends EventNames<EventMap>>(event: T, fn?: EventListener<EventMap, T>, context?: any, once?: boolean): this;
|
|
20
|
+
removeAllListeners(event?: EventNames<EventMap>): this;
|
|
21
|
+
off<T extends EventNames<EventMap>>(event: T, fn?: EventListener<EventMap, T> | undefined, context?: any, once?: boolean | undefined): events<EventMap>;
|
|
22
|
+
addListener<T extends EventNames<EventMap>>(event: T, fn: EventListener<EventMap, T>, context?: any): events<EventMap>;
|
|
23
|
+
}
|
|
24
|
+
export declare class Events<EventMap extends ValidEventMap = any> extends events<EventMap> {
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed eventemitter3 wrapper used by dgram sockets and listener classes.
|
|
3
|
+
* Inspired by @yandeu/events: https://github.com/yandeu/events
|
|
4
|
+
*/
|
|
5
|
+
import eventEmitter3 from 'eventemitter3';
|
|
6
|
+
const { EventEmitter } = eventEmitter3;
|
|
7
|
+
class events {
|
|
8
|
+
on(event, fn, context) {
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
emit(event, ...args) {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
once(event, fn, context) {
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
eventNames() {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
listeners(event) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
listenerCount(event) {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
removeListener(event, fn, context, once) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
removeAllListeners(event) {
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
off(event, fn, context, once) {
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
addListener(event, fn, context) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
events = EventEmitter;
|
|
40
|
+
export class Events extends events {
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../dgram-common/src/events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,aAAa,MAAM,eAAe,CAAC;AAE1C,MAAM,EAAE,YAAY,EAAE,GAAG,aAAa,CAAC;AA2BvC,MAAM,MAAM;IACH,EAAE,CACP,KAAQ,EACR,EAA8B,EAC9B,OAAa;QAEb,OAAO,CAAQ,CAAC;IAClB,CAAC;IAEM,IAAI,CACT,KAAQ,EACR,GAAG,IAA4B;QAE/B,OAAO,CAAQ,CAAC;IAClB,CAAC;IAEM,IAAI,CACT,KAAQ,EACR,EAA8B,EAC9B,OAAa;QAEb,OAAO,CAAQ,CAAC;IAClB,CAAC;IAEM,UAAU;QACf,OAAO,CAAQ,CAAC;IAClB,CAAC;IAEM,SAAS,CAAC,KAA2B;QAC1C,OAAO,CAAQ,CAAC;IAClB,CAAC;IAEM,aAAa,CAAC,KAA2B;QAC9C,OAAO,CAAQ,CAAC;IAClB,CAAC;IAEM,cAAc,CACnB,KAAQ,EACR,EAA+B,EAC/B,OAAa,EACb,IAAc;QAEd,OAAO,CAAQ,CAAC;IAClB,CAAC;IAED,kBAAkB,CAAC,KAA4B;QAC7C,OAAO,CAAQ,CAAC;IAClB,CAAC;IAEM,GAAG,CACR,KAAQ,EACR,EAA2C,EAC3C,OAAa,EACb,IAA0B;QAE1B,OAAO,CAAQ,CAAC;IAClB,CAAC;IAEM,WAAW,CAChB,KAAQ,EACR,EAA8B,EAC9B,OAAa;QAEb,OAAO,CAAQ,CAAC;IAClB,CAAC;CACF;AAEA,MAAc,GAAG,YAAY,CAAC;AAE/B,MAAM,OAAO,MAEX,SAAQ,MAAgB;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dgram-common/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Events } from './events.js';
|
|
2
|
+
/** Describes a connection failure reported through the socket `connect` event. */
|
|
3
|
+
export interface ConnectionError extends Error {
|
|
4
|
+
/** Numeric status code for the failure. Browser support failures use `-1`. */
|
|
5
|
+
status: number;
|
|
6
|
+
/** Human-readable status text suitable for logs or UI. */
|
|
7
|
+
statusText: string;
|
|
8
|
+
}
|
|
9
|
+
/** Events emitted by dgram socket implementations. */
|
|
10
|
+
interface SocketEvents {
|
|
11
|
+
/** Fired after the peer connection or data channel closes. */
|
|
12
|
+
disconnect: () => void;
|
|
13
|
+
/** Fired when binary payload data arrives from the remote peer. */
|
|
14
|
+
receive: (data: Uint8Array) => void;
|
|
15
|
+
/** Fired when the socket connects, or with an error when setup fails. */
|
|
16
|
+
connect: (err?: ConnectionError) => void;
|
|
17
|
+
}
|
|
18
|
+
/** Common socket-shaped interface implemented by browser and server dgram sockets. */
|
|
19
|
+
export declare abstract class Socket extends Events<SocketEvents> {
|
|
20
|
+
/** Stable connection id assigned by the signaling server. */
|
|
21
|
+
abstract get id(): string;
|
|
22
|
+
/** Sends one binary datagram-like payload over the underlying WebRTC data channel. */
|
|
23
|
+
abstract send(data: Uint8Array): void;
|
|
24
|
+
/** Closes the underlying WebRTC connection and releases resources. */
|
|
25
|
+
abstract close(): void;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../../../dgram-common/src/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAoBrC,sFAAsF;AACtF,MAAM,OAAgB,MAAO,SAAQ,MAAoB;CAOxD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vworlds/dgram-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dgram-client/src/index.js",
|
|
6
|
+
"types": "./dgram-client/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dgram-client/src/index.d.ts",
|
|
10
|
+
"default": "./dgram-client/src/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"eventemitter3": "^4.0.7"
|
|
15
|
+
},
|
|
16
|
+
"license": "UNLICENSED"
|
|
17
|
+
}
|