Comments (5)
Hi @billyshena did you find any answers to your question? Have you tried posting in one of the other forums?
Contribution Guide | Stackoverflow | Google Group | Trello | IRC | Build Status
from angularsails.
Anyone found a solution for initializing the socket in angular? pretty much the same situation as @billyshena. trying to manually initialize the socket after the user has authenticated so I can attach a query string to io.connect. regards.
from angularsails.
i make some fixes for this problem, because i have a same))
this version a i dont checked - i change my code for requirejs, but this two methods - like me
<+>UTF-8
===================================================================
--- assets/common/factories/test.js (date 1419454510000)
+++ assets/common/factories/test.js (revision )
@@ -721,8 +721,10 @@
// if we won't have the response in cache, send the request to the backend
if (angular.isUndefined(cachedResp)) {
- $sailsSocketBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
+ $sailsSocketBackend.then(function (backend) {
+ backend(config.method, url, reqData, done, reqHeaders, config.timeout,
- config.withCredentials, config.responseType);
+ config.withCredentials, config.responseType);
+ });
}
return promise;
@@ -817,8 +819,9 @@
if(!$window.io.socket){
console.warn('no connected socket...')
}
+ var defered = $q.defer();
+ var socket = $window.io.connect();
-
var tick = function (socket, callback) {
return callback ? function () {
var args = arguments;
@@ -843,16 +846,20 @@
url = url || $browser.url();
- $window.io.socket[method.toLowerCase()](url,fromJson(post),socketResponse);
+ socket[method.toLowerCase()](url,fromJson(post),socketResponse);
}
//TODO normalize http paths to event names
connection.subscribe = function(event,handler){
- $window.io.socket.on(event,tick($window.io.socket,handler));
+ socket.on(event,tick(socket,handler));
}
- return connection;
+ socket.on('connect', function () {
+ defered.resolve(connection);
+ });
+
+ return defered.promise;
}
\ No newline at end of file
from angularsails.
now when you first make request with $sailsSocket
he make connect function and whet socket.io emit connect event - return connection to main code
from angularsails.
I run an application into the similar problem. My solution is to configure autoConnect = false and decorate $sailsSocketBackend to return promise for connection ready so that it spares the time for sails.io.js to delete io.socket, assign io.socket once backend is ready, and at last $sailsSocket would raise the request after the backend is ready.
<script type="text/javascript" src="./path/to/bower_components/sails.io.js"></script>
<script type="text/javascript">
io.sails.autoConnect = false;
</script>
angular.module('starter', [...])
.config ($provide) ->
$provide.decorator '$sailsSocketBackend', ($delegate, $log) ->
# socket connect
io.sails.url = env.server.app.urlRoot
io.sails.path = "#{env.path}/socket.io"
io.sails.useCORSRouteToGetCookie = false
socket = null
p = new Promise (fulfill, reject) ->
socket = io.sails.connect()
socket.on 'connect', ->
fulfill()
socket.on 'connect_error', ->
reject()
socket.on 'connect_timeout', ->
reject()
(method, url, post, callback, headers, timeout, withCredentials, responseType) ->
p
.then ->
io.socket = socket
opts =
method: method.toLowerCase()
url: url
data: if typeof post == 'string' then JSON.parse(post) else post
headers: headers
socket.request opts, (body, jwr) ->
callback jwr.statusCode, body
.catch $log.error
from angularsails.
Related Issues (20)
- No way to unsubscribe HOT 2
- Incompatibility with stable (0.10.5) version of sails? HOT 2
- what is the replacement for $sailsSocket.subscribe?
- Query params not functioning properly with sailsSocket request
- npm publish this please! HOT 2
- BLOCKER: TypeError: Cannot read property 'connected' of undefined
- _socketDefaults unused
- $sailsSocket .get is not a function HOT 1
- change in bower.json to report support for angular 1.4 HOT 3
- Missing a ) in dist/ngsails.io.js HOT 1
- "main": "index.js" in package.json does not exist HOT 2
- Publish 0.11.5 please! HOT 2
- $sailsSocket.get is not a function HOT 4
- Remove sails.io dependency
- $sailsSocket() error on get method HOT 1
- .put() shortcut is not defined HOT 1
- Adjusment for unsubscribing HOT 4
- Correct way injecting angularSails? HOT 1
- Support for Angular 2
- server error 500 req.isAuthenticated is not a function HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angularsails.