func (p *PeerConnWebSocket) Receive(ctx context.Context) ([]*Message, error) {
	bytsCh := make(chan []byte, 1)
	errCh := make(chan error, 1)
	go func() {
		if _, b, err := p.Underlying.ReadMessage(); err != nil {
			errCh <- err
		} else {
			bytsCh <- b
		}
	}()
	select {
	case err := <-errCh:
		return nil, err
	case <-ctx.Done():
		return nil, ctx.Err()
	case byts := <-bytsCh:
		// If it's a JSON array, it means it's an array of JSON strings, otherwise it's one message
		if byts[0] != '[' {
			var msg Message
			if err := json.Unmarshal(byts, &msg); err != nil {
				return nil, err
			}
			return []*Message{&msg}, nil
		}
		var jsonStrs []string
		if err := json.Unmarshal(byts, &jsonStrs); err != nil {
			return nil, err
		}
		msgs := make([]*Message, len(jsonStrs))
		for i, jsonStr := range jsonStrs {
			if err := json.Unmarshal([]byte(jsonStr), &(msgs[i])); err != nil {
				return nil, err
			}
		}
		return msgs, nil
	}
}
// Receive implements PeerConn.Receive.
Receive implements PeerConn.Receive.
// Receive implements PeerConn . Receive .
func (p *PeerConnWebSocket) Receive(ctx context.Context) ([]*Message, error) {
	bytsCh := make(chan []byte, 1)
	errCh := make(chan error, 1)
	go func() {
		if _, b, err := p.Underlying.ReadMessage(); err != nil {
			errCh <- err
		} else {
			bytsCh <- b
		}
	}()
	select {
	case err := <-errCh:
		return nil, err
	case <-ctx.Done():
		return nil, ctx.Err()
	case byts := <-bytsCh:
		if byts[0] != '[' {
			var msg Message
			if err := json.Unmarshal(byts, &msg); err != nil {
				return nil, err
			}
			return []*Message{&msg}, nil
		}
		var jsonStrs []string
		if err := json.Unmarshal(byts, &jsonStrs); err != nil {
			return nil, err
		}
		msgs := make([]*Message, len(jsonStrs))
		for i, jsonStr := range jsonStrs {
			if err := json.Unmarshal([]byte(jsonStr), &(msgs[i])); err != nil {
				return nil, err
			}
		}
		return msgs, nil
	}
}
func ( p * PeerConnWebSocket ) Receive ( ctx context . Context ) ( [ ] * Message , error ) { bytsCh := make ( chan [ ] byte , 1 ) errCh := make ( chan error , 1 ) go func ( ) { if _ , b , err := p . Underlying . ReadMessage ( ) ; err != nil { errCh <- err } else { bytsCh <- b } } ( ) select { case err := <- errCh : return nil , err case <- ctx . Done ( ) : return nil , ctx . Err ( ) case byts := <- bytsCh : if byts [ 0 ] != '[' { var msg Message if err := json . Unmarshal ( byts , & msg ) ; err != nil { return nil , err } return [ ] * Message { & msg } , nil } var jsonStrs [ ] string if err := json . Unmarshal ( byts , & jsonStrs ) ; err != nil { return nil , err } msgs := make ( [ ] * Message , len ( jsonStrs ) ) for i , jsonStr := range jsonStrs { if err := json . Unmarshal ( [ ] byte ( jsonStr ) , & ( msgs [ i ] ) ) ; err != nil { return nil , err } } return msgs , nil } }
Receive implements PeerConn.Receive.
Receive implements PeerConn . Receive .
// If it's a JSON array, it means it's an array of JSON strings, otherwise it's one message