Adds some debugging to the websocket connections.

parent 37f51e35
......@@ -176,6 +176,7 @@ export class ConnectionService {
if (defaultSocket) {
this._socket = <Subject<IMessage>>defaultSocket.pipe(map((response: MessageEvent): IMessage => {
const parsedResponse = JSON.parse(response.data);
console.log('connectionservice - received message', parsedResponse);
this._websocketAvailable = true;
if (parsedResponse.payload && parsedResponse.payload.activeQuizzes) {
......
......@@ -23,21 +23,22 @@ export class WebsocketService {
} catch (e) {
return null;
}
const observable = Observable.create(
(obsvr: Observer<MessageEvent>) => {
socket.onmessage = obsvr.next.bind(obsvr);
socket.onerror = obsvr.error.bind(obsvr);
socket.onclose = obsvr.complete.bind(obsvr);
return socket;
},
);
const observable = Observable.create((obsvr: Observer<MessageEvent>) => {
socket.onmessage = obsvr.next.bind(obsvr);
socket.onerror = obsvr.error.bind(obsvr);
socket.onclose = obsvr.complete.bind(obsvr);
return socket;
});
const observer = {
next: (data: Object) => {
if (socket.readyState === WebSocket.OPEN) {
console.log('websocketservice - sending message', data);
socket.send(JSON.stringify(data));
} else if (socket.readyState === WebSocket.CONNECTING) {
console.log('websocketservice - waiting 500ms for connection');
setTimeout(() => (observer.next(data)), 500);
setTimeout(() => (
observer.next(data)
), 500);
}
},
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment