aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/assets/js/chat.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/assets/js/chat.js')
-rw-r--r--resources/assets/js/chat.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/resources/assets/js/chat.js b/resources/assets/js/chat.js
new file mode 100644
index 0000000..5f634d2
--- /dev/null
+++ b/resources/assets/js/chat.js
@@ -0,0 +1,26 @@
+var socket = io('http://127.0.0.1:8890', {
+ transports: ['websocket']
+});
+socket.on('message', function (data) {
+ data = JSON.parse(data);
+ $("#messages").append("<p>" + data.user + " : " + data.message + "</p>");
+});
+
+$('input.send').click(function (e) {
+ e.preventDefault();
+ sendMessage();
+});
+
+function sendMessage() {
+ var message = $('input.message').val();
+ $.ajax({
+ type: "POST",
+ url: "sendMessage",
+ data: {
+ "_token": $('meta[name="csrf-token"]').attr('content'),
+ "message": message
+ },
+ cache: false,
+ success: function (results) {}
+ });
+} \ No newline at end of file