josephg / ShareJS

Collaborative editing in any app
Other
4.97k stars 454 forks source link

Connecting to sharejs 0.7.0 #319

Open magnetic-pi opened 10 years ago

magnetic-pi commented 10 years ago

In version 0.6.3 it was possible to specify the server location of the sharejs server (ex: http://192.168.1.1:8000) like:

<script>
$(document).ready(function () {

  var $textarea = $('#textarea');
  var $textareaEditor = $('#textarea-editor');

var connection = sharejs.open('blag', 'text', 'http://192.168.1.1:8000/channel', function(error, doc) {
            if (error) {
                        console.log(error);
                 } else {
                       $textarea.disabled = false;
                     doc.attach_textarea($textarea[0]);
                 }
        });
});
</script> 

I cannot figure out how to specify the url of the server in 0.7.0:

 14 
 15 var elem = document.getElementById('pad');
 16 
 17 var s = new BCSocket(null, {reconnect: true});
 18 
 19 var sjs = new window.sharejs.Connection(s);
 20 
 21 var doc = sjs.get('users', 'seph');
 22 console.log(doc);
 23 doc.subscribe();
 24 
 25 doc.whenReady(function () {
 26   if (!doc.type) doc.create('text');
 27   if (doc.type && doc.type.name === 'text')
 28     doc.attachTextarea(elem);
 29 });

How can I specify the connection url like:

var s = new BCSocket('http://192.168.1.1:7007/channel', {reconnect: true});

or

var s = new BCSocket('http://192.168.1.1:7007/channel');

Neither of those worked.

sillyslux commented 9 years ago
var s = new BCSocket('http://myserver.lan:7007/channel', {reconnect: true});

works, if you enable CORS in browserChannel:

// webserver.use browserChannel {webserver, sessionTimeoutInterval:5000}, (client) ->
   webserver.use browserChannel {webserver, sessionTimeoutInterval:5000, cors:'*'}, (client) ->