From 5aa9bec9ae6e2bd53b077bcf281c6390d9df70b0 Mon Sep 17 00:00:00 2001 From: balzack Date: Sun, 19 Mar 2023 15:11:00 -0700 Subject: [PATCH] removing test code --- app/mobile/src/session/profile/Profile.jsx | 271 ++++++++------------- net/web/src/session/welcome/Welcome.jsx | 140 +---------- 2 files changed, 99 insertions(+), 312 deletions(-) diff --git a/app/mobile/src/session/profile/Profile.jsx b/app/mobile/src/session/profile/Profile.jsx index a7822fdf..93cc2397 100644 --- a/app/mobile/src/session/profile/Profile.jsx +++ b/app/mobile/src/session/profile/Profile.jsx @@ -1,4 +1,3 @@ -import { useEffect, useRef, useState } from 'react'; import { ActivityIndicator, KeyboardAvoidingView, Modal, View, Switch, Text, TextInput, TouchableOpacity, Alert } from 'react-native'; import Ionicons from 'react-native-vector-icons/AntDesign'; import MatIcons from 'react-native-vector-icons/MaterialCommunityIcons'; @@ -11,18 +10,6 @@ import { BlockedTopics } from './blockedTopics/BlockedTopics'; import { BlockedContacts } from './blockedContacts/BlockedContacts'; import { BlockedMessages } from './blockedMessages/BlockedMessages'; -import { - ScreenCapturePickerView, - RTCPeerConnection, - RTCIceCandidate, - RTCSessionDescription, - RTCView, - MediaStream, - MediaStreamTrack, - mediaDevices, - registerGlobals -} from 'react-native-webrtc'; - export function ProfileHeader() { const { state, actions } = useProfile(); @@ -33,155 +20,6 @@ export function ProfileHeader() { export function ProfileBody() { const { state, actions } = useProfile(); - const ws = useRef(); - const peer = useRef(); - const stream = useRef(); - const [streamUrl, setStreamUrl] = useState(null); - const localMediaStream = useRef(); - - useEffect(() => { - - -console.log("WS CONNECT!!!"); -console.log("WS CONNECT!!!"); -console.log("WS CONNECT!!!"); -console.log("WS CONNECT!!!"); -console.log("WS CONNECT!!!"); -console.log("WS CONNECT!!!"); -console.log("WS CONNECT!!!"); - ws.current = new WebSocket('wss://balzack.coredb.org/relay'); - ws.current.onmessage = async (ev) => { - - const msg = JSON.parse(ev.data); - if (msg.candidate) { - console.log("> CANDIDATE: ", msg.candidate); - const candidate = new RTCIceCandidate( msg.candidate ); - return peer.current.addIceCandidate(candidate); - } - else if (msg.offer) { - console.log("> OFFER: ", msg.offer); - const offerDescription = new RTCSessionDescription(msg.offer ); - await peer.current.setRemoteDescription( offerDescription ); - const answer = await peer.current.createAnswer(); - await peer.current.setLocalDescription( answer ); - ws.current.send(JSON.stringify({ answer })); - } - else if (msg.answer) { - console.log("> ANSWER: ", msg.answer); - const answer = new RTCSessionDescription( msg.answer ); - await peer.current.setRemoteDescription( answer ); - } - } - ws.current.onclose = (e) => { - console.log("CLOSED"); - } - ws.current.onopen = () => { - console.log("OPENED"); - } - ws.current.error = (e) => { - console.log("ERROR"); - } - - - - let peerConstraints = { - iceServers: [ - { - urls: 'stun:192.168.13.233:5001?transport=udp', - username: 'user', - credential: 'pass' - }, - { - urls: 'turn:192.168.13.233:5001?transport=udp', - username: 'user', - credential: 'pass' - }] - }; - - peer.current = new RTCPeerConnection( peerConstraints ); - go(); - - peer.current.addEventListener( 'connectionstatechange', event => { - console.log("CONNECTION STATE"); - } ); - - peer.current.addEventListener( 'icecandidate', event => { - if ( !event.candidate ) { return; }; - ws.current.send(JSON.stringify({ candidate: event.candidate })); - console.log("SEND CANDIDATE!!!"); - } ); - - peer.current.addEventListener( 'icecandidateerror', event => { - console.log("ICE ERROR"); - } ); - - peer.current.addEventListener( 'iceconnectionstatechange', event => { - console.log("ICE STATE CHANGE"); - } ); - - peer.current.addEventListener( 'negotiationneeded', event => { - console.log("ICE NEGOTIATION"); - start(); - } ); - - peer.current.addEventListener( 'signalingstatechange', event => { - console.log("ICE SIGNALING"); - } ); - - peer.current.addEventListener( 'track', event => { - console.log("ICE TRACK", event.track); - // Grab the remote track from the connected participant. - //remoteMediaStream = remoteMediaStream || new MediaStream(); - //remoteMediaStream.addTrack( event.track, remoteMediaStream ); - - if (!stream.current) { - stream.current = new MediaStream(); - } - stream.current.addTrack(event.track, stream.current); - setStreamUrl(stream.current.toURL()); - } ); - - }, []); - - const go = async () => { - - - let mediaConstraints = { - audio: true, - video: { - frameRate: 4, - facingMode: 'user' - } - }; - -console.log("GETTING MEDIA DEVICES"); - - localMediaStream.current = await mediaDevices.getUserMedia( mediaConstraints ); - } - -const okay = async () => { - - console.log("ADDING TRACKS"); - localMediaStream.current.getTracks().forEach((track) => { - peer.current.addTrack( track, localMediaStream.current ) - console.log("TRACK ADDED!!!!"); - }); -}; - - - const start = async () => { - let sessionConstraints = { - mandatory: { - OfferToReceiveAudio: false, - OfferToReceiveVideo: true, - VoiceActivityDetection: false, - } - }; - - const offer = await peer.current.createOffer( sessionConstraints ); - await peer.current.setLocalDescription( offer ); - ws.current.send(JSON.stringify({ offer })); - }; const logout = async () => { Alert.alert( @@ -293,22 +131,104 @@ const okay = async () => { return ( - - SEND - + + + + + + + + + + + { state.disconnected && ( + Disconnected + )} + + + + { state.name && ( + { state.name } + )} + { !state.name && ( + Name + )} + + + + + + + { state.location && ( + { state.location } + )} + { !state.location && ( + Location + )} + + + + + + { state.description && ( + { state.description } + )} + { !state.description && ( + Description + )} + + + + + + setVisible(!state.searchable)} activeOpacity={1}> + Visible in Registry + + + + + setNotifications(!state.pushEnabled)} activeOpacity={1}> + Enable Notifications + + + + - - START - + + + Logout + - + + + Change Login + + + { state.sealable && ( + + + Sealed Topics + + )} + + + + Delete Account + + + Manage Blocked: + + + Contacts + + + Topics + + + Messages + + { - const canvas = Object.assign(document.createElement("canvas"), {width: 320, height: 240}); - const ctx = canvas.getContext('2d'); - ctx.fillRect(0, 0, 320, 240); - const p = ctx.getImageData(0, 0, 320, 240); - requestAnimationFrame(function draw(){ - for (var i = 0; i < p.data.length; i++) { - p.data[i++] = p.data[i++] = p.data[i++] = Math.random() * 255; - } - ctx.putImageData(p, 0, 0); - requestAnimationFrame(draw); - }); - return canvas.captureStream(); - } - - const start = async () => { - const stream = await navigator.mediaDevices.getUserMedia({video: true}); - //const stream = await whiteNoise(); - peer.current.addTransceiver(stream.getTracks()[0], {streams: [stream]}); - }; - - const rtc = async () => { - const iceServers = [ - { - urls: 'stun:192.168.13.233:5001?transport=udp', - username: 'user', - credential: 'pass' - }, - { - urls: 'turn:192.168.13.233:5001?transport=udp', - username: 'user', - credential: 'pass' - }]; - - const pc = new RTCPeerConnection({ - iceServers - }); - - //const pc = new RTCPeerConnection(); - peer.current = pc; - - pc.onicecandidate = (e) => { - if (!e.candidate) return; - - ws.current.send(JSON.stringify({ candidate: e.candidate })); - console.log(JSON.stringify(e.candidate)); - - // If a srflx candidate was found, notify that the STUN server works! - if(e.candidate.type == "srflx"){ - console.log("The STUN server is reachable!"); - console.log(` Your Public IP Address is: ${e.candidate.address}`); - } - - // If a relay candidate was found, notify that the TURN server works! - if(e.candidate.type == "relay"){ - console.log("The TURN server is reachable !"); - } - }; - - pc.onicecandidateerror = (e) => { - console.error(e); - }; - - pc.ontrack = ({streams: [stream]}) => { - console.log("ON TRACK!"); - vid.current.srcObject = stream; - }; - - - const dc = pc.createDataChannel("both", {negotiated: true, id: 0}); - - pc.onnegotiationneeded = async () => { - console.log("NEGOTIATION"); - create(); - }; - - } - - const create = async () => { - const offer = await peer.current.createOffer(); - await peer.current.setLocalDescription(offer); - ws.current.send(JSON.stringify({ offer: offer })); - console.log(":: OFFER: ", offer); - } - - useEffect(() => { - rtc(); - ws.current = new WebSocket('wss://balzack.coredb.org/relay'); - ws.current.onmessage = async (ev) => { - const msg = JSON.parse(ev.data); - if (msg.candidate) { - console.log("> CANDIDATE: ", msg.candidate); - candidates.current.push(msg.candidate); - await peer.current.addIceCandidate(msg.candidate); - } - else if (msg.offer) { - console.log("> OFFER: ", msg.offer); - peer.current.setRemoteDescription(msg.offer); - await peer.current.setLocalDescription(await peer.current.createAnswer()); - ws.current.send(JSON.stringify({ answer: peer.current.localDescription })); - } - else if (msg.answer) { - console.log("> ANSWER: ", msg.answer); - peer.current.setRemoteDescription(msg.answer); - } - } - ws.current.onclose = (e) => { - console.log("CLOSED"); - } - ws.current.onopen = () => { - console.log("OPENED"); - } - ws.current.error = (e) => { - console.log("ERROR"); - } - - }, []); - return (
Databag
Communication for the decentralized web
- -
-
- -
Create
-
Start
- + Session Background
Setup your profile
@@ -160,3 +25,4 @@ export function Welcome() { ); } +