mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
sending rings to requested clients
This commit is contained in:
parent
86497089e8
commit
479ce81b30
@ -113,7 +113,7 @@ func getRevision(account *store.Account) Activity {
|
|||||||
r.Card = account.CardRevision
|
r.Card = account.CardRevision
|
||||||
|
|
||||||
var a Activity
|
var a Activity
|
||||||
a.Revision = r
|
a.Revision = &r
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ func SetRing(card *store.Card, ring Ring) {
|
|||||||
phone.CalleeToken = ring.CalleeToken
|
phone.CalleeToken = ring.CalleeToken
|
||||||
phone.CardID = card.CardSlot.CardSlotID
|
phone.CardID = card.CardSlot.CardSlotID
|
||||||
var a Activity
|
var a Activity
|
||||||
a.Phone = phone;
|
a.Phone = ☎
|
||||||
msg, err := json.Marshal(a)
|
msg, err := json.Marshal(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrMsg(err);
|
ErrMsg(err);
|
||||||
|
@ -395,9 +395,9 @@ type ProfileData struct {
|
|||||||
|
|
||||||
//Activity listener for account
|
//Activity listener for account
|
||||||
type Activity struct {
|
type Activity struct {
|
||||||
Revision Revision `json:"revision,emitempty"`
|
Revision *Revision `json:"revision,emitempty"`
|
||||||
|
|
||||||
Phone Phone `json:"ring",omitempty"`
|
Phone *Phone `json:"ring",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//Revision revision of each account module
|
//Revision revision of each account module
|
||||||
|
@ -12,6 +12,7 @@ import { StoreContextProvider } from 'context/StoreContext';
|
|||||||
import { UploadContextProvider } from 'context/UploadContext';
|
import { UploadContextProvider } from 'context/UploadContext';
|
||||||
import { ViewportContextProvider } from 'context/ViewportContext';
|
import { ViewportContextProvider } from 'context/ViewportContext';
|
||||||
import { ConversationContextProvider } from 'context/ConversationContext';
|
import { ConversationContextProvider } from 'context/ConversationContext';
|
||||||
|
import { RingContextProvider } from 'context/RingContext';
|
||||||
|
|
||||||
import { AppWrapper } from 'App.styled';
|
import { AppWrapper } from 'App.styled';
|
||||||
import { Root } from './root/Root';
|
import { Root } from './root/Root';
|
||||||
@ -30,33 +31,35 @@ function App() {
|
|||||||
<ProfileContextProvider>
|
<ProfileContextProvider>
|
||||||
<StoreContextProvider>
|
<StoreContextProvider>
|
||||||
<AccountContextProvider>
|
<AccountContextProvider>
|
||||||
<ViewportContextProvider>
|
<RingContextProvider>
|
||||||
<AppContextProvider>
|
<ViewportContextProvider>
|
||||||
<AppWrapper>
|
<AppContextProvider>
|
||||||
<ConfigProvider theme={{ token: {
|
<AppWrapper>
|
||||||
colorPrimary: Colors.primary,
|
<ConfigProvider theme={{ token: {
|
||||||
colorLink: Colors.primary,
|
colorPrimary: Colors.primary,
|
||||||
colorLinkHover: Colors.background,
|
colorLink: Colors.primary,
|
||||||
} }}>
|
colorLinkHover: Colors.background,
|
||||||
<Router>
|
} }}>
|
||||||
<Routes>
|
<Router>
|
||||||
<Route path="/" element={ <Root /> } />
|
<Routes>
|
||||||
<Route path="/dashboard" element={ <Dashboard /> } />
|
<Route path="/" element={ <Root /> } />
|
||||||
<Route path="/admin" element={ <Access mode="admin" /> } />
|
<Route path="/dashboard" element={ <Dashboard /> } />
|
||||||
<Route path="/login" element={ <Access mode="login" /> } />
|
<Route path="/admin" element={ <Access mode="admin" /> } />
|
||||||
<Route path="/create" element={ <Access mode="create" /> } />
|
<Route path="/login" element={ <Access mode="login" /> } />
|
||||||
<Route path="/session" element={
|
<Route path="/create" element={ <Access mode="create" /> } />
|
||||||
<ConversationContextProvider>
|
<Route path="/session" element={
|
||||||
<Session />
|
<ConversationContextProvider>
|
||||||
</ConversationContextProvider>
|
<Session />
|
||||||
}>
|
</ConversationContextProvider>
|
||||||
</Route>
|
}>
|
||||||
</Routes>
|
</Route>
|
||||||
</Router>
|
</Routes>
|
||||||
</ConfigProvider>
|
</Router>
|
||||||
</AppWrapper>
|
</ConfigProvider>
|
||||||
</AppContextProvider>
|
</AppWrapper>
|
||||||
</ViewportContextProvider>
|
</AppContextProvider>
|
||||||
|
</ViewportContextProvider>
|
||||||
|
</RingContextProvider>
|
||||||
</AccountContextProvider>
|
</AccountContextProvider>
|
||||||
</StoreContextProvider>
|
</StoreContextProvider>
|
||||||
</ProfileContextProvider>
|
</ProfileContextProvider>
|
||||||
|
12
net/web/src/api/addContactRing.js
Normal file
12
net/web/src/api/addContactRing.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
|
export async function addContactRing(server, token, call) {
|
||||||
|
let host = "";
|
||||||
|
if (server) {
|
||||||
|
host = `https://${server}`
|
||||||
|
}
|
||||||
|
|
||||||
|
let ring = await fetchWithTimeout(`${host}/talk/ring?contact=${token}`, { method: 'POST', body: JSON.stringify(call) });
|
||||||
|
checkResponse(ring);
|
||||||
|
}
|
||||||
|
|
14
net/web/src/context/RingContext.js
Normal file
14
net/web/src/context/RingContext.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { createContext } from 'react';
|
||||||
|
import { useRingContext } from './useRingContext.hook';
|
||||||
|
|
||||||
|
export const RingContext = createContext({});
|
||||||
|
|
||||||
|
export function RingContextProvider({ children }) {
|
||||||
|
const { state, actions } = useRingContext();
|
||||||
|
return (
|
||||||
|
<RingContext.Provider value={{ state, actions }}>
|
||||||
|
{children}
|
||||||
|
</RingContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ import { CardContext } from './CardContext';
|
|||||||
import { ChannelContext } from './ChannelContext';
|
import { ChannelContext } from './ChannelContext';
|
||||||
import { StoreContext } from './StoreContext';
|
import { StoreContext } from './StoreContext';
|
||||||
import { UploadContext } from './UploadContext';
|
import { UploadContext } from './UploadContext';
|
||||||
|
import { RingContext } from './RingContext';
|
||||||
import { createWebsocket } from 'api/fetchUtil';
|
import { createWebsocket } from 'api/fetchUtil';
|
||||||
|
|
||||||
export function useAppContext(websocket) {
|
export function useAppContext(websocket) {
|
||||||
@ -30,6 +31,7 @@ export function useAppContext(websocket) {
|
|||||||
setState((s) => ({ ...s, ...value }))
|
setState((s) => ({ ...s, ...value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ringContext = useContext(RingContext);
|
||||||
const uploadContext = useContext(UploadContext);
|
const uploadContext = useContext(UploadContext);
|
||||||
const storeContext = useContext(StoreContext);
|
const storeContext = useContext(StoreContext);
|
||||||
const accountContext = useContext(AccountContext);
|
const accountContext = useContext(AccountContext);
|
||||||
@ -57,6 +59,7 @@ export function useAppContext(websocket) {
|
|||||||
const clearSession = () => {
|
const clearSession = () => {
|
||||||
uploadContext.actions.clear();
|
uploadContext.actions.clear();
|
||||||
storeContext.actions.clear();
|
storeContext.actions.clear();
|
||||||
|
ringContext.actions.clear();
|
||||||
|
|
||||||
accountContext.actions.clearToken();
|
accountContext.actions.clearToken();
|
||||||
profileContext.actions.clearToken();
|
profileContext.actions.clearToken();
|
||||||
@ -173,8 +176,14 @@ export function useAppContext(websocket) {
|
|||||||
let activity = JSON.parse(ev.data);
|
let activity = JSON.parse(ev.data);
|
||||||
updateState({ status: 'connected' });
|
updateState({ status: 'connected' });
|
||||||
if (activity.revision) {
|
if (activity.revision) {
|
||||||
|
console.log("GOR REVISION");
|
||||||
setAppRevision(activity.revision);
|
setAppRevision(activity.revision);
|
||||||
}
|
}
|
||||||
|
if (activity.ring) {
|
||||||
|
console.log("GOT PHONE!");
|
||||||
|
const { cardId, callId, calleeToken } = activity.ring;
|
||||||
|
ringContext.actions.ring(cardId, callId, calleeToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
60
net/web/src/context/useRingContext.hook.js
Normal file
60
net/web/src/context/useRingContext.hook.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import { useEffect, useContext, useState, useRef } from 'react';
|
||||||
|
|
||||||
|
export function useRingContext() {
|
||||||
|
const [state, setState] = useState({
|
||||||
|
ringing: new Map(),
|
||||||
|
});
|
||||||
|
const access = useRef(null);
|
||||||
|
|
||||||
|
const EXPIRE = 3000
|
||||||
|
const ringing = useRef(new Map());
|
||||||
|
|
||||||
|
const updateState = (value) => {
|
||||||
|
setState((s) => ({ ...s, ...value }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const actions = {
|
||||||
|
clear: () => {
|
||||||
|
ringing.current = new Map();
|
||||||
|
updateState({ ringing: ringing.current });
|
||||||
|
},
|
||||||
|
ring: (cardId, callId, calleeToken) => {
|
||||||
|
const key = `${cardId}:${callId}`
|
||||||
|
const call = ringing.current.get(key) || { calleeToken, callId }
|
||||||
|
call.expires = Date.now() + EXPIRE;
|
||||||
|
ringing.current.set(key, call);
|
||||||
|
updateState({ ringing: ringing.current });
|
||||||
|
},
|
||||||
|
ignore: (cardId, callId) => {
|
||||||
|
const key = `${cardId}:${callId}`
|
||||||
|
const call = ringing.current.get(key);
|
||||||
|
if (call) {
|
||||||
|
call.status = 'ignored'
|
||||||
|
ringing.current.set(key, call);
|
||||||
|
updateState({ ringing: ringing.current });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
decline: (cardId, callId) => {
|
||||||
|
const key = `${cardId}:${callId}`
|
||||||
|
const call = ringing.current.get(key);
|
||||||
|
if (call) {
|
||||||
|
call.status = 'declined'
|
||||||
|
ringing.current.set(key, call);
|
||||||
|
updateState({ ringing: ringing.current });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
accept: (cardId, callId) => {
|
||||||
|
const key = `${cardId}:${callId}`
|
||||||
|
const call = ringing.current.get(key);
|
||||||
|
if (call) {
|
||||||
|
call.status = 'accepted'
|
||||||
|
ringing.current.set(key, call);
|
||||||
|
updateState({ ringing: ringing.current });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return { state, actions }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -9,6 +9,10 @@ export function Contact({ close, guid, listing }) {
|
|||||||
const [ modal, modalContext ] = Modal.useModal();
|
const [ modal, modalContext ] = Modal.useModal();
|
||||||
const { state, actions } = useContact(guid, listing, close);
|
const { state, actions } = useContact(guid, listing, close);
|
||||||
|
|
||||||
|
const ring = async () => {
|
||||||
|
actions.ring();
|
||||||
|
};
|
||||||
|
|
||||||
const updateContact = async (action) => {
|
const updateContact = async (action) => {
|
||||||
try {
|
try {
|
||||||
await action();
|
await action();
|
||||||
@ -132,6 +136,9 @@ export function Contact({ close, guid, listing }) {
|
|||||||
<div className={ state.buttonStatus } onClick={() => updateContact(actions.saveConnect)}>Save and Request</div>
|
<div className={ state.buttonStatus } onClick={() => updateContact(actions.saveConnect)}>Save and Request</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div className={ state.buttonStatus } onClick={ring}>RING</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { CardContext } from 'context/CardContext';
|
|||||||
import { ViewportContext } from 'context/ViewportContext';
|
import { ViewportContext } from 'context/ViewportContext';
|
||||||
import { getListingMessage } from 'api/getListingMessage';
|
import { getListingMessage } from 'api/getListingMessage';
|
||||||
import { getCardByGuid } from 'context/cardUtil';
|
import { getCardByGuid } from 'context/cardUtil';
|
||||||
|
import { addContactRing } from 'api/addContactRing';
|
||||||
|
|
||||||
export function useContact(guid, listing, close) {
|
export function useContact(guid, listing, close) {
|
||||||
|
|
||||||
@ -155,6 +156,14 @@ export function useContact(guid, listing, close) {
|
|||||||
close();
|
close();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
ring: async () => {
|
||||||
|
console.log("ringing!!");
|
||||||
|
const contact = card.state.cards.get(state.cardId);
|
||||||
|
const { node, guid } = contact.data.cardProfile;
|
||||||
|
const { token } = contact.data.cardDetail;
|
||||||
|
await addContactRing(node, `${guid}.${token}`, { index: 0, callId: 'abc', calleeToken: '123' });
|
||||||
|
console.log(contact);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return { state, actions };
|
return { state, actions };
|
||||||
|
@ -5,6 +5,7 @@ import { CardContext } from 'context/CardContext';
|
|||||||
import { StoreContext } from 'context/StoreContext';
|
import { StoreContext } from 'context/StoreContext';
|
||||||
import { ViewportContext } from 'context/ViewportContext';
|
import { ViewportContext } from 'context/ViewportContext';
|
||||||
import { ProfileContext } from 'context/ProfileContext';
|
import { ProfileContext } from 'context/ProfileContext';
|
||||||
|
import { RingContext } from 'context/RingContext';
|
||||||
|
|
||||||
export function useSession() {
|
export function useSession() {
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ export function useSession() {
|
|||||||
const app = useContext(AppContext);
|
const app = useContext(AppContext);
|
||||||
const card = useContext(CardContext);
|
const card = useContext(CardContext);
|
||||||
const store = useContext(StoreContext);
|
const store = useContext(StoreContext);
|
||||||
|
const ring = useContext(RingContext);
|
||||||
const viewport = useContext(ViewportContext);
|
const viewport = useContext(ViewportContext);
|
||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
|
|
||||||
@ -39,6 +41,10 @@ export function useSession() {
|
|||||||
setState((s) => ({ ...s, ...value }));
|
setState((s) => ({ ...s, ...value }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(ring.state);
|
||||||
|
}, [ring.state]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!profile.state.identity?.guid) {
|
if (!profile.state.identity?.guid) {
|
||||||
updateState({ loading: true });
|
updateState({ loading: true });
|
||||||
|
Loading…
Reference in New Issue
Block a user