{"id":18448808,"url":"https://github.com/synrc/review","last_synced_at":"2025-07-04T21:40:32.503Z","repository":{"id":54300001,"uuid":"92737079","full_name":"synrc/review","owner":"synrc","description":"💧 REVIEW: MQTT Sample Application","archived":false,"fork":false,"pushed_at":"2021-11-17T14:04:51.000Z","size":327,"stargazers_count":5,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-14T04:22:46.093Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://review.n2o.dev","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/synrc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-29T12:16:49.000Z","updated_at":"2023-07-17T12:43:42.000Z","dependencies_parsed_at":"2022-08-13T11:20:48.807Z","dependency_job_id":null,"html_url":"https://github.com/synrc/review","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synrc%2Freview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synrc%2Freview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synrc%2Freview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synrc%2Freview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/synrc","download_url":"https://codeload.github.com/synrc/review/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223269519,"owners_count":17117019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T07:17:18.229Z","updated_at":"2024-11-06T07:17:18.770Z","avatar_url":"https://github.com/synrc.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"REVIEW TT: MQTT Application\n===========================\n\n[![Build Status](https://travis-ci.com/synrc/review.svg?branch=master)](https://travis-ci.com/synrc/review)\n\nTL;DR MQTT Sample IoT Application is a Nitro N2O pages that works on top\nof MQTT connection between browser and server.\n\nIntro\n-----\n\nSample application consist of two pages `login` and `index`.\nIt creates WebSocket MQTT connection to `emqttd` server which is dependency of `n2o`.\nThe permanent example is accesible at \u003ca href=\"http://review.n2o.dev/index.htm\"\u003ereview.n2o.dev/index.htm\u003c/a\u003e.\n\nIndex\n-----\n\nInit event.\n\n```\nevent(init) -\u003e\n    nitro:wire(\"nodes=\"++nitro:to_list(length(n2o:ring()))++\";\"),\n    #cx{session=Token,params=Id,node=Node} = get(context),\n    Room = n2o:session(room),\n    nitro:update(logout,\n      #button { id=logout, body=\"Logout \" ++ n2o:user(),postback=logout}),\n    nitro:update(send,\n      #button { id=send, body=\"Chat\", source=[message], postback=chat}),\n    nitro:update(heading, #h2 { id=heading, body=Room}),\n    nitro:update(upload, #upload { id=upload   }),\n    nitro:wire(\"mqtt.subscribe('room/\"++Room++\"',subscribeOptions);\"),\n    Topic = iolist_to_binary([\"events/1/\",Node,\"/index/anon/\",Id,\"/\",Token]),\n    n2o:send_reply(\u003c\u003c\u003e\u003e, 2, Topic, term_to_binary(#client{id=Room,data=list})),\n    nitro:wire(#jq{target=message,method=[focus,select]});\n```\n\nChat event.\n\n```\nevent(chat) -\u003e\n    User    = n2o:user(),\n    Message = n2o:q(message),\n    Room    = n2o:session(room),\n    #cx{session=ClientId} = get(context),\n    io:format(\"Chat pressed: ~p\\r~n\",[{Room,ClientId,Message,User}]),\n    kvs:add(#entry{id=kvs:next_id(\"entry\",1),\n                   from=n2o:user(),feed_id={room,Room},media=Message}),\n\n    nitro:insert_top(history, nitro:jse(message_view(User,Message))),\n    Actions = iolist_to_binary(n2o_nitro:render_actions(n2o:actions())),\n    M = term_to_binary({io,Actions,\u003c\u003c\u003e\u003e}),\n    n2o:send_reply(ClientId, 2, iolist_to_binary([\u003c\u003c\"room/\"\u003e\u003e,Room]), M);\n```\n\nClient event.\n\n```\nevent(#client{id=Room,data=list}) -\u003e\n    [ nitro:insert_top(history, nitro:jse(message_view(E#entry.from,E#entry.media)))\n      || E \u003c- lists:reverse(kvs:entries(kvs:get(feed,{room,Room}),entry,30)) ];\n```\n\nFTP event.\n\n```\nevent(#ftp{sid=_Sid,filename=Filename,status={event,stop}}=Data) -\u003e\n    io:format(\"FTP Delivered ~p~n\",[Data]),\n    Name = hd(lists:reverse(string:tokens(nitro:to_list(Filename),\"/\"))),\n    IP = application:get_env(review,host,\"127.0.0.1\"),\n    erlang:put(message,\n    nitro:render(#link{href=iolist_to_binary([\"http://\",IP,\":8000/ftp/\",\n                       nitro_conv:url_encode(Name)]),body=Name})),\n    event(chat);\n```\n\nLogin\n-----\n\nChannel init.\n\n```\nevent(init) -\u003e\n    nitro:wire(\"nodes=\"++nitro:to_list(length(n2o:ring()))++\";\"),\n    nitro:update(loginButton,\n          #button { id=loginButton, body=\"login\",\n                    postback=login,source=[user,pass]});\n```\n\nLogin event.\n\n```\nevent(login) -\u003e\n    User = nitro:to_list(n2o:q(user)),\n    Room = nitro:to_list(n2o:q(pass)),\n    n2o:user(User),\n    n2o:session(room,Room),\n    nitro:redirect(\"/index.htm\");\n```\n\nSetup\n-----\n\nTo run review application just clone, build and run:\n\n```\n$ git clone git://github.com/synrc/review\n$ cd review\n$ mad dep com pla rep\n```\n\nThen open it in browser:\n\n```\n$ open http://127.0.0.1:8000\n```\n\nCredits\n-------\n* Brought with ❤ by N2O community\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynrc%2Freview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsynrc%2Freview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynrc%2Freview/lists"}