diff --git a/README.md b/README.md index d2661842..29f609fc 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,8 @@ Also create file `index.html` near `main.go` with content: const input = document.getElementById("input"); input.addEventListener('keyup', function(e) { - if (e.keyCode === 13) { + if (e.key === "ENTER") { + e.preventDefault(); sub.publish(this.value); input.value = ''; } @@ -228,9 +229,12 @@ go run main.go Open several browser tabs with http://localhost:8000 and see chat in action. -While this example is only the top of an iceberg, it should give you a good insight on library API. Check out [examples](https://github.com/centrifugal/centrifuge/tree/master/_examples) folder for more. +While this example is only the top of an iceberg, it should give you a good insight on library API. Check out [examples](https://github.com/centrifugal/centrifuge/tree/master/_examples) folder for more. We recommend to start looking from [chat_json](https://github.com/centrifugal/centrifuge/tree/master/_examples/chat_json) example, which extends the basics shown here and demonstrates more possibilities of Centrifuge protocol: -Keep in mind that Centrifuge library is not a framework to build chat applications. It's a **general purpose real-time transport** for your messages with some helpful primitives. You can build many kinds of real-time apps on top of this library including chats but depending on application you may need to write business logic yourself. +[![Chat example](https://raw.githubusercontent.com/centrifugal/centrifuge/master/_examples/chat_json/demo.gif "Chat Demo")](https://github.com/centrifugal/centrifuge/tree/master/_examples/chat_json) + +> [!IMPORTANT] +> Keep in mind that Centrifuge library is not a framework to build chat applications. It's a **general purpose real-time transport** for your messages with some helpful primitives. You can build many kinds of real-time apps on top of this library including chats but depending on application you may need to write business logic yourself. ### Tips and tricks diff --git a/_examples/chat_json/demo.gif b/_examples/chat_json/demo.gif new file mode 100644 index 00000000..cd52c722 Binary files /dev/null and b/_examples/chat_json/demo.gif differ diff --git a/_examples/chat_json/index.html b/_examples/chat_json/index.html index bfd701d9..76b7bfb4 100644 --- a/_examples/chat_json/index.html +++ b/_examples/chat_json/index.html @@ -3,12 +3,150 @@ - -
- - -
- +
+
+
+ + +
+
diff --git a/_examples/chat_json/readme.md b/_examples/chat_json/readme.md index f3469ccd..2e4748aa 100644 --- a/_examples/chat_json/readme.md +++ b/_examples/chat_json/readme.md @@ -1,6 +1,6 @@ Example demonstrates a simple chat with JSON protocol. -Client uses Websocket by default, but you can simply uncomment one line in `index.html` to use SockJS instead. +Client uses Websocket to connect to Centrifuge server, and we demonstrate many possibilities of Centrifuge protocol here. To start example run the following command from example directory: @@ -8,4 +8,6 @@ To start example run the following command from example directory: go run main.go ``` -Then go to http://localhost:8000 to see it in action. +Then go to http://localhost:8000 to see it in action. Open several browser tabs and publish messages. + +[![Chat example](https://raw.githubusercontent.com/centrifugal/centrifuge/master/_examples/chat_json/demo.gif "Chat Demo")](https://github.com/centrifugal/centrifuge/tree/master/_examples/chat_json)