drop closed remote client

This commit is contained in:
Igor Shymko 2014-09-14 16:15:48 +03:00
parent cf66b5a48d
commit 8dabbf2d62
1 changed files with 9 additions and 8 deletions

View File

@ -49,6 +49,10 @@
(setq mdpm:websocket-server nil
mdpm:remote-clients nil)))
(defun mdpm:drop-closed-clients ()
(setq mdpm:remote-clients
(remove-if-not #'websocket-openp mdpm:remote-clients)))
(defun mdpm:start-websocket-server ()
(when (not mdpm:websocket-server)
(setq mdpm:websocket-server
@ -57,14 +61,11 @@
:on-message (lambda (websocket frame)
(mapc (lambda (ws)
(websocket-send-text ws
(websocket-frame-payload frame)))
(websocket-frame-payload frame)))
:on-open (lambda (websocket)
(push websocket mdpm:remote-clients)
:on-close (lambda (websocket)
(delete websocket mdpm:remote-clients)
:on-open (lambda (websocket) (push websocket mdpm:remote-clients))
:on-error (lambda (websocket type err) (message err))
:on-close (lambda (websocket) (mdpm:drop-closed-clients))
(add-hook 'kill-emacs-hook 'mdpm:stop-websocket-server)
@ -91,7 +92,7 @@
(add-hook 'after-save-hook 'mdpm:send-preview nil t))
(defun mdpm:stop ()
(remove-hook 'after-save-hook 'mdpm:send-preview))
(remove-hook 'after-save-hook 'mdpm:send-preview t))
(defun markdown-preview-open-browser ()