detecting ip based url and use http

This commit is contained in:
Roland Osborne 2024-05-03 13:25:25 -07:00
parent 0bcb289833
commit aab471eed7
3 changed files with 9 additions and 3 deletions

View File

@ -192,7 +192,9 @@ export function useAppContext() {
}
const setWebsocket = (session) => {
ws.current = createWebsocket(`wss://${session.server}/status?mode=ring`);
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(session.server);
const protocol = insecure ? 'ws' : 'wss';
ws.current = createWebsocket(`${protocol}://${session.server}/status?mode=ring`);
ws.current.onmessage = (ev) => {
if (ev.data == '') {
actions.logout();

View File

@ -239,7 +239,9 @@ export function useRingContext() {
videoTrack.current = false;
audioTrack.current = false;
ws.current = createWebsocket(`wss://${node}/signal`);
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(node);
const protocol = insecure ? 'ws' : 'wss';
ws.current = createWebsocket(`${protocol}://${node}/signal`);
ws.current.onmessage = async (ev) => {
// handle messages [impolite]
try {

View File

@ -66,11 +66,13 @@ export function useUploadContext() {
const actions = {
addTopic: (node, token, channelId, topicId, files, success, failure, cardId) => {
const insecure = /^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|:\d+$|$)){4}$/.test(node);
const protocol = insecure ? 'http' : 'https';
const key = cardId ? `${cardId}:${channelId}` : `:${channelId}`;
const controller = new AbortController();
const entry = {
index: index.current,
baseUrl: cardId ? `https://${node}/content/channels/${channelId}/topics/${topicId}/` : `https://${node}/content/channels/${channelId}/topics/${topicId}/`,
baseUrl: cardId ? `${protocol}://${node}/content/channels/${channelId}/topics/${topicId}/` : `${protocol}://${node}/content/channels/${channelId}/topics/${topicId}/`,
urlParams: cardId ? `?contact=${token}` : `?agent=${token}`,
files,
assets: [],