The original Etherpad (currently unmaintained) is itself an open source java+javascript based application. The team is now working on a pure javascript solution etherpad-lite which is much more modular. The latter should suffice for your needs.
If you need something more custom, both codemirror code editor, and prosemirror (by the same author) have support for collaborative editing. You may also want to look at ot.js, which is a more generic and lower level library for operational transformation. OT is a well studied problem for which numerous approaches exist.
An alternative to operational transformation is diffing and patching, which may be better suited (eg. if your input control is a complex widget and user interactions don't map as is to state change of the widget) or more bandwidth efficient (though it is also possible to compress ot change sequences before transmitting). Google has published a very good open source library for this, which is available in several languages.