Skip to content

Commit acce97a

Browse files
committed
PR review changes
1 parent e7ceb83 commit acce97a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

source/simple_socketio.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,17 @@ export default class SimpleSocketIOClient {
201201
}
202202
/**
203203
* Handles WebSocket messages
204+
* The messages are a version of the socket.io message protocol
205+
* from before v1. The messages are formatted with the first character
206+
* being an number, the packet type (see PACKET_TYPES const for available types).
207+
* It is followed by two or three colons depending on if the packet type has data
208+
* or not. For example heartbeat, "2::", does not contain data, while message, "3:::Hello", does.
209+
*
204210
* @private
205211
*/
206212
private handleMessage(event: MessageEvent): void {
207213
const packetType = event.data[0]; // Get the first character of the message, the packet type
208-
const data = event.data.replace(/^\d+:::?/, ""); // Remove the packet type and the : that split message parts.
214+
const data = event.data.replace(/^\d:::?/, ""); // Remove the packet type and the : that split message parts.
209215
if (packetType === PACKET_TYPES.event) {
210216
const parsedData = JSON.parse(data) as Payload;
211217
const { name, args } = parsedData;

test/simple_socketio.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ describe("Tests using SimpleSocketIOClient", () => {
227227

228228
test("handleMessage correctly handles data with '::' in it", () => {
229229
const eventName = "testEvent";
230-
const eventData = { foo: ":::bar" };
230+
const eventData = { foo: "::bar" };
231231
const packetData = JSON.stringify({ name: eventName, args: [eventData] });
232232

233233
vi.spyOn(client, "handleEvent");

0 commit comments

Comments
 (0)