Codox
Search…
CodeMirror
Enable real-time co-editing for CodeMirror 5

Overview

Add the Codox JavaScript library and css files:
1
<script src="https://cdn1.codox.io/lib/2.x/api/wave.client.js" type="text/javascript"></script>
Copied!
1
<link href="https://cdn1.codox.io/lib/2.x/css/wave.client.css" rel="stylesheet">
Copied!

JavaScript code

Add the following JavaScript block to your application to enable real-time co-editing for CodeMirror. Replace the apiKey field with your own, which you can get here.
1
let editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
2
lineNumbers: true
3
});
4
5
let codox = new Codox();
6
//Codox configuration
7
8
let config = {
9
"docId" : "mydoc",
10
"app" : "codemirror",
11
"editor" : editor,
12
"apiKey" : "9deed72a-0c3a-48f3-912f-87b5955efbbe",
13
"user" : {"name" : "Steve"}
14
};
15
16
//Start!
17
codox.start(config);
Copied!
The co-editing session will start inside the CodeMirror editor instance specified in the editorattribute.
Before invoking codox.init() the CodeMirror editor should be fully initialized. In the example code, we ensure that CodeMirror is initialized first by adding an initialized event hook to CodeMirror constructor.
The values for docIdandusername should come from your document management service. Codox expects docIdto be globally unique across your service.

Multiple Instances

Every co-editing session should have its distinct codox object. That means if you are running multiple instances of CodeMirror editor on the same page or with in the same application, there should be multiple instances of codox, one for each CodeMirror editor instance or document fragment (note: each document fragment should be uniquely identifiable).

Parameters

The config parameter is a JSON object with the following key-value pairs:

Summary

Key
Value
app
(required)
string
docId
(required)
string
user
(required)
object
apiKey
(required)
string
editor
(required)
CodeMirror
autoStart
(optional)
boolean
Additional configration paramaters can be found here

Description

app

string
The static string value 'codemirror'

docId

string
A unique identifier for the document. In a content management service, this could for example be the resource identifier for the document.

user

object
A user meta-data object.
Key
Value
name
(optional)
string
email
(optional)
string
avatar
(optional)
string
id
(optional)
string
For a content management service, this field should be set for each logged-in user based on their credentials. The value of user.name will be used to render the default text-based initials avatar. To create an image-based avatar, set user.avatar to the path of the image resource.

apiKey

string
The API key for the CodeMirror integration. You can obtain a key from your account.

editor

CodeMirror
A reference to a CodeMirror editor instance, in which the co-editing session should be bootstrapped.

autoStart (optional)

boolean
Set to true to start the co-editing session automatically on init(config). Set to false to initialize but delay start the co-editing (see the start() client API). Default setting is true.
Last modified 5mo ago