| 131 | //--------------------------------------------------------- |
| 132 | |
| 133 | export class EveClient { |
| 134 | socket: WebSocket; |
| 135 | socketQueue: string[] = []; |
| 136 | localEve:boolean = false; |
| 137 | localControl:boolean = false; |
| 138 | showIDE:boolean = true; |
| 139 | ide:IDE; |
| 140 | worker: Worker; |
| 141 | |
| 142 | constructor(url?:string) { |
| 143 | let loc = url ? url : this.getUrl(); |
| 144 | |
| 145 | this.socket = new WebSocket(loc); |
| 146 | this.socket.onerror = (event) => { |
| 147 | this.onError(); |
| 148 | } |
| 149 | this.socket.onopen = (event) => { |
| 150 | this.onOpen(); |
| 151 | } |
| 152 | this.socket.onmessage = (event) => { |
| 153 | this.onMessage(event); |
| 154 | } |
| 155 | this.socket.onclose = (event) => { |
| 156 | this.onClose(); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | getUrl() { |
| 161 | let protocol = "ws://"; |
| 162 | if(location.protocol.indexOf("https") > -1) { |
| 163 | protocol = "wss://"; |
| 164 | } |
| 165 | return protocol + window.location.host +"/ws"; |
| 166 | } |
| 167 | |
| 168 | socketSend(message:string) { |
| 169 | if(this.socket && this.socket.readyState === 1) { |
| 170 | this.socket.send(message); |
| 171 | } else { |
| 172 | this.socketQueue.push(message); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | send(payload:{type: string, [attributes:string]: any}) { |
| 177 | let message = JSON.stringify(payload); |
| 178 | if(!this.localEve) { |
| 179 | this.socketSend(message); |
| 180 | } else { |
| 181 | this.worker.postMessage(message); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | sendControl(message:string) { |
| 186 | if(!this.localControl) { |
| 187 | this.socketSend(message); |
| 188 | } else { |
| 189 | // @TODO where do local control messages go? |
| 190 | } |
nothing calls this directly
no outgoing calls
no test coverage detected