(debug: boolean = false)
| 89 | } |
| 90 | |
| 91 | start_session(debug: boolean = false): void { |
| 92 | let that = this; |
| 93 | |
| 94 | this.set_ws_api(); |
| 95 | |
| 96 | this._session_create_ts = Date.now(); |
| 97 | this.debug = debug; |
| 98 | this.ws = new WebSocket(this.ws_api); |
| 99 | this.ws.onopen = () => { |
| 100 | safe_poprun_callbacks(this._session_create_callbacks, 'session_create_callback'); |
| 101 | }; |
| 102 | |
| 103 | this.ws.onclose = function (evt) { |
| 104 | if (!that._closed && that.webio_session_id != 'NEW') { // not receive `close_session` command && enabled reconnection |
| 105 | const session_create_interval = 5000; |
| 106 | if (Date.now() - that._session_create_ts > session_create_interval) |
| 107 | that.start_session(that.debug); |
| 108 | else |
| 109 | setTimeout(() => { |
| 110 | that.start_session(that.debug); |
| 111 | }, session_create_interval - Date.now() + that._session_create_ts); |
| 112 | } else { |
| 113 | that.close_session(); |
| 114 | } |
| 115 | }; |
| 116 | this.ws.onmessage = function (evt) { |
| 117 | let msg: Command = JSON.parse(evt.data); |
| 118 | if (debug) console.info('>>>', JSON.parse(evt.data)); |
| 119 | that._on_server_message(msg); |
| 120 | }; |
| 121 | } |
| 122 | |
| 123 | start_onprogress(onprogress?: (loaded: number, total: number) => void): void { |
| 124 | let total = this.ws.bufferedAmount; |
nothing calls this directly
no test coverage detected