@eleven-am/pondsocket-client 0.0.19 → 0.0.20
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/browser/client.js +2 -1
- package/browser/client.test.js +26 -2
- package/package.json +2 -2
package/browser/client.js
CHANGED
|
@@ -47,7 +47,8 @@ class PondClient {
|
|
|
47
47
|
const socket = new WebSocket(this._address.toString());
|
|
48
48
|
socket.onmessage = (message) => {
|
|
49
49
|
const data = JSON.parse(message.data);
|
|
50
|
-
|
|
50
|
+
const event = pondsocket_common_1.channelEventSchema.parse(data);
|
|
51
|
+
this._broadcaster.publish(event);
|
|
51
52
|
};
|
|
52
53
|
socket.onerror = () => socket.close();
|
|
53
54
|
socket.onclose = () => {
|
package/browser/client.test.js
CHANGED
|
@@ -43,9 +43,33 @@ describe('PondClient', () => {
|
|
|
43
43
|
pondClient.connect();
|
|
44
44
|
const mockWebSocket = pondClient['_socket'];
|
|
45
45
|
const broadcasterSpy = jest.spyOn(pondClient['_broadcaster'], 'publish');
|
|
46
|
-
mockWebSocket.onmessage({
|
|
46
|
+
mockWebSocket.onmessage({
|
|
47
|
+
data: JSON.stringify({
|
|
48
|
+
action: pondsocket_common_1.ServerActions.SYSTEM,
|
|
49
|
+
channelName: 'exampleChannel',
|
|
50
|
+
requestId: '123',
|
|
51
|
+
payload: {},
|
|
52
|
+
event: 'exampleEvent',
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
47
55
|
expect(broadcasterSpy).toHaveBeenCalledTimes(1);
|
|
48
|
-
expect(broadcasterSpy).toHaveBeenCalledWith({
|
|
56
|
+
expect(broadcasterSpy).toHaveBeenCalledWith({
|
|
57
|
+
action: pondsocket_common_1.ServerActions.SYSTEM,
|
|
58
|
+
channelName: 'exampleChannel',
|
|
59
|
+
requestId: '123',
|
|
60
|
+
payload: {},
|
|
61
|
+
event: 'exampleEvent',
|
|
62
|
+
});
|
|
63
|
+
broadcasterSpy.mockClear();
|
|
64
|
+
expect(() => {
|
|
65
|
+
mockWebSocket.onmessage({ data: 'invalid json' });
|
|
66
|
+
}).toThrow();
|
|
67
|
+
expect(broadcasterSpy).not.toHaveBeenCalled();
|
|
68
|
+
broadcasterSpy.mockClear();
|
|
69
|
+
expect(() => {
|
|
70
|
+
mockWebSocket.onmessage({ data: JSON.stringify({}) });
|
|
71
|
+
}).toThrow();
|
|
72
|
+
expect(broadcasterSpy).not.toHaveBeenCalled();
|
|
49
73
|
});
|
|
50
74
|
test('socket should only pass to publish state when acknowledged event is received', () => {
|
|
51
75
|
pondClient.connect();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "PondSocket is a fast simple socket server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"socket",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"pipeline": "npm run test && npm run build && npm run push"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@eleven-am/pondsocket-common": "^0.0.
|
|
32
|
+
"@eleven-am/pondsocket-common": "^0.0.20",
|
|
33
33
|
"websocket": "^1.0.34"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|