Previously, I placed one-time listeners inside the resolve
. The code snippet below ensures that the page must receive a message of yes
to resolve x
, followed by "yes again" to resolve y
, and so on:
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('edit', {
resolve: {
x: ['$q', function ($q) {
var deferred = $q.defer();
$window.addEventListener("message", function (e) {
if (e.data === "yes") deferred.resolve(e.data)
}, { once: true };
return deferred.promise
}],
y: ... ...
if (e.data === "yes again") deferred.resolve(e.data)
... ...
return deferred.promise
}],
z: ... ...
return deferred.promise
Now, I am considering using socket.io
to handle these listeners; it listens for messages emitted by the server. If not within a resolve
, receiving messages can be done by:
var socket = io.connect();
socket.on('message', function (message) {
console.log(message)
})
I would like to assign one socket
per page. Is there a way to incorporate this into multiple resolve
functions to achieve similar functionality as the event listeners?