private onMessageParsed()

in src/panelSocket.ts [39:68]


    private onMessageParsed(eventName: WebviewEvent, args: string): boolean {
        if (eventName === 'ready') {
            this.dispose();

            // First message, so connect a real websocket to the target
            this.connectToTarget();
        }

        if (eventName === 'websocket') {
            if (!this.socket) {
                // Reconnect if we no longer have a websocket
                this.connectToTarget();
            }

            const { message } = JSON.parse(args) as {message: string};
            if (message && message[0] === '{') {
                if (!this.isConnected) {
                    // DevTools are sending a message before the real websocket has finished opening so cache it
                    this.messages.push(message);
                } else {
                    // Websocket ready so send the message directly
                    if (this.socket) {
                        this.socket.send(message);
                    }
                }
            }
        }

        return this.emit(eventName, args);
    }