Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3248989
D9607.id32626.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D9607.id32626.diff
View Options
diff --git a/lib/facts/tunnelbroker.js b/lib/facts/tunnelbroker.js
new file mode 100644
--- /dev/null
+++ b/lib/facts/tunnelbroker.js
@@ -0,0 +1,9 @@
+// @flow
+
+import { isDev } from '../utils/dev-utils.js';
+
+const tunnnelbrokerURL: string = isDev
+ ? 'ws://localhost:51001'
+ : 'https://tunnelbroker.commtechnologies.org';
+
+export { tunnnelbrokerURL };
diff --git a/lib/tunnelbroker/tunnelbroker-context.js b/lib/tunnelbroker/tunnelbroker-context.js
--- a/lib/tunnelbroker/tunnelbroker-context.js
+++ b/lib/tunnelbroker/tunnelbroker-context.js
@@ -3,6 +3,7 @@
import invariant from 'invariant';
import * as React from 'react';
+import { tunnnelbrokerURL } from '../facts/tunnelbroker.js';
import { type TunnelbrokerMessage } from '../types/tunnelbroker/messages.js';
import type { ConnectionInitializationMessage } from '../types/tunnelbroker/session-types.js';
@@ -31,9 +32,35 @@
};
function TunnelbrokerProvider(props: Props): React.Node {
- const { children } = props;
- const [connected] = React.useState(false);
+ const { children, initMessage } = props;
+ const [connected, setConnected] = React.useState(false);
const listeners = React.useRef<Set<TunnelbrokerSocketListener>>(new Set());
+ const socket = React.useRef<?WebSocket>(null);
+
+ React.useEffect(() => {
+ if (connected || !initMessage) {
+ return;
+ }
+
+ const tunnelbrokerSocket = new WebSocket(tunnnelbrokerURL);
+
+ tunnelbrokerSocket.onopen = () => {
+ tunnelbrokerSocket.send(JSON.stringify(initMessage));
+ };
+
+ tunnelbrokerSocket.onclose = () => {
+ setConnected(false);
+ console.error('Connection to Tunnelbroker closed');
+ };
+ tunnelbrokerSocket.onerror = e => {
+ console.error('Tunnelbroker socket error:', e.message);
+ };
+ tunnelbrokerSocket.onmessage = (event: MessageEvent) => {
+ console.log('Received message:', event.data);
+ };
+
+ socket.current = tunnelbrokerSocket;
+ }, [connected, initMessage]);
const sendMessage: () => Promise<void> = React.useCallback(() => {
return new Promise(() => {});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 16, 11:45 AM (12 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2497697
Default Alt Text
D9607.id32626.diff (2 KB)
Attached To
Mode
D9607: [lib] implement creating Tunnelbroker socket
Attached
Detach File
Event Timeline
Log In to Comment