diff --git a/app/controllers/video_chats_controller.rb b/app/controllers/video_chats_controller.rb
index c8262322c..055eca400 100644
--- a/app/controllers/video_chats_controller.rb
+++ b/app/controllers/video_chats_controller.rb
@@ -1,7 +1,11 @@
class VideoChatsController < ApplicationController
before_action :authenticate_user!
+ after_action :verify_authorized
def show
+ @chat_channel = ChatChannel.find(params[:id]) || not_found
+ authorize @chat_channel
+
account_sid = ApplicationConfig["TWILIO_ACCOUNT_SID"]
api_key = ApplicationConfig["TWILIO_VIDEO_API_KEY"]
api_secret = ApplicationConfig["TWILIO_VIDEO_API_SECRET"]
diff --git a/app/javascript/chat/chat.jsx b/app/javascript/chat/chat.jsx
index 7fc9f0e74..858bd3598 100644
--- a/app/javascript/chat/chat.jsx
+++ b/app/javascript/chat/chat.jsx
@@ -597,12 +597,16 @@ export default class Chat extends Component {
if (message.startsWith('/code')) {
this.setActiveContentState(activeChannelId, { type_of: 'code_editor' });
} else if (message.startsWith('/call')) {
- this.setState({ activeVideoChannelId: activeChannelId });
- window.pusher
- .channel(`presence-channel-${activeChannelId}`)
- .trigger('client-initiatevideocall', {
- channelId: activeChannelId,
- });
+ const messageObject = {
+ activeChannelId,
+ message: '/call',
+ mentionedUsersId: this.getMentionedUsers(message),
+ };
+ this.setActiveContent({
+ path: '/video_chats/'+activeChannelId,
+ type_of: 'article',
+ });
+ sendMessage(messageObject, this.handleSuccess, this.handleFailure);
} else if (message.startsWith('/new')) {
this.setActiveContentState(activeChannelId, {
type_of: 'loading-post',
diff --git a/app/javascript/packs/videoChat.jsx b/app/javascript/packs/videoChat.jsx
index c9cdd1a0d..4ca92d5b7 100644
--- a/app/javascript/packs/videoChat.jsx
+++ b/app/javascript/packs/videoChat.jsx
@@ -1,22 +1,25 @@
const { createLocalVideoTrack, connect } = require('twilio-video');
-const root = document.getElementById('chat');
+const root = document.getElementById('videochat');
const muteButton = document.getElementById('mute-toggle');
-const videoToggleButton = document.getElementById('videohide-toggle')
+const videoToggleButton = document.getElementById('videohide-toggle');
+let numConnected = 0;
connect(root.dataset.token, { name: 'room-name', audio: true, type: 'peer-to-peer', video: { width: 640 } }).then(room => {
room.participants.forEach(participantConnected);
room.on('participantConnected', participantConnected);
room.on('participantDisconnected', participantDisconnected);
room.once('disconnected', error => room.participants.forEach(participantDisconnected));
-
+ console.log(room.participants.length)
muteButton.onclick = function(e) {
e.preventDefault();
room.localParticipant.audioTracks.forEach(function(trackPub) {
if (muteButton.dataset.muted === 'true') {
muteButton.dataset.muted = 'false'
+ muteButton.classList.remove('active');
trackPub.track.enable();
} else {
muteButton.dataset.muted = 'true'
+ muteButton.classList.add('active');
trackPub.track.disable();
}
});
@@ -27,9 +30,11 @@ connect(root.dataset.token, { name: 'room-name', audio: true, type: 'peer-to-pee
room.localParticipant.videoTracks.forEach(function(trackPub) {
if (videoToggleButton.dataset.hidden === 'true') {
videoToggleButton.dataset.hidden = 'false'
+ videoToggleButton.classList.remove('active');
trackPub.track.enable();
} else {
videoToggleButton.dataset.hidden = 'true'
+ videoToggleButton.classList.add('active');
trackPub.track.disable();
}
});
@@ -59,8 +64,19 @@ function participantConnected(participant) {
trackSubscribed(div, publication.track);
}
});
-
root.appendChild(div);
+ numConnected += 1;
+ let gridStyle = 'one-per';
+ if (numConnected > 2) {
+ gridStyle = 'two-per';
+ }
+ if (numConnected > 6) {
+ gridStyle = 'three-per';
+ }
+ if (numConnected > 9) {
+ gridStyle = 'four-per';
+ }
+ root.className = 'video-chat-wrapper video-chat-wrapper-num-' + gridStyle;
}
function participantDisconnected(participant) {
diff --git a/app/models/message.rb b/app/models/message.rb
index e8bfd4c6e..7a123d31e 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -42,6 +42,7 @@ class Message < ApplicationRecord
html = MarkdownParser.new(message_markdown).evaluate_markdown
html = append_rich_links(html)
html = wrap_mentions_with_links(html)
+ html = handle_call(html)
self.message_html = html
end
@@ -118,19 +119,23 @@ class Message < ApplicationRecord
#{user.name}
".html_safe
- elsif anchor["href"].include?("/video_chats/")
- html += "
-
- 👾 Experimental Video Chat Started
-
- ".html_safe
end
end
html
end
+ def handle_call(html)
+ return html if html.to_s.exclude?("
/call
") + + " +