aboutsummaryrefslogtreecommitdiff
path: root/lib/client/sharder/shard.ml
diff options
context:
space:
mode:
authorMishio595 <[email protected]>2018-11-04 20:20:27 -0700
committerMishio595 <[email protected]>2018-11-04 20:20:27 -0700
commit450f62a3d695a58bc66f13f77cba0f267c71dba6 (patch)
treefa7d03d987ccaa0d130f79df152ad0c8b2104de9 /lib/client/sharder/shard.ml
parentidek (diff)
downloaddisml-450f62a3d695a58bc66f13f77cba0f267c71dba6.tar.xz
disml-450f62a3d695a58bc66f13f77cba0f267c71dba6.zip
Major changes and refactoring
Diffstat (limited to 'lib/client/sharder/shard.ml')
-rw-r--r--lib/client/sharder/shard.ml81
1 files changed, 0 insertions, 81 deletions
diff --git a/lib/client/sharder/shard.ml b/lib/client/sharder/shard.ml
deleted file mode 100644
index 7be4aad..0000000
--- a/lib/client/sharder/shard.ml
+++ /dev/null
@@ -1,81 +0,0 @@
-open Lwt.Infix
-open Websocket
-
-type t = {
- send: (Frame.t -> unit Lwt.t);
- id: int;
- total_shards: int;
- hb_interval: int;
- session_id: string;
- seq: int;
- token: string;
-}
-
-let init ?(hb_interval=42500) ?(session_id="") ?(seq=0) ~send ~id ~total_shards ~token () =
- { send; id; total_shards; hb_interval; session_id; seq; token; }
-
-let push_frame shard frame =
- shard.send frame
-
-let process_frame shard frame =
- let json = frame |> Yojson.Basic.from_string in
- match json with
- | `Assoc [("s", `Int _s); ("d", _d); ("t", `String _t); ("op", `Int op);] -> begin
- match op |> Opcode.from_int with
- | DISPATCH -> () (* dispatch t d Need to write the dispatcher and other ops *)
- | HEARTBEAT -> ()
- | IDENTIFY -> ()
- | STATUS_UPDATE -> ()
- | VOICE_STATE_UPDATE -> ()
- | RESUME -> ()
- | RECONNECT -> ()
- | REQUEST_GUILD_MEMBERS -> ()
- | INVALID_SESSION -> ()
- | HELLO -> ()
- | HEARTBEAT_ACK -> ()
- |> ignore;
- (* { shard with seq = s; } *)
- end
- | _ -> shard
-
-let wrap_payload d op =
- `Assoc [
- ("op", `Int op);
- ("d", d)
- ]
-
-let create_frame content =
- Frame.create ~content ()
-
-let identify ?(threshold=250) shard=
- let p = wrap_payload (`Assoc [
- ("token", `String shard.token);
- ("properties", `Assoc [
- ("$os", `String Sys.os_type);
- ("$browser", `String "animus");
- ("$device", `String "animus");
- ]);
- ("large_threshold", `Int threshold);
- ("shard", `List [`Int shard.id; `Int shard.total_shards]);
- ]) (Opcode.to_int IDENTIFY) in
- push_frame shard (Yojson.Basic.to_string p |> create_frame)
-
-let resume shard =
- let p = wrap_payload (`Assoc [
- ("token", `String shard.token);
- ("session_id", `String shard.session_id);
- ("seq", `Int shard.seq);
- ]) (Opcode.to_int RESUME) in
- push_frame shard (Yojson.Basic.to_string p |> create_frame)
-
-let heartbeat shard =
- let p = wrap_payload (`Int shard.seq) (Opcode.to_int HEARTBEAT) in
- push_frame shard (Yojson.Basic.to_string p |> create_frame)
-
-let connect ~_options ~uri ~id ~total ~token () =
- let url = uri |> Uri.to_string in
- let ip = Ipaddr.V4 Ipaddr.V4.any in
- let client = Websocket.Connected_Client.create
- Websocket_lwt.with_connection (`TLS (`Hostname url, `IP ip, `Port 443)) uri (* Maybe use upgrade_connection? *)
- >|= fun (recv, send) ->
- init ~send ~id ~token ~total_shards:total () \ No newline at end of file