Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit of opa pubnub client side client

  • Loading branch information...
commit 56c5f34dd77e19d4c23d9b3855bd580aefd9f0de 0 parents
Tristan Sloughter tsloughter authored
17 Makefile
@@ -0,0 +1,17 @@
+NAME = pubnub_test.exe
+
+SRC = pubnub.opp src/examples/pubnub_test.opa
+
+all : pubnub opa
+
+pubnub:
+ opa-plugin-builder src/plugin/pubnub.js -o pubnub
+
+opa:
+ opa $(SRC) -o $(NAME)
+ @echo "run: ./pubnub_test.exe"
+
+clean:
+ rm -rf pubnub_test.exe
+ rm -rf _build _tracks
+ rm -rf pubnub.opp
1  README
@@ -0,0 +1 @@
+## ADD TO ##
44 src/examples/pubnub_test.opa
@@ -0,0 +1,44 @@
+pubnub_publish = %%pubnub.publish%%
+pubnub_subscribe = %%pubnub.subscribe%%
+pubnub_history = %%pubnub.history%%
+
+@client publish_client = pubnub_publish
+@client subscribe_client = pubnub_subscribe
+@client history_client = pubnub_history
+
+action() =
+ history_client("chat", 10, (x -> Dom.transform([ #box <- x])))
+
+/* s = Dom.get_value(#input)
+ username : RPC.Json.json = {String = "tristan"}
+ message : RPC.Json.json = {String = s}
+ record_json : RPC.Json.json = {Record = [("username", username), ("message", message)]}
+ publish(record_json)
+*/
+
+publish(j : RPC.Json.json) =
+ publish_client("chat", Json.to_string(j))
+
+button(id, message) =
+ <a id={id:string}
+ class="button"
+ ref="#"
+ onclick={_ -> action() }>{message:string}
+ </a>
+
+add(x) =
+ match Json.deserialize(x) with
+ | {some={Record = [("username", username), ("message", message)]}} -> Dom.transform([ #box <- Json.to_string(message) ])
+ | {some=_} -> Dom.transform([ #box <- "fail" ])
+ | {none} -> Dom.transform([ #box <- "none" ])
+
+page() =
+ <>
+ <div id=pubnub pub-key=demo sub-key=demo onready={_ -> subscribe_client("chat", (x -> add(x))) }></div>
+ <div><input id=input placeholder=you-chat-here /></div>
+ <div id=box></div>
+ {button("publish_client", "Send Message")}
+ </>
+
+do Resource.register_external_js("http://cdn.pubnub.com/pubnub-3.1.min.js")
+server = one_page_server("Hello Bindings", page)
57 src/plugin/pubnub.js
@@ -0,0 +1,57 @@
+// This is an Javascript file, containing opa preprocessing directives
+
+##register publish : string, string -> void
+##args(c, m)
+{
+ PUBNUB.publish({
+ channel : c, message : m
+ });
+
+ return js_void;
+}
+
+##register subscribe : string, (string -> void) -> void
+##args(c, callback)
+{
+ PUBNUB.subscribe({
+ channel : c,
+ callback : callback
+ });
+
+ return js_void;
+}
+
+##register unsubscribe : string -> void
+##args(channel)
+{
+ PUBNUB.unsubscribe({ channel : channel });
+
+ return js_void;
+}
+
+##register history : string, int, (string -> void) -> void
+##args(channel, limit, callback)
+{
+ PUBNUB.history({
+ channel : channel,
+ limit : limit
+ }, callback);
+
+ return js_void;
+}
+
+##register uuid : (string -> void) -> void
+##args(callback)
+{
+ PUBNUB.uuid(callback);
+
+ return js_void;
+}
+
+##register time : (int -> void) -> void
+##args(callback)
+{
+ PUBNUB.time(callback);
+
+ return js_void;
+}
4 src/plugin/pubnub.ml
@@ -0,0 +1,4 @@
+(* This is an Ocaml file, containing opa preprocessing directives *)
+
+##register stammer : string -> string
+let stammer s = "server is stammering: " ^ s ^ s ^ s
Please sign in to comment.
Something went wrong with that request. Please try again.