Skip to content

Commit

Permalink
working with prod socket conn and removing env deps
Browse files Browse the repository at this point in the history
  • Loading branch information
sidmohanty11 committed Apr 3, 2022
1 parent cdd7794 commit 9e508f3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 31 deletions.
8 changes: 0 additions & 8 deletions app/.env.local.sample
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,5 @@ ROCKETCHAT_CLIENT_SECRET="client secret"
ROCKETCHAT_URL="base url of rocket chat server"
### END: Environment variables for RocketChat OAuth legacy

# INAPPCHAT
# for development it defaults to: http://localhost:3000
# in prod, it should be: [PROTOCOL]://[DOMAIN]:[PORT]
NEXT_PUBLIC_ROCKET_CHAT_HOST=requiredInProd
# id of the room where conf will take place
NEXT_PUBLIC_ROCKET_CHAT_CONF_RID=required
# id of the greenroom
NEXT_PUBLIC_ROCKET_CHAT_GREENROOM_RID=required
NEXT_PUBLIC_ROCKET_CHAT_GREENROOM_RTMP="rtmp://bkk.contribute.live-video.net/app/{stream_key}"

6 changes: 2 additions & 4 deletions app/components/inappchat/inappchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ import MDPreview from '../mdpreview';
import InappchatTextInput from './inappchattextinput';
import { useMediaQuery } from '@rocket.chat/fuselage-hooks';

const rcClient = new Rocketchat({ logger: console, protocol: 'ddp' });

const InAppChat = ({ host, closeChat, rid }) => {
const [messages, setMessages] = useState([]);
const emojiAnimationRef = useRef();

const isSmallScreen = useMediaQuery("(max-width: 992px)");
const cookies = { rc_token: Cookie.get('rc_token'), rc_uid: Cookie.get('rc_uid') };
const isAuth = cookies.rc_token && cookies.rc_uid;
const rcURL = new URL(host);
const useSsl = !/http:\/\//.test(host);
const rcClient = new Rocketchat({ logger: console, protocol: 'ddp', host, useSsl });

function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
Expand Down Expand Up @@ -93,7 +91,7 @@ const InAppChat = ({ host, closeChat, rid }) => {
useEffect(() => {
const runRealtime = async (token, rid) => {
try {
await rcClient.connect({ host: rcURL.host, useSsl });
await rcClient.connect();
await rcClient.resume({ token });
await rcClient.subscribe("stream-room-messages", rid);
rcClient.onMessage((data) => {
Expand Down
17 changes: 6 additions & 11 deletions app/components/inappchat/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import axios from 'axios';

export const getMessages = async (host, rid, cookies) => {
try {
const messages = await fetch(
`${host}/api/v1/channels.messages?roomId=${rid}`,
{
headers: {
"Content-Type": "application/json",
const messages = await axios.get(`${host}/api/v1/channels.messages?roomId=${rid}`, { headers: {
"Content-Type": "application/json",
"X-Auth-Token": cookies.rc_token ?? "",
"X-User-Id": cookies.rc_uid ?? "",
},
method: "GET",
}
);

return await messages.json();
} })
return messages.data;
} catch (err) {
console.log(err.message);
}
Expand Down
8 changes: 3 additions & 5 deletions app/pages/virtualconf/greenroom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import styles from "../../../styles/Mainstage.module.css";
import { Container, Row, Col } from "react-bootstrap";
import Jitsibroadcaster from "../../../components/clientsideonly/jitsibroadcaster";
import InAppChat from "../../../components/inappchat/inappchat";
const greenroom_rid = process.env.NEXT_PUBLIC_ROCKET_CHAT_GREENROOM_RID;
const host =
process.env.NODE_ENV === "development"
? "http://localhost:3000"
: "https://community.liaison.rocketchat.digital";

const greenroom_rid = "GENERAL";
const host = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://community.liaison.rocketchat.digital";

const Greenroom = () => {
const [openChat, setOpenChat] = useState(false);
Expand Down
6 changes: 3 additions & 3 deletions app/pages/virtualconf/mainstage/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import InAppChat from '../../../components/inappchat/inappchat';
import { useMediaQuery } from '@rocket.chat/fuselage-hooks';
import styles from '../../../styles/Videostreamer.module.css';

const rid = process.env.NEXT_PUBLIC_ROCKET_CHAT_CONF_RID;
const rid = "GENERAL";
const host = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://community.liaison.rocketchat.digital";

export default function ConfMainStage({ cookies }) {
export default function ConfMainStage() {
const [openChat, setOpenChat] = useState(true);
const isSmallScreen = useMediaQuery('(max-width: 992px)');

Expand Down Expand Up @@ -46,7 +46,7 @@ export default function ConfMainStage({ cookies }) {
<svg
xmlns='http://www.w3.org/2000/svg'
fill='currentColor'
class='bi bi-chat-dots'
className='bi bi-chat-dots'
viewBox='0 0 16 16'
>
<path d='M5 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm4 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm3 1a1 1 0 1 0 0-2 1 1 0 0 0 0 2z' />
Expand Down

0 comments on commit 9e508f3

Please sign in to comment.