MCPcopy Create free account
hub / github.com/CommE2E/comm / Socket

Class Socket

lib/socket/socket.react.js:118–832  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116 +inflightRequests: ?InflightRequests,
117};
118class Socket extends React.PureComponent<Props, State> {
119 state: State = {
120 inflightRequests: null,
121 };
122 socket: ?CommTransportLayer;
123 nextClientMessageID: number = 0;
124 listeners: Set<SocketListener> = new Set();
125 pingTimeoutID: ?TimeoutID;
126 messageLastReceived: ?number;
127 reopenConnectionAfterClosing: boolean = false;
128 initializedWithUserState: ?PreRequestUserState;
129 initFailureCount: number = 0;
130 fetchingPendingUpdates: boolean = false;
131
132 openSocket(newStatus: ConnectionStatus) {
133 if (
134 this.props.frozen ||
135 !this.props.cookie ||
136 !this.props.cookie.startsWith('user=')
137 ) {
138 return;
139 }
140 if (this.socket) {
141 const { status } = this.props.connection;
142 if (status === 'forcedDisconnecting') {
143 this.reopenConnectionAfterClosing = true;
144 return;
145 } else if (status === 'disconnecting' && this.socket.readyState === 1) {
146 this.markSocketInitialized();
147 return;
148 } else if (
149 status === 'connected' ||
150 status === 'connecting' ||
151 status === 'reconnecting'
152 ) {
153 return;
154 }
155 if (this.socket.readyState < 2) {
156 this.socket.close();
157 console.log(`this.socket seems open, but Redux thinks it's ${status}`);
158 }
159 }
160 this.props.dispatch({
161 type: updateConnectionStatusActionType,
162 payload: { status: newStatus, keyserverID: this.props.keyserverID },
163 });
164
165 const socket = this.props.openSocket();
166 const openObject: { initializeMessageSent?: true } = {};
167 socket.onopen = () => {
168 if (this.socket === socket) {
169 void this.initializeSocket();
170 openObject.initializeMessageSent = true;
171 }
172 };
173 socket.onmessage = this.receiveMessage;
174 socket.onclose = () => {
175 if (this.socket === socket) {

Callers

nothing calls this directly

Calls 15

openSocketMethod · 0.95
sendMessageMethod · 0.95
messageFromEventMethod · 0.95
resetPingMethod · 0.95
finishClosingSocketMethod · 0.95
stopPingMethod · 0.95
sendInitialMessageMethod · 0.95
fetchPendingUpdatesMethod · 0.95
listenerFunction · 0.85
rejectAllMethod · 0.80

Tested by

no test coverage detected