Browse Source

Replace websocket.el with wsc

* indium-v8.el: Replace websocket with wsc
* indium.el:
* Makefile: Remove dependency to websocket.el
wsc
Nicolas Petton 4 years ago
parent
commit
f6b1bd8311
No known key found for this signature in database GPG Key ID: E8BCD7866AFCF978
4 changed files with 27 additions and 36 deletions
  1. +0
    -1
      Makefile
  2. +17
    -26
      indium-v8.el
  3. +1
    -1
      indium.el
  4. +9
    -8
      test/unit/indium-v8-test.el

+ 0
- 1
Makefile View File

@ -24,7 +24,6 @@ ci-dependencies:
# Install dependencies in ~/.emacs.d/elpa
$(BATCH) \
--funcall package-refresh-contents \
--eval "(package-install 'websocket)" \
--eval "(package-install 'company)" \
--eval "(package-install 'undercover)" \
--eval "(package-install 'buttercup)" \


+ 17
- 26
indium-v8.el View File

@ -36,11 +36,11 @@
;;; Code:
(require 'websocket)
(require 'json)
(require 'map)
(require 'seq)
(require 'wsc)
(require 'indium-backend)
(require 'indium-structs)
(require 'indium-repl)
@ -71,16 +71,17 @@
(cl-defmethod indium-backend-active-connection-p ((_backend (eql v8)))
"Return non-nil if the current connection is active."
(when-indium-connected
(websocket-openp (indium-connection-ws indium-current-connection))))
(when-let ((wsc-connection (indium-connection-ws indium-current-connection)))
(wsc-connection-open-p wsc-connection))))
(cl-defmethod indium-backend-close-connection ((_backend (eql v8)))
"Close the websocket associated with the current connection."
(websocket-close (indium-connection-ws indium-current-connection))
(wsc-close (indium-connection-ws indium-current-connection))
(run-hooks 'indium-connection-closed-hook))
(cl-defmethod indium-backend-reconnect ((_backend (eql v8)))
(let ((url (indium-current-connection-url))
(ws-url (websocket-url (indium-connection-ws indium-current-connection))))
(ws-url (wsc-connection-url (indium-connection-ws indium-current-connection))))
;; close all buffers related to the closed
;; connection the first
(indium-quit)
@ -301,14 +302,13 @@ If NODEJS is non-nil, add a `nodejs' flag to the
`indium-current-connection' to handle special cases."
(unless websocket-url
(user-error "Cannot open connection, another devtools instance might be open"))
(websocket-open websocket-url
:on-open (lambda (ws)
(indium-v8--handle-ws-open ws url nodejs)
(when on-open
(funcall on-open)))
:on-message #'indium-v8--handle-ws-message
:on-close #'indium-v8--handle-ws-closed
:on-error #'indium-v8--handle-ws-error))
(wsc-open websocket-url
(lambda (ws)
(indium-v8--handle-ws-open ws url nodejs)
(when on-open
(funcall on-open)))
#'indium-v8--handle-ws-message
#'indium-v8--handle-ws-closed))
(defun indium-v8--make-connection (ws url &optional nodejs)
"Return a new connection for WS and URL.
@ -333,9 +333,9 @@ If NODEJS is non-nil, set an extra property in the connection."
(switch-to-buffer (indium-repl-get-buffer-create))
(run-hooks 'indium-connection-open-hook))
(defun indium-v8--handle-ws-message (_ws frame)
"Handle a websocket message FRAME."
(let* ((message (indium-v8--read-ws-message frame))
(defun indium-v8--handle-ws-message (message)
"Handle a websocket MESSAGE."
(let* ((message (json-read-from-string message))
(error (map-elt message 'error))
(method (map-elt message 'method))
(request-id (map-elt message 'id))
@ -419,11 +419,6 @@ MESSAGE explains why the connection has been closed."
"Cleanup function called when the connection socket is closed."
(run-hooks 'indium-connection-closed-hook))
(defun indium-v8--handle-ws-error (_ws _action error)
"Display an error message for an exception in a websocket callback handling.
ERROR should be a description of the exception."
(message "Exception in websocket callback! %s" error))
(defun indium-v8--send-request (request &optional callback)
"Send REQUEST to the current connection.
Evaluate CALLBACK with the response.
@ -435,14 +430,10 @@ If the current connection is closed, display a message."
(map-put (indium-current-connection-callbacks)
id
callback))
(websocket-send-text (indium-connection-ws indium-current-connection)
(json-encode (cons `(id . ,id) request))))
(wsc-send (indium-connection-ws indium-current-connection)
(json-encode (cons `(id . ,id) request))))
(message "Socket connection closed")))
(defun indium-v8--read-ws-message (frame)
"Parse the payload from the websocket FRAME."
(json-read-from-string (websocket-frame-payload frame)))
(defun indium-v8--enable-tools ()
"Enable developer tools for the current tab.


+ 1
- 1
indium.el View File

@ -6,7 +6,7 @@
;; URL: https://github.com/NicolasPetton/indium
;; Keywords: tools, javascript
;; Version: 1.2.0
;; Package-Requires: ((emacs "25") (seq "2.16") (js2-mode "20140114") (company "0.9.0") (websocket "1.6"))
;; Package-Requires: ((emacs "25") (seq "2.16") (js2-mode "20140114") (company "0.9.0"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by


+ 9
- 8
test/unit/indium-v8-test.el View File

@ -44,7 +44,8 @@
(describe "V8 connection handling"
(it "should be active if the websocket is open"
(spy-on 'websocket-openp :and-return-value t)
(spy-on 'wsc-connection-open-p :and-return-value t)
(spy-on 'indium-connection-ws :and-return-value 'ws)
(with-fake-indium-connection
(expect (indium-backend-active-connection-p 'v8) :to-be-truthy)))
@ -53,19 +54,19 @@
(expect (indium-backend-active-connection-p 'v8) :to-be nil)))
(it "should close the socket when closing the connection"
(spy-on 'websocket-close)
(spy-on 'wsc-close)
(with-indium-connection (indium-connection-create :backend 'v8)
(map-put (indium-current-connection-props) 'ws 'ws)
(indium-backend-close-connection 'v8)
(expect #'websocket-close :to-have-been-called-with 'ws))))
(expect #'wsc-close :to-have-been-called-with 'ws))))
(describe "Sending requests"
(it "should not send requests if the connection is closed"
(spy-on 'websocket-send-test)
(spy-on 'wsc-send)
(spy-on 'message)
(with-fake-indium-connection
(indium-v8--send-request 'foo)
(expect #'websocket-send-test :not :to-have-been-called)))
(expect #'wsc-send :not :to-have-been-called)))
(it "should display a warning message if the connection is closed"
(spy-on 'message)
@ -74,17 +75,17 @@
(expect #'message :to-have-been-called-with "Socket connection closed")))
(it "should send requests if the connection is active"
(spy-on 'websocket-send-text)
(spy-on 'wsc-send)
(spy-on 'indium-backend-active-connection-p :and-return-value t)
(spy-on 'indium-v8--next-request-id :and-return-value 'id)
(with-indium-connection (indium-connection-create :backend 'v8)
(map-put (indium-current-connection-props) 'ws 'ws)
(indium-v8--send-request '((message . "message")))
(expect #'websocket-send-text :to-have-been-called-with
(expect #'wsc-send :to-have-been-called-with
'ws (json-encode '((id . id) (message . "message"))))))
(it "should register callbacks when sending requests"
(spy-on 'websocket-send-text)
(spy-on 'wsc-send)
(spy-on 'indium-backend-active-connection-p :and-return-value t)
(spy-on 'indium-v8--next-request-id :and-return-value 'id)
(with-indium-connection (indium-connection-create :backend 'v8)


Loading…
Cancel
Save