diff --git a/.babelrc b/.babelrc index ded31c0..cd7d9f1 100644 --- a/.babelrc +++ b/.babelrc @@ -1,18 +1,26 @@ { "presets": [ - ["env", { - "modules": false, - "targets": { - "browsers": "> 1%", - "uglify": true - }, - "useBuiltIns": true - }] + [ + "env", + { + "modules": false, + "targets": { + "browsers": "> 1%", + "uglify": true + }, + "useBuiltIns": true + } + ] ], - "plugins": [ "syntax-dynamic-import", "transform-object-rest-spread", - ["transform-class-properties", { "spec": true }] + "transform-runtime", + [ + "transform-class-properties", + { + "spec": true + } + ] ] } diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index dd8b1f4..479ef60 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -13,8 +13,6 @@ class PagesController < ApplicationController end - - def cable_testing chatroom = 'chat_room_' + params[:chat_room_id] puts params diff --git a/app/javascript/components/modal.js b/app/javascript/components/modal.js index 25eb307..a35d32a 100644 --- a/app/javascript/components/modal.js +++ b/app/javascript/components/modal.js @@ -1,11 +1,12 @@ - const triggerModalEvent = () => { const btn = document.getElementById("modalTrigger"); const modal = document.getElementById("myModal"); - btn.addEventListener('click', function(event) { - $('#myModal').modal('show'); - }); + if (btn) { + btn.addEventListener('click', function(event) { + $('#myModal').modal('show'); + }); + } } export { triggerModalEvent } diff --git a/app/javascript/packs/chatrooms.js b/app/javascript/packs/chatrooms.js index 46b193b..a72d582 100644 --- a/app/javascript/packs/chatrooms.js +++ b/app/javascript/packs/chatrooms.js @@ -23,13 +23,13 @@ App['chatroom' + chatroomId] = App.cable.subscriptions.create({ }) // Testing ActionCable -const testBtn = document.getElementById('test-btn') -testBtn.addEventListener('click', event => { - fetch(`/chat_rooms/${chatroomId}/cable_testing` , { - method: 'POST', - body: JSON.stringify({}) - }) -}) +// const testBtn = document.getElementById('test-btn') +// testBtn.addEventListener('click', event => { +// fetch(`/chat_rooms/${chatroomId}/cable_testing` , { +// method: 'POST', +// body: JSON.stringify({}) +// }) +// }) diff --git a/app/javascript/packs/notifications.js b/app/javascript/packs/notifications.js index cff3892..9310ce3 100644 --- a/app/javascript/packs/notifications.js +++ b/app/javascript/packs/notifications.js @@ -12,7 +12,6 @@ import ActionCable from 'actioncable' const userId = parseInt(document.getElementById("my-user-id").dataset["userId"]) let chatRoomId = null - App.cable.subscriptions.create({ channel: 'NotificationsChannel' }, { @@ -24,19 +23,13 @@ App.cable.subscriptions.create({ // console.log(userId) console.log("received broadcast") // console.log(data.body) - if (data.head === 302 && data.body["caller"] === userId && data.path ) { + if (data.head === 302 && data.body["caller"] === userId && data.path) { window.location.pathname = data.path - } else if (data["message"]["user_id"] === userId) { + } else if (data["message"]["user_id"] === userId) { // Some error appears here but it is not fatal console.log("TRIGGER MODAL") const acceptButton = document.getElementById('accept-button') acceptButton.style.display = "block" - // const receiveCall = document.getElementById('receive-call') - // receiveCall.dataset.toggle = 'modal' - // receiveCall.dataset.target ='#calleeModal' - // console.log(receiveCall) - // const calleeModal = document.getElementById('calleeModal') - // calleeModal.modal("show") chatRoomId = data["message"]["chat_room_id"] console.log(`user with id: ${userId} needs to subscribe to chatroom ${[chatRoomId]}`) } else { diff --git a/app/assets/javascripts/signaling-server.js b/app/javascript/packs/webrtc.js similarity index 75% rename from app/assets/javascripts/signaling-server.js rename to app/javascript/packs/webrtc.js index e8a88c0..5bf7376 100644 --- a/app/assets/javascripts/signaling-server.js +++ b/app/javascript/packs/webrtc.js @@ -1,7 +1,5 @@ // Broadcast Types -class Signaling {} - const JOIN_ROOM = "JOIN_ROOM"; const EXCHANGE = "EXCHANGE"; const REMOVE_USER = "REMOVE_USER"; @@ -16,12 +14,9 @@ let pcPeers = {}; // peer connection let localstream; window.onload = () => { - // if (document.getElementById("current-user")) { - currentUser = document.getElementById("current-user").innerHTML; - console.log(currentUser) - localVideo = document.getElementById("local-video"); - remoteVideoContainer = document.getElementById("remote-video-container"); - // } + currentUser = document.getElementById("current-user").innerHTML; + localVideo = document.getElementById("local-video"); + remoteVideoContainer = document.getElementById("remote-video-container"); }; // Ice Credentials @@ -37,45 +32,14 @@ document.onreadystatechange = async () => { }) localstream = stream; - // if (localVideo) { - localVideo.srcObject = stream - localVideo.muted = true - // } + localVideo.srcObject = stream + localVideo.muted = true } catch (e) { console.error(e); } } }; -// find chatroom -// const handleJoinSession = async () => { -// App.session = await App.cable.subscriptions.create("VideoSessionChannel", { -// connected: () => { -// broadcastData({ -// type: JOIN_ROOM, -// from: currentUser -// }); -// }, -// received: data => { -// console.log("received", data); -// if (data.from === currentUser) return; -// switch (data.type) { -// case JOIN_ROOM: -// return joinRoom(data); -// case EXCHANGE: -// if (data.to !== currentUser) return; -// return exchange(data); -// case REMOVE_USER: -// return removeUser(data); -// default: -// return; -// } -// } -// }); -// }; -// if (document.getElementById('chatroom-hook')) { - const chatroomId = document.getElementById('chatroom-hook').dataset["chatroomId"] - -// } +const chatroomId = document.getElementById('chatroom-hook').dataset["chatroomId"] const handleJoinSession = async () => { App['chatroom' + chatroomId] = await App.cable.subscriptions.create({ @@ -83,7 +47,6 @@ const handleJoinSession = async () => { room: chatroomId }, { connected: () => { - console.log(chatroomId) broadcastData({ type: JOIN_ROOM, from: currentUser, @@ -91,7 +54,6 @@ const handleJoinSession = async () => { }); }, received: data => { - console.log(data) if (data.from === currentUser) return; switch (data.type) { case JOIN_ROOM: @@ -136,9 +98,6 @@ const removeUser = data => { const broadcastData = data => { - if (data.type === EXCHANGE) { - console.log("yayyy") - } fetch("chat_room_sessions", { method: "POST", body: JSON.stringify(data), @@ -220,7 +179,7 @@ const exchange = data => { } if (data.sdp) { - sdp = JSON.parse(data.sdp); + const sdp = JSON.parse(data.sdp); pc .setRemoteDescription(new RTCSessionDescription(sdp)) .then(() => { @@ -242,3 +201,15 @@ const exchange = data => { }; const logError = error => console.warn("Whoops! Error:", error); + + +const joinButton = document.getElementById("join-btn") +joinButton.addEventListener('click', event => { + handleJoinSession() +}) + +// WARNING: COMPLETELY HACKISH SOLUTION --> MUST INTRODUCE SOME SORT OF DELAY! +setTimeout(function() { + joinButton.click() +}, 5000); + diff --git a/app/views/chat_rooms/show.html.erb b/app/views/chat_rooms/show.html.erb index 0835cd4..fd9e62f 100644 --- a/app/views/chat_rooms/show.html.erb +++ b/app/views/chat_rooms/show.html.erb @@ -1,27 +1,19 @@ - - - +
+ -<%= contact.email %>
<% else %> -<%= contact.email %>
- +<%= contact.first_name %> <%= contact.last_name %>
<% end %>Last call: <%= Time.now %>