aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndrajith K L2023-11-06 06:12:28 +0530
committerIndrajith K L2023-11-06 06:12:28 +0530
commitbf91c7ef4f374a78bff46a42a85c0426b0abf7d0 (patch)
treea38e002b64c3dd5fb6f9dca7791eba4f99a68760
downloadwialt_listener-master.tar.gz
wialt_listener-master.tar.bz2
wialt_listener-master.zip
Initial CommitHEADmaster
* Listener Implementation - In-Progress * Initial API Endpoints and Websocket implementation * API End Points Implemented -> /music_changed, /state_change * Websocket End Points implemented -> /i_am_listening_to * Socket Implementation - In-Progress
-rw-r--r--.editorconfig9
-rw-r--r--.gitignore5
-rw-r--r--LICENSE21
-rw-r--r--README.md16
-rw-r--r--shard.lock18
-rw-r--r--shard.yml17
-rw-r--r--spec/spec_helper.cr2
-rw-r--r--spec/wialt_listener_spec.cr9
-rw-r--r--src/wialt_listener.cr52
9 files changed, 149 insertions, 0 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..163eb75
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,9 @@
+root = true
+
+[*.cr]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 2
+trim_trailing_whitespace = true
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0bb75ea
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+/docs/
+/lib/
+/bin/
+/.shards/
+*.dwarf
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6f1ec5f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 Indrajith K L <indrajith@indrajith.dev>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..abeadbc
--- /dev/null
+++ b/README.md
@@ -0,0 +1,16 @@
+# [W]hat [I] [A]m [L]istening [T]o Listener
+
+A Web Server written in Crystal Lang which is part of WIALT Project. This server is a broker server which act as a bridge between Local MPC Music Player and indrajith.dev website. Whose main purpose is to display music title I'am listening to.
+
+## Installation
+
+* Install Crystal
+* `shards install`
+
+## Usage
+
+* `crystal run src/wialt_listener.cr`
+
+## Contributors
+
+- [Indrajith K L](https://github.com/cooljith91112) - creator and maintainer
diff --git a/shard.lock b/shard.lock
new file mode 100644
index 0000000..82d8d02
--- /dev/null
+++ b/shard.lock
@@ -0,0 +1,18 @@
+version: 2.0
+shards:
+ backtracer:
+ git: https://github.com/sija/backtracer.cr.git
+ version: 1.2.2
+
+ exception_page:
+ git: https://github.com/crystal-loot/exception_page.git
+ version: 0.3.1
+
+ kemal:
+ git: https://github.com/kemalcr/kemal.git
+ version: 1.4.0
+
+ radix:
+ git: https://github.com/luislavena/radix.git
+ version: 0.4.1
+
diff --git a/shard.yml b/shard.yml
new file mode 100644
index 0000000..5100ca1
--- /dev/null
+++ b/shard.yml
@@ -0,0 +1,17 @@
+name: wialt_listener
+version: 0.1.0
+
+authors:
+ - Indrajith K L <indrajith@indrajith.dev>
+
+dependencies:
+ kemal:
+ github: kemalcr/kemal
+
+targets:
+ wialt_listener:
+ main: src/wialt_listener.cr
+
+crystal: '>= 1.10.1'
+
+license: MIT
diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr
new file mode 100644
index 0000000..cb31982
--- /dev/null
+++ b/spec/spec_helper.cr
@@ -0,0 +1,2 @@
+require "spec"
+require "../src/wialt_listener"
diff --git a/spec/wialt_listener_spec.cr b/spec/wialt_listener_spec.cr
new file mode 100644
index 0000000..bf9fa0c
--- /dev/null
+++ b/spec/wialt_listener_spec.cr
@@ -0,0 +1,9 @@
+require "./spec_helper"
+
+describe WialtListener do
+ # TODO: Write tests
+
+ it "works" do
+ false.should eq(true)
+ end
+end
diff --git a/src/wialt_listener.cr b/src/wialt_listener.cr
new file mode 100644
index 0000000..7c4d01e
--- /dev/null
+++ b/src/wialt_listener.cr
@@ -0,0 +1,52 @@
+# TODO: Write documentation for `WialtListener`
+require "kemal"
+
+class MusicChange
+ include JSON::Serializable
+
+ property title : String
+end
+
+
+module WialtListener
+ VERSION = "0.1.0"
+ sockets = [] of HTTP::WebSocket
+
+ static_headers do |response|
+ response.headers.add("Access-Control-Allow-Origin", "")
+ end
+
+ post "/music_changed" do |env|
+ response = MusicChange.from_json env.request.body.not_nil!
+ puts "#{response.title}"
+ send_message_to_clients(sockets, response.title)
+ {status: "OK"}
+ end
+
+ post "/state_change" do |env|
+ puts "#{env.request.body}"
+ {status: "OK"}
+ end
+
+ ws "/i_am_listening_to" do |socket|
+ sockets.push socket
+
+ socket.on_message do |message|
+ send_message_to_clients(sockets, message)
+ end
+
+ socket.on_close do |_|
+ sockets.delete(socket)
+ puts "Closing Socket: #{socket}"
+ end
+
+ end
+
+ def self.send_message_to_clients(sockets, title)
+ sockets.each do |a_socket|
+ a_socket.send title
+ end
+ end
+
+ Kemal.run
+end