added js package so that es7 syntax works, moved signaling-server from apps folder to pack folder, removed recurring js errors

This commit is contained in:
Beatrice Olivera 2018-08-31 20:47:33 +01:00
parent 62194ffea4
commit fbde469f45
8 changed files with 61 additions and 86 deletions

View File

@ -1,18 +1,26 @@
{ {
"presets": [ "presets": [
["env", { [
"env",
{
"modules": false, "modules": false,
"targets": { "targets": {
"browsers": "> 1%", "browsers": "> 1%",
"uglify": true "uglify": true
}, },
"useBuiltIns": true "useBuiltIns": true
}] }
]
], ],
"plugins": [ "plugins": [
"syntax-dynamic-import", "syntax-dynamic-import",
"transform-object-rest-spread", "transform-object-rest-spread",
["transform-class-properties", { "spec": true }] "transform-runtime",
[
"transform-class-properties",
{
"spec": true
}
]
] ]
} }

View File

@ -3,9 +3,11 @@ const triggerModalEvent = () => {
const btn = document.getElementById("modalTrigger"); const btn = document.getElementById("modalTrigger");
const modal = document.getElementById("myModal"); const modal = document.getElementById("myModal");
if (btn) {
btn.addEventListener('click', function(event) { btn.addEventListener('click', function(event) {
$('#myModal').modal('show'); $('#myModal').modal('show');
}); });
}
} }
export { triggerModalEvent } export { triggerModalEvent }

View File

@ -23,13 +23,13 @@ App['chatroom' + chatroomId] = App.cable.subscriptions.create({
}) })
// Testing ActionCable // Testing ActionCable
const testBtn = document.getElementById('test-btn') // const testBtn = document.getElementById('test-btn')
testBtn.addEventListener('click', event => { // testBtn.addEventListener('click', event => {
fetch(`/chat_rooms/${chatroomId}/cable_testing` , { // fetch(`/chat_rooms/${chatroomId}/cable_testing` , {
method: 'POST', // method: 'POST',
body: JSON.stringify({}) // body: JSON.stringify({})
}) // })
}) // })

View File

@ -1,7 +1,5 @@
// Broadcast Types // Broadcast Types
class Signaling {}
const JOIN_ROOM = "JOIN_ROOM"; const JOIN_ROOM = "JOIN_ROOM";
const EXCHANGE = "EXCHANGE"; const EXCHANGE = "EXCHANGE";
const REMOVE_USER = "REMOVE_USER"; const REMOVE_USER = "REMOVE_USER";
@ -16,12 +14,9 @@ let pcPeers = {}; // peer connection
let localstream; let localstream;
window.onload = () => { window.onload = () => {
// if (document.getElementById("current-user")) {
currentUser = document.getElementById("current-user").innerHTML; currentUser = document.getElementById("current-user").innerHTML;
console.log(currentUser)
localVideo = document.getElementById("local-video"); localVideo = document.getElementById("local-video");
remoteVideoContainer = document.getElementById("remote-video-container"); remoteVideoContainer = document.getElementById("remote-video-container");
// }
}; };
// Ice Credentials // Ice Credentials
@ -37,45 +32,14 @@ document.onreadystatechange = async () => {
}) })
localstream = stream; localstream = stream;
// if (localVideo) {
localVideo.srcObject = stream localVideo.srcObject = stream
localVideo.muted = true localVideo.muted = true
// }
} catch (e) { console.error(e); } } 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 () => { const handleJoinSession = async () => {
App['chatroom' + chatroomId] = await App.cable.subscriptions.create({ App['chatroom' + chatroomId] = await App.cable.subscriptions.create({
@ -83,7 +47,6 @@ const handleJoinSession = async () => {
room: chatroomId room: chatroomId
}, { }, {
connected: () => { connected: () => {
console.log(chatroomId)
broadcastData({ broadcastData({
type: JOIN_ROOM, type: JOIN_ROOM,
from: currentUser, from: currentUser,
@ -91,7 +54,6 @@ const handleJoinSession = async () => {
}); });
}, },
received: data => { received: data => {
console.log(data)
if (data.from === currentUser) return; if (data.from === currentUser) return;
switch (data.type) { switch (data.type) {
case JOIN_ROOM: case JOIN_ROOM:
@ -136,9 +98,6 @@ const removeUser = data => {
const broadcastData = data => { const broadcastData = data => {
if (data.type === EXCHANGE) {
console.log("yayyy")
}
fetch("chat_room_sessions", { fetch("chat_room_sessions", {
method: "POST", method: "POST",
body: JSON.stringify(data), body: JSON.stringify(data),
@ -220,7 +179,7 @@ const exchange = data => {
} }
if (data.sdp) { if (data.sdp) {
sdp = JSON.parse(data.sdp); const sdp = JSON.parse(data.sdp);
pc pc
.setRemoteDescription(new RTCSessionDescription(sdp)) .setRemoteDescription(new RTCSessionDescription(sdp))
.then(() => { .then(() => {
@ -242,3 +201,9 @@ const exchange = data => {
}; };
const logError = error => console.warn("Whoops! Error:", error); const logError = error => console.warn("Whoops! Error:", error);
const joinButton = document.getElementById("join-btn")
joinButton.addEventListener('click', event => {
handleJoinSession()
})

View File

@ -1,9 +1,8 @@
<button onclick="handleJoinSession()" data-room="<%= @chat_room.id %>">Join Room</button> <button id="join-btn" data-room="<%= @chat_room.id %>">Join Room</button>
<!-- <div id="join-session" data-room="<%= @chat_room.id %>"> --> <!-- <div id="join-session" onclick="handleJoinSession()" data-room="<%= @chat_room.id %>"> -->
<!-- <h1 style="color: white;">This is chatroom #<%= @chat_room.id %></h1> -->
<div id="chatroom-hook" data-chatroom-id='<%= @chat_room.id %>'></div> <div id="chatroom-hook" data-chatroom-id='<%= @chat_room.id %>'></div>
<!-- <button id="test-btn">Test Connection</button> -->
<div class="call-container"> <div class="call-container">
<div id="remote-video-container"> <div id="remote-video-container">
<div id="video_overlays"> <div id="video_overlays">
@ -16,12 +15,12 @@
<span id="current-user" class="text-color" style="display:none"><%= current_user.id %></span> <span id="current-user" class="text-color" style="display:none"><%= current_user.id %></span>
</div> </div>
<!-- <script>
const joinSession = document.getElementById("join-session")
joinSession.addEventListener('load', event => {
handleJoinSession()
})
</script> -->
<%= javascript_pack_tag 'chatrooms' %> <%= javascript_pack_tag 'chatrooms' %>
<%= javascript_pack_tag 'webrtc' %>
<script>
</script>

View File

@ -1,9 +1,3 @@
<%
def hello_world
puts "Hello World"
end
%>
<div class="card"> <div class="card">
<div class="info"> <div class="info">
<% if contact.photo.url.nil? %> <% if contact.photo.url.nil? %>

View File

@ -4,6 +4,7 @@
"dependencies": { "dependencies": {
"@rails/webpacker": "3.5", "@rails/webpacker": "3.5",
"actioncable": "^5.2.1", "actioncable": "^5.2.1",
"babel-plugin-transform-runtime": "^6.23.0",
"bootstrap": "3", "bootstrap": "3",
"jquery": "^3.3.1" "jquery": "^3.3.1"
}, },

View File

@ -680,6 +680,12 @@ babel-plugin-transform-regenerator@^6.22.0:
dependencies: dependencies:
regenerator-transform "^0.10.0" regenerator-transform "^0.10.0"
babel-plugin-transform-runtime@^6.23.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz#88490d446502ea9b8e7efb0fe09ec4d99479b1ee"
dependencies:
babel-runtime "^6.22.0"
babel-plugin-transform-strict-mode@^6.24.1: babel-plugin-transform-strict-mode@^6.24.1:
version "6.24.1" version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758"