Skip to content

Commit

Permalink
fixes and example
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtori committed Oct 24, 2020
1 parent 33d609e commit 109f10c
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
_build/
*.install
*.merlin
test
*.merlin
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1 - 2020-07-31

First release

## 0.2 - 2020-10-24

- more exhaustive binding
- update to ezjs_min.0.2
4 changes: 3 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
(depends
(ocaml (>= 4.05))
(dune (>= 2.0))
ezjs_min))
(ezjs_min (>= 0.2))
bigstring
(base64 (>= 3.2))))
13 changes: 13 additions & 0 deletions example/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(executable
(name index_example)
(modules index_example)
(preprocess (pps js_of_ocaml-ppx))
(libraries ezjs_push)
(modes js))

(executable
(name sw_example)
(modules sw_example)
(preprocess (pps js_of_ocaml-ppx))
(libraries ezjs_push)
(modes js))
9 changes: 9 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<title>Test Push Notification</title>
<link rel="manifest" href="/manifest.json"/>
<script src="index_example.bc.js"></script>
</head>
<body>
</body>
</html>
8 changes: 8 additions & 0 deletions example/index_example.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
open Ezjs_min
open Ezjs_push

let () =
request_permission @@ fun permission ->
js_log permission;
registration "/sw_example.bc.js" @@ fun reg ->
update_worker reg
4 changes: 4 additions & 0 deletions example/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Test Push Notifications",
"gcm_sender_id": "..."
}
19 changes: 19 additions & 0 deletions example/sw_example.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
open Ezjs_min
open Ezjs_push

let () =
onactivate (fun _ev ->
log_str "service worker activation";
let options = {
so_user_visible_only = Some true;
so_application_server_key = Some "BMDc6lvxIgN4aluWtZSZokp5GcJedJwgHUzRUVqFlTHzJl26o4eZTdokJ7svKn7MyaugUXeOc00F7cPh_922-Os"
} in
subscription ~options self##.registration (fun subscr ->
js_log subscr;
js_log @@ subscr##toJSON);
);
onpush (fun e ->
log_str "received a push message";
let data = Opt.case e##.data (fun () -> "no payload") (fun d -> to_string d##text) in
let options = {empty_notif with no_body = Some data} in
show_notification ~options self##.registration "test")
4 changes: 3 additions & 1 deletion ezjs_push.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ bug-reports: "https://github.com/ocamlpro/ezjs_push/issues"
depends: [
"ocaml" {>= "4.05"}
"dune" {>= "2.0"}
"ezjs_min"
"ezjs_min" {>= "0.2"}
"bigstring"
"base64" {>= "3.2"}
]
build: [
["dune" "subst"] {pinned}
Expand Down
3 changes: 2 additions & 1 deletion src/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(library
(public_name ezjs_push)
(preprocess (pps js_of_ocaml-ppx))
(libraries ezjs_min bigstring base64))
(libraries ezjs_min bigstring base64)
(modes byte))
11 changes: 5 additions & 6 deletions src/ezjs_push.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
open Ezjs_min.Js
open Ezjs_min.Promise
module Typed_array = Js_of_ocaml.Typed_array
open Ezjs_min
open Promise

class type extendableEvent = object
inherit Dom_html.event
Expand Down Expand Up @@ -78,7 +77,7 @@ class type pushSubscription = object
method endpoint : js_string t readonly_prop
method exiprationTime : number t opt readonly_prop
method options : subscription_options t readonly_prop
method getKey : Typed_array.arrayBuffer t meth
method getKey : js_string t -> Typed_array.arrayBuffer t meth
method toJSON : json t meth
method unsubscribe : bool t promise t meth
end
Expand Down Expand Up @@ -317,8 +316,8 @@ let get_subscription ?(none=fun () -> log_str "No subscription") reg f =
let push_manager = push_manager reg in
jthen push_manager##getSubscription (fun subs -> Opt.case subs none f)

let subscription ?(verbose=false) ?options reg f =
get_subscription ~none:(fun () -> subscribe ?options reg f) reg f
let subscription ?verbose ?options reg f =
get_subscription ~none:(fun () -> subscribe ?verbose ?options reg f) reg f

let make_notification_action {na_action; na_title; na_icon} : notification_action t =
object%js
Expand Down

0 comments on commit 109f10c

Please sign in to comment.