Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Visoff committed Aug 12, 2023
1 parent 0ea1af8 commit 88e6aab
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
7 changes: 1 addition & 6 deletions golang_server/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import (
var Mux *http.ServeMux = http.NewServeMux()

func Init() {
Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
AllowCors(&w)
w.WriteHeader(200)
w.Write([]byte("pong"))
})
Mux.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
Mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
AllowCors(&w)
w.WriteHeader(200)
w.Write([]byte("pong"))
Expand Down
3 changes: 1 addition & 2 deletions golang_server/db/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package db

import (
"database/sql"
"fmt"
"strings"

_ "github.com/lib/pq"
Expand All @@ -17,7 +16,7 @@ func UrlFromEnv(env func(string, string) string) string {
func Connect(url string) error {
// return nil
var err error
fmt.Println(url)
// fmt.Println(url)
Db, err = sql.Open("postgres", url)
if err != nil {
return err
Expand Down
Binary file modified golang_server/main.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ http {
server {
listen 80;

location / {
location /server/ {
proxy_pass http://goserver:8080/api/;
}
}
Expand Down
3 changes: 2 additions & 1 deletion svelte_client/src/components/Layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { browser } from "$app/environment";
import SelectAppNav from "./SelectAppNav.svelte";
import {clerk as clerk_import, clerk_ready} from "$lib"
import { host } from "$lib/env";
let signOut = () => {}
Expand All @@ -17,7 +18,7 @@
return
}
if (localStorage.getItem("user_token") == undefined) {
fetch("http://localhost:8080/api/user/sign/", {
fetch(host+"/user/sign/", {
method:"POST",
body:clerk.user.id
}).then(response => response.text())
Expand Down
7 changes: 4 additions & 3 deletions svelte_client/src/components/chat/ChatList.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts">
import { browser } from "$app/environment";
import { host } from "$lib/env";
import Chat from "./Chat.svelte";
let chats:any[] = []
if (browser) {
fetch("http://localhost:8080/api/user/chats", {
fetch(host+"/user/chats", {
method:"GET",
headers:{
Authorization:`Bearer ${localStorage.getItem("user_token")}`
Expand All @@ -25,7 +26,7 @@
if (name == undefined) return;
const description = prompt("Chat description")
if (description == undefined) return;
fetch("http://localhost:8080/api/chat/", {
fetch(host+"/chat/", {
method:"POST",
headers:{
Authorization:`Bearer ${localStorage.getItem("user_token")}`,
Expand All @@ -40,7 +41,7 @@
if (browser) {
let longpoll = new Date().toISOString()
setInterval(() => {
fetch("http://localhost:8080/api/user/chats", {
fetch(host+"/user/chats", {
method:"GET",
headers:{
Authorization:`Bearer ${localStorage.getItem("user_token")}`,
Expand Down
3 changes: 2 additions & 1 deletion svelte_client/src/components/chat/MessageInput.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import {CurrentChat} from '$lib'
import { host } from '$lib/env';
let typing:Boolean = false
function CheckTyping(e:Event&{currentTarget: HTMLInputElement}) {
typing = (e.target as HTMLInputElement).value != ""
Expand All @@ -9,7 +10,7 @@
e.preventDefault()
const content = (e.target as any)[0].value
if (content == "") return;
fetch("http://localhost:8080/api/message", {
fetch(host+"/message", {
method:"POST",
headers:{
Authorization:`Bearer ${localStorage.getItem("user_token")}`,
Expand Down
5 changes: 3 additions & 2 deletions svelte_client/src/components/chat/MessageList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { CurrentChat } from '$lib'
import { browser } from "$app/environment";
import Message from "./Message.svelte";
import { host } from '$lib/env';
function onChatChange(chat_id:string|false) {
if (!browser) {
Expand All @@ -17,7 +18,7 @@
}
]
}
fetch("http://localhost:8080/api/chat/messages/", {
fetch(host+"/chat/messages/", {
method:"GET",
headers:{
Authorization:`Bearer ${localStorage.getItem("user_token")}`,
Expand All @@ -38,7 +39,7 @@
if (browser) {
let last_time = new Date().toISOString()
setInterval(() => {
fetch("http://localhost:8080/api/chat/messages/", {
fetch(host+"/chat/messages/", {
method:"GET",
headers:{
Authorization:`Bearer ${localStorage.getItem("user_token")}`,
Expand Down
1 change: 1 addition & 0 deletions svelte_client/src/lib/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const host:string = "http://goserver:8080/api"
16 changes: 9 additions & 7 deletions svelte_client/src/lib/rtc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { host } from "./env"

/*const servers = {
iceServers:[
{
Expand All @@ -13,7 +15,7 @@
const servers = {}

function WaitForAnswer(pc:RTCPeerConnection, call:string) {
fetch("http://localhost:8080/api/conference/answer", {
fetch(host+"/conference/answer", {
method:"GET",
headers:{
Call:call
Expand All @@ -36,7 +38,7 @@ function WaitForAnswer(pc:RTCPeerConnection, call:string) {
function listenForIce(call:string, callback:(candidate:RTCIceCandidate) => void) {
let date = new Date().toISOString()
setInterval(() => {
fetch("http://localhost:8080/api/conference/icepoll", {
fetch(host+"/conference/icepoll", {
method:"GET",
headers:{
Call:call,
Expand All @@ -56,7 +58,7 @@ function listenForIce(call:string, callback:(candidate:RTCIceCandidate) => void)
}

function AddIceCandidate(ice:RTCIceCandidate, call:string) {
fetch("http://localhost:8080/api/conference/ice", {
fetch(host+"/conference/ice", {
method:"POST",
headers:{
Call:call
Expand All @@ -73,7 +75,7 @@ export async function call(stream:MediaStream, local_video_tag:HTMLVideoElement,
pc.addTrack(track, stream)
});
const offer = await pc.createOffer()
const call = await fetch("http://localhost:8080/api/conference/call", {
const call = await fetch(host+"/conference/call", {
method:"POST",
body:JSON.stringify({
sdp:offer.sdp,
Expand Down Expand Up @@ -118,7 +120,7 @@ export async function answer(id:string, local_video_tag:HTMLVideoElement, remote
localStream.getTracks().forEach(track => {
pc.addTrack(track, localStream)
})
const starterice = await fetch("http://localhost:8080/api/conference/ice", {
const starterice = await fetch(host+"/conference/ice", {
method:"GET",
headers:{
Call:id
Expand All @@ -136,7 +138,7 @@ export async function answer(id:string, local_video_tag:HTMLVideoElement, remote
stream.addTrack(track)
})
}
const offer = await (await fetch("http://localhost:8080/api/conference/call", {
const offer = await (await fetch(host+"/conference/call", {
method:"GET",
headers:{
"Call":id
Expand All @@ -147,7 +149,7 @@ export async function answer(id:string, local_video_tag:HTMLVideoElement, remote
pc.addIceCandidate(new RTCIceCandidate(JSON.parse(ice.Candidate)))
})
const answer = await pc.createAnswer()
fetch("http://localhost:8080/api/conference/answer", {
fetch(host+"/conference/answer", {
method:"POST",
headers:{
"Call":id
Expand Down

0 comments on commit 88e6aab

Please sign in to comment.