btford / angular-socket-io

Socket.IO component for AngularJS
1.51k stars 233 forks source link

Can't get it to work #135

Closed RayKahn closed 8 years ago

RayKahn commented 8 years ago

Hi, I have the following declarations in my app.js file: (function () { angular.module('medmart', [ 'ui.router',
'oc.lazyLoad', 'ui.bootstrap', 'ngFileUpload', 'ui.validate', 'btford.socket-io', ]). factory('mySocket', function (socketFactory) { var mySocket = socketFactory({ prefix: 'medmart~', ioSocket: io.connect('https://:::8443'), }); mySocket.forward('error'); return mySocket; }); })();

And in my index.html I have the following statements:

<script src="js/angular/angular.min.js"></script> <script src="js/plugins/oclazyload/dist/ocLazyLoad.min.js"></script> <script src="js/ui-router/angular-ui-router.min.js"></script> <script src="js/bootstrap/ui-bootstrap-tpls-0.12.0.min.js"></script> <script src="js/plugins/ng-file-upload/ng-file-upload.min.js"></script>
<script src="/socket.io/socket.io.js"></script> <script src="js/plugins/angular-socket-io/socket.js"></script>

And in controlers.js I have the following:

function MainCtrl($scope, $rootScope, $http, mySocket) {

mySocket.forward('medmart~procedure', $scope); . . . mySocket.on('connect', function () { console.log("connected..."); $scope.$on('socket:error', function (ev, data) { console.log("ERROR: " + data) }); $scope.$on('medmart~procedure', function(event, data) { console.log("in medmart:procedure" + data); if (!data.payload) { return; } $scope.$apply(function() { //my code }); }); });

In my routs.js (Node.js) I am sending the following: socket.emit('medmart~procedure', procedure);

However, I am not able to receive any messages in my controller. Can some one tell me what am I doing wrong?

Thanks in advance.

RayKahn commented 8 years ago

Issue resolved. Looked at https://github.com/btford/angular-socket-io-im to figure out what I was doing wrong.