Search Posts

Category: socket.io

$rootScope.$broadcast not working with angular-socket-io

I’m using angular-socket-io for client/server communication.I’m able to receive the data from the server.Below is my code socket.on(‘new_question’, function (event) { console.log(event) // I’m receiving the event $rootScope.$broadcast(‘received_new_question’,event); //this is not working }); //listen to the event $scope.$on(‘received_new_question’,function(event){ console.log(event); //not working }) At first I tried $scope.$apply() but that didn’t work.So I tried to broadcast this event so that the data can be attached into the controller and I can render it in the views.But […]

How to initiate websocket connection when user logged in and unsubscribe them when logged out in Angularjs 1.x web app [on hold]

Currently, I am using Angularjs 1.5. I need to subscribe to websocket topics when user logged in and unsubscribe them when user logged out in angularjs.. And need to handle page refresh, subscribe to topics when user is already logged in. Not sure where to write this logic.. app.run(()=>{}) ? Source: AngularJS

Socket.io – GET http://localhost:2017/socket.io/?EIO=3&transport=polling&t=MCvaSKo 0 ()

I’m running AngularJS application with backend as node.js. In this application socket.io used to communicate with node API. But I got GET http://localhost:2017/socket.io/?EIO=3&transport=polling&t=MCvaSKo 0 () error when I’m running application. due to this error I cant send data from angularJS to node API. How could I resolve this error? Can anyone help? Thanks in advance. Source: AngularJS

AngularJS Socketio factory error i cant fix

My Factory angular.module(‘myApp’) .factory(‘socketFac’,function($rootscope) { var socket = io.connect(); return { on: function (eventName, callback) { socket.on(eventName, function () { var args = arguments; $rootScope.$apply(function () { callback.apply(socket, args); }); }); }, emit: function (eventName, data, callback) { socket.emit(eventName, data, function () { var args = arguments; $rootScope.$apply(function () { if (callback) { callback.apply(socket, args); } }); }) } }; }); My App angular.module(‘myApp’, [ ‘ngRoute’, ‘appRoutes’, ‘anasayfaCtrl’, ‘girisCtrl’, ‘kayitCtrl’, ‘indexCtrl’, ‘btcCtrl’, ‘ltcCtrl’, ‘bchCtrl’, ‘profilCtrl’, […]

Realtime web notification by using angular and php

I need Realtime web notification by using angular and php without nodejs. I am getting codes all with node support. Pusher have using node and in firebase I am not getting token. Can i achieve this without node js. Socket.io is using node. Can i use socket.io for this. Web socket is working localhost. but i do not know how to run server file in live server. Source: AngularJS

Angular 4 – ERROR TypeError: Cannot read property ‘push’ of undefined

this is my component code. and i am using socket.on to get data from node server and then want to push that into a Typescript array. its showing error on push function. actually list array is undefined at this point. import { Component } from ‘@angular/core’; import * as io from ‘socket.io-client’; @Component({ selector: ‘app-admin’, templateUrl: ‘./admin.component.html’, styleUrls: [‘./admin.component.css’] }) export class AdminComponent{ private socket: io.Socket; private list: any[]; constructor() { this.socket = io(‘wss://ngrk-buzzer-app.herokuapp.com’); this.socket.on(‘message’, […]

Angular 1.6.9 and socket.io chat application

The following code I have developed so far for a chat application using Angular and Socket.io. The crucial part that I can’t seem to fix is the “nickWrap”. It consists of a message ‘Enter Nickname’, an input text box and a submit button. The nickname is passed to the server where it checks in an array if the nickname is already present. If not then it should give back a success, then I should disable […]

$location.path(‘/home’) not working with socket.io

I am using express, node, angularJS as my stack, trying to incorporate socket.io emit event from server to client, which I can successfully do, when I angular js controllers do receive a message on the respective channel I am trying to navigate to for example $location.path(‘/home’) but it is not working no error is thrown as well. server side emit code: app.get(‘/api/students/id’, asyncMiddleware(async (req, res, next) => { const studentData = await getStudent(req.query.studentId); io.on(‘connection’, function(socket){ […]

Multiple socket connection, event listen not working in controller

how to Multiple socket connection, event listen not working in controller using angularjs socket factory. (btford-angular-socket-io). Using two servers “A” and “B”, when user selects value from dropdown i am using instance of socketA or socketB accordingly, unfortunately the only working socket is the one that was set on page load: My guess is that events in controller where attached on page load and were not reinitialized when socket was changed but not sure how […]

Next Page »