* Parses the message and determines what action to take
(dataString: string)
| 89 | * Parses the message and determines what action to take |
| 90 | */ |
| 91 | public parseMessage(dataString: string) { |
| 92 | let dataPackage: CommDataPackage; |
| 93 | try { |
| 94 | dataPackage = JSON.parse(dataString); |
| 95 | } catch (error) { |
| 96 | // Ignore messages that aren't in the expected format |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | // If it came from myself, ignore it :) |
| 101 | if (!dataPackage) { |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | // If we specified a channel, then check it, if we didn't, then we ignore anything with one |
| 106 | if ((this.channel && (!dataPackage.channel || dataPackage.channel !== this.channel)) || |
| 107 | (!this.channel && dataPackage.channel)) { |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | try { |
| 112 | this.handleDataPackage(dataPackage); |
| 113 | } catch (e) { |
| 114 | if (this.communicatorErrorHandler) { |
| 115 | this.communicatorErrorHandler(e); |
| 116 | } else { |
| 117 | throw e; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Determines the correct way to handle the given data package. |
no test coverage detected