| 1126 | |
| 1127 | util.inherits(MpdProtocol, Duplex); |
| 1128 | function MpdProtocol(options) { |
| 1129 | var streamOptions = extend(extend({}, options.streamOptions || {}), {decodeStrings: false}); |
| 1130 | Duplex.call(this, streamOptions); |
| 1131 | this.player = options.player; |
| 1132 | this.apiServer = options.apiServer; |
| 1133 | this.playerServer = options.playerServer; |
| 1134 | |
| 1135 | this.closed = false; |
| 1136 | this.buffer = ""; |
| 1137 | this.bufferIndex = 0; |
| 1138 | this.cmdListState = CMD_LIST_STATE_NONE; |
| 1139 | this.cmdList = []; |
| 1140 | this.okMode = false; |
| 1141 | this.isIdle = false; |
| 1142 | this.commandQueue = []; |
| 1143 | this.ongoingCommand = false; |
| 1144 | this.grooveBasinProtocol = new GrooveBasinProtocol(options); |
| 1145 | this.updatedSubsystems = { |
| 1146 | database: false, |
| 1147 | update: false, |
| 1148 | stored_playlist: false, |
| 1149 | playlist: false, |
| 1150 | player: false, |
| 1151 | mixer: false, |
| 1152 | output: false, |
| 1153 | options: false, |
| 1154 | sticker: false, |
| 1155 | subscription: false, |
| 1156 | message: false, |
| 1157 | }; |
| 1158 | this._read = mpdRead; |
| 1159 | this._write = mpdWrite; |
| 1160 | |
| 1161 | this.mpdTransport = new EventEmitter(); |
| 1162 | this.mpdTransport.sendMessage = noop; |
| 1163 | this.client = this.playerServer.createClient(this.mpdTransport, "MPD-Guest"); |
| 1164 | this.id = uuid(); |
| 1165 | this.apiServer.handleNewClient(this); |
| 1166 | |
| 1167 | this.push("OK MPD 0.19.0\n"); |
| 1168 | } |
| 1169 | |
| 1170 | MpdProtocol.prototype.close = function() { |
| 1171 | if (this.closed) return; |