add websocket example

This commit is contained in:
zedhugh committed 2023-11-22 01:30:51 +08:00
1 parent bb37fefaa2
commit 75a6ab7ffa
3 files changed
+85

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
;; -*- coding: utf-8; lexical-binding: t; -*-
(require 'websocket)
(setq-local websocket-eldoc-callback nil)
(defun test-websocket-eldoc (callback)
(setq websocket-eldoc-callback
(if (compiled-function-p callback) callback nil)))
(set (make-local-variable 'eldoc-documentation-strategy)
'eldoc-documentation-compose-eagerly)
(run-with-timer 1 nil
(lambda ()
(funcall websocket-eldoc-callback "hel")))
(test-websocket-eldoc "hel")
(make-local-variable 'eldoc-documentation-functions)
(add-to-list 'eldoc-documentation-functions #'test-websocket-eldoc)
(setq ws-server (websocket-server
4000
:host 'local
:on-message (lambda (ws frame)
(when (and (boundp 'websocket-eldoc-callback) (compiled-function-p websocket-eldoc-callback))
(websocket-send-text ws (format "eldoc showed: %s" (websocket-frame-text frame)))
(funcall websocket-eldoc-callback (websocket-frame-text frame))))))
(funcall (symbol-value (obarray-get obarray "websocket-eldoc-callback")) "hello")
(symbol-value 'websocket-eldoc-callback)
(websocket-server-close ws-server)
(funcall websocket-eldoc-callback "hello")