func (p *PeerConnWebSocket) Send(ctx context.Context, msg *Message, moreMsgs ...*Message) error {
	// If there are more, send all as an array of JSON strings, otherwise just the msg
	var toWrite interface{}
	if len(moreMsgs) == 0 {
		toWrite = msg
	} else {
		b, err := json.Marshal(msg)
		if err != nil {
			return err
		}
		msgs := []string{string(b)}
		for _, nextMsg := range moreMsgs {
			if b, err = json.Marshal(nextMsg); err != nil {
				return err
			}
			msgs = append(msgs, string(b))
		}
		toWrite = msgs
	}
	// Send async so we can wait on context
	errCh := make(chan error, 1)
	go func() {
		p.WriteLock.Lock()
		defer p.WriteLock.Unlock()
		errCh <- p.Underlying.WriteJSON(toWrite)
	}()
	select {
	case err := <-errCh:
		return err
	case <-ctx.Done():
		return ctx.Err()
	}
}
// Send implements PeerConn.Send.
Send implements PeerConn.Send.
// Send implements PeerConn . Send .
func (p *PeerConnWebSocket) Send(ctx context.Context, msg *Message, moreMsgs ...*Message) error {
	var toWrite interface{}
	if len(moreMsgs) == 0 {
		toWrite = msg
	} else {
		b, err := json.Marshal(msg)
		if err != nil {
			return err
		}
		msgs := []string{string(b)}
		for _, nextMsg := range moreMsgs {
			if b, err = json.Marshal(nextMsg); err != nil {
				return err
			}
			msgs = append(msgs, string(b))
		}
		toWrite = msgs
	}
	errCh := make(chan error, 1)
	go func() {
		p.WriteLock.Lock()
		defer p.WriteLock.Unlock()
		errCh <- p.Underlying.WriteJSON(toWrite)
	}()
	select {
	case err := <-errCh:
		return err
	case <-ctx.Done():
		return ctx.Err()
	}
}
func ( p * PeerConnWebSocket ) Send ( ctx context . Context , msg * Message , moreMsgs ... * Message ) error { var toWrite interface { } if len ( moreMsgs ) == 0 { toWrite = msg } else { b , err := json . Marshal ( msg ) if err != nil { return err } msgs := [ ] string { string ( b ) } for _ , nextMsg := range moreMsgs { if b , err = json . Marshal ( nextMsg ) ; err != nil { return err } msgs = append ( msgs , string ( b ) ) } toWrite = msgs } errCh := make ( chan error , 1 ) go func ( ) { p . WriteLock . Lock ( ) defer p . WriteLock . Unlock ( ) errCh <- p . Underlying . WriteJSON ( toWrite ) } ( ) select { case err := <- errCh : return err case <- ctx . Done ( ) : return ctx . Err ( ) } }
Send implements PeerConn.Send.
Send implements PeerConn . Send .
// If there are more, send all as an array of JSON strings, otherwise just the msg // Send async so we can wait on context