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

Method openSocket

lib/socket/socket.react.js:132–208  ·  view source on GitHub ↗
(newStatus: ConnectionStatus)

Source from the content-addressed store, hash-verified

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) {
176 this.onClose();
177 }
178 };
179 this.socket = socket;
180
181 void (async () => {
182 await sleep(clientRequestVisualTimeout);
183 if (this.socket !== socket || openObject.initializeMessageSent) {
184 return;
185 }
186 this.setLateResponse(-1, true);
187 await sleep(remainingTimeAfterVisualTimeout);
188 if (this.socket !== socket || openObject.initializeMessageSent) {
189 return;

Callers 4

finishClosingSocketMethod · 0.95
SocketClass · 0.95
componentDidMountMethod · 0.95
componentDidUpdateMethod · 0.95

Calls 5

markSocketInitializedMethod · 0.95
finishClosingSocketMethod · 0.95
closeMethod · 0.65
sleepFunction · 0.50
logMethod · 0.45

Tested by

no test coverage detected