n2o v4.4 fork https://github.com/synrc/n2o/commits/refs/tags/4.4
![]() |
1 year ago | |
---|---|---|
ebin | 3 years ago | |
include | 3 years ago | |
priv | 3 years ago | |
src | 3 years ago | |
test | 3 years ago | |
.gitignore | 3 years ago | |
CHANGELOG.md | 1 year ago | |
LICENSE | 3 years ago | |
PEOPLE_4.4.md | 3 years ago | |
README.md | 3 years ago | |
rebar.config | 3 years ago |
do not forget
sudo apt-get install esl-erlang
# or install erlang with kerl
sudo apt-get install git
sudo apt-get install gcc
sudo apt-get install make
sudo apt-get install build-essential
sudo apt-get install inotify-tools
You can use any message formmatter at the bottom of N2O protocol. IO messages supported by the N2O protocol are as follows:
1. BERT : {io,"console.log('hello')",1}
2. WAMP : [io,"console.log('hello')",1]
3. JSON : {name:io,eval:"console.log('hello')",data:1}
4. TEXT : IO console.log('hello') 1\n
5. XML : <io><eval>console.log('hello')</eval><data>1</data></io>
Besides, you can even switch a channel termination formatter on the fly within one WebSocket session.
-module(index).
-compile([export_all, nowarn_export_all]).
-include_lib("nitro/include/nitro.hrl").
-include_lib("n4u/include/n4u.hrl").
peer() -> io_lib:format("~p",[wf:peer(?REQ)]).
message() -> wf:js_escape(wf:html_encode(wf:q(message))).
main() -> #dtl{file="index",app=n4u_sample,bindings=[{body,body()}]}.
body() ->
{Pid,_} = wf:async(fun(X) -> chat_loop(X) end),
[ #panel{id=history}, #textbox{id=message},
#button{id=send,body="Chat",postback={chat,Pid},source=[message]} ].
event(init) -> wf:reg(room);
event({chat,Pid}) -> Pid ! {peer(), message()};
event(Event) -> skip.
chat_loop({Peer, Message} ) ->
wf:insert_bottom(history,#panel{body=[Peer,": ",Message,#br{}]}),
wf:flush(room) end.
OM A HUM