Skip to content
This repository was archived by the owner on Aug 13, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions sails.io.backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
if (socket) return;

if (Backbone.socket) {
socket = Backbone.socket;
socketSrc = '`Backbone.socket`';
socket = Backbone.io.socket;
socketSrc = '`Backbone.io.socket`';
}
else if (window.socket) {
socket = window.socket;
socketSrc = '`window.socket`';
else if (window.io.socket) {
socket = window.io.socket;
socketSrc = '`window.io.socket`';
}

// The first time a socket is acquired, bind comet listener
Expand All @@ -72,7 +72,7 @@
clearTimeout(socketTimer);

// Check if socket is connected (synchronous)
var socketIsConnected = socket.socket && socket.socket.connected;
var socketIsConnected = socket && socket.isConnected();


if (socketIsConnected) {
Expand All @@ -97,7 +97,7 @@
// 'but its `connected` property is still set to false.\n' +
// 'But maybe Socket.io just hasn\'t finished connecting yet?\n' +
// '\n' +
// 'You might check to be sure you\'re waiting for `socket.on(\'connect\')`\n' +
// 'You might check to be sure you\'re waiting for `io.socket.on(\'connect\')`\n' +
// 'before using sync methods on your Backbone models and collections.'
// );
}
Expand All @@ -114,7 +114,7 @@


var _attemptToAcquireSocket = function () {
if ( socket ) return;
if ( io.socket ) return;
attempts++;
_acquireSocket();
if (attempts >= maxAttempts) return;
Expand Down Expand Up @@ -144,7 +144,7 @@
* Let's start light and layer on additional functionality carefully.
*/
var _bindCometListener = function socketAcquiredForFirstTime () {
socket.on('message', function cometMessageReceived (message) {
io.socket.on('message', function cometMessageReceived (message) {
Backbone.trigger('comet', message);
});
};
Expand Down Expand Up @@ -179,7 +179,7 @@


// Handle missing socket
if (!socket) {
if (!io.socket) {
throw new Error(
'\n' +
'Backbone cannot find a suitable `socket` object.\n' +
Expand All @@ -193,7 +193,7 @@

// Ensures the socket is connected and able to communicate w/ the server.
//
var socketIsConnected = socket.socket && socket.socket.connected;
var socketIsConnected = io.socket && io.socket.isConnected();
if ( !socketIsConnected ) {

// If the socket is not connected, the request is queued
Expand Down Expand Up @@ -261,12 +261,18 @@
}


var requestOpts = {
method: verb,
url: url,
params: params,
headers: {}
};

// Send a simulated HTTP request to Sails via Socket.io
var simulatedXHR =
socket.request(url, params, function serverResponded ( response ) {
socket.request(requestOpts, function serverResponded ( response ) {
if (options.success) options.success(response);
}, verb);
});



Expand Down