Created
June 5, 2013 11:31
-
-
Save b0oh/5713241 to your computer and use it in GitHub Desktop.
Simpliest Chat Ever
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -module(index). | |
| -export([main/0, title/0, body/0, event/1]). | |
| -include_lib("nitrogen_core/include/wf.hrl"). | |
| -include("records.hrl"). | |
| main() -> #template { file="./site/templates/bare.html" }. | |
| title() -> "Simple Chat". | |
| body() -> | |
| wf:comet_global(fun() -> chat_loop() end, chat_pool), | |
| [ | |
| #textbox{ id = msg, text = "Your message...", next = submit }, | |
| #button{ id = submit, text = "Submit", postback = submit }, | |
| #panel{ id = placeholder } | |
| ]. | |
| event(submit) -> | |
| ?PRINT(wf:q(msg)), | |
| wf:send_global(chat_pool, {msg, wf:q(msg)}). | |
| chat_loop() -> | |
| receive | |
| {msg, Msg} -> wf:insert_top(placeholder, [Msg, "<br>"]) | |
| end, | |
| wf:flush(), | |
| chat_loop(). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment