Skip to content

Instantly share code, notes, and snippets.

@b0oh
Created June 5, 2013 11:31
Show Gist options
  • Select an option

  • Save b0oh/5713241 to your computer and use it in GitHub Desktop.

Select an option

Save b0oh/5713241 to your computer and use it in GitHub Desktop.
Simpliest Chat Ever
-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