Skip to content

Commit

Permalink
Fix emacs 23 compatibility, and make it an explicit goal in the README
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyatt committed Jul 28, 2012
1 parent e9b7712 commit eef37ba
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
5 changes: 4 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ to write apps that use websockets, and is not useful by itself.
An example of how to use the library is in the
[[https://github.com/ahyatt/emacs-websocket/blob/master/websocket-functional-test.el][websocket-functional-test.el]] file.

This library is compatible with emacs 23 and 24, although only emacs
24 support secure websockets.

* Version

** Version 1.0 requiements
Expand All @@ -23,7 +26,7 @@ the EIEIO branch). Please send us any feedback about the API.
Each version that is released should be checked with this checklist:

- [ ] All ert test passing
- [ ] Functional test passing
- [ ] Functional test passing on emacs 23 and 24
- [ ] websocket.el byte compiling cleanly

* Existing clients:
Expand Down
47 changes: 24 additions & 23 deletions websocket-functional-test.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;; Simple functional testing
;; Usage: emacs -batch -Q -L . -l websocket-functional-test.el

(setq debug-on-error t)
(require 'websocket)
(eval-when-compile (require 'cl))

Expand Down Expand Up @@ -61,28 +62,28 @@
;; Remove server test, with wss ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(message "Testing with wss://echo.websocket.org")
(when (featurep 'tls)
(message "Testing with wss://echo.websocket.org")
(setq wstest-ws
(websocket-open
"wss://echo.websocket.org"
:on-open (lambda (websocket)
(message "Websocket opened"))
:on-message (lambda (websocket frame)
(push (websocket-frame-payload frame) wstest-msgs)
(message "ws frame: %S" (websocket-frame-payload frame)))
:on-close (lambda (websocket)
(message "Websocket closed")
(setq wstest-closed t)))
wstest-msgs nil)
(sleep-for 0.3)
(assert (websocket-openp wstest-ws))
(assert (null wstest-msgs))
(websocket-send-text wstest-ws "Hi!")
(sleep-for 0.1)
(assert (equal (car wstest-msgs) "Hi!"))
(websocket-close wstest-ws)

(message "\nAll tests passed!\n"))

(setq wstest-ws
(websocket-open
"wss://echo.websocket.org"
:on-open (lambda (websocket)
(message "Websocket opened"))
:on-message (lambda (websocket frame)
(push (websocket-frame-payload frame) wstest-msgs)
(message "ws frame: %S" (websocket-frame-payload frame)))
:on-close (lambda (websocket)
(message "Websocket closed")
(setq wstest-closed t)))
wstest-msgs nil)

(sleep-for 0.1)
(assert (websocket-openp wstest-ws))
(assert (null wstest-msgs))
(websocket-send-text wstest-ws "Hi!")
(sleep-for 0.1)
(assert (equal (car wstest-msgs) "Hi!"))
(websocket-close wstest-ws)

(message "\nAll tests passed!\n")

24 changes: 13 additions & 11 deletions websocket.el
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,19 @@ websocket."
(coding-system-for-read 'binary)
(coding-system-for-write 'binary)
(conn (if (member (url-type url-struct) '("ws" "wss"))
(open-network-stream name (get-buffer-create buf-name)
(url-host url-struct)
(if (= 0 (url-port url-struct))
(if (equal
(url-type url-struct) "ws")
80 443)
(url-port url-struct))
:type (if (equal (url-type url-struct) "ws")
'plain
'tls)
:nowait nil)
(let* ((type (if (equal (url-type url-struct) "ws")
'plain 'tls))
(port (if (= 0 (url-port url-struct))
(if (eq type 'tls) 443 80)
(url-port url-struct)))
(host (url-host url-struct))
(buf (get-buffer-create buf-name)))
(if (featurep 'tls)
(open-network-stream name buf host port :type type :nowait nil)
(when (eq type "wss")
(error
"This version of emacs does not support tls, so cannot connect to secure websockets (wss)"))
(open-network-stream name buf host port)))
(error "Unknown protocol")))
(websocket (websocket-inner-create
:conn conn
Expand Down

0 comments on commit eef37ba

Please sign in to comment.