func (c *serverConn) OnPacket(r *parser.PacketDecoder) { if s := c.getState(); s != stateNormal && s != stateUpgrading { return } switch r.Type() { case parser.OPEN: case parser.CLOSE: c.getCurrent().Close() case parser.PING: t := c.getCurrent() u := c.getUpgrade() newWriter := t.NextWriter if u != nil { if w, _ := t.NextWriter(message.MessageText, parser.NOOP); w != nil { w.Close() } newWriter = u.NextWriter } if w, _ := newWriter(message.MessageText, parser.PONG); w != nil { io.Copy(w, r) w.Close() } fallthrough case parser.PONG: c.pingChan <- true case parser.MESSAGE: closeChan := make(chan struct{}) c.readerChan <- newConnReader(r, closeChan) <-closeChan close(closeChan) r.Close() case parser.UPGRADE: c.upgraded() case parser.NOOP: } }
func (f *fakeCallback) OnPacket(r *parser.PacketDecoder) { f.packetType = r.Type() f.messageType = r.MessageType() f.body, f.err = ioutil.ReadAll(r) f.onPacket <- true }