(data: any)
| 59 | received has the same id |
| 60 | */ |
| 61 | send(data: any) { |
| 62 | // add _id to each message |
| 63 | const id = this.generateId(); |
| 64 | data._id = id; |
| 65 | |
| 66 | const promiseData = {} as PromiseData<void>; |
| 67 | promiseData.promise = new Promise<void>((resolve, reject) => { |
| 68 | promiseData.resolve = resolve; |
| 69 | promiseData.reject = reject; |
| 70 | }); |
| 71 | this.promises[id] = promiseData; |
| 72 | |
| 73 | const jsonData = JSON.stringify(data); |
| 74 | if (this.socket.readyState === this.socket.OPEN) { |
| 75 | this.socket.send(jsonData); |
| 76 | } else { |
| 77 | // if the WebSocket is not open yet, add the data to the queue |
| 78 | this.queue.push(jsonData); |
| 79 | } |
| 80 | // socket is not watched by cypress, so we need to |
| 81 | // create a timeout while we are using the socket so that protractor waits for it |
| 82 | const to = setTimeout(() => {}, 20000); |
| 83 | |
| 84 | return promiseData.promise.then(() => { |
| 85 | clearTimeout(to); |
| 86 | }); |
| 87 | } |
| 88 | |
| 89 | flush() { |
| 90 | // send all the data waiting in the queue |
no test coverage detected