I saw a tutorial where they do a chat with socket and ionic I tried to do but with a url of my api rest when running it I get this, can you please tell me the correct way to use it correctly?
import { DetallesPedidosPage } from './../detalles-pedidos/detalles-pedidos';
import { LoginProvider } from './../../providers/login/login';
import { ConexionesProvider } from './../../providers/conexiones/conexiones';
import { LocalizacionProvider } from './../../providers/localizacion/localizacion';
import { Http } from '@angular/http';
import { Component,ViewChild,NgZone } from '@angular/core';
import { NavController ,NavParams,Content} from 'ionic-angular';
import { AngularFireDatabaseModule,AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/database';
import * as io from 'socket.io-client';
import { URL_SERVICIOS } from "../../config/url.servicios";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
@ViewChild(Content) content:Content;
domiciliario:FirebaseObjectObservable<any[]>;
usuario:string='carlos'
lat= this._G.lat;
lng=this._G.long;
detalles= DetallesPedidosPage;
// nombre:any;
// token:any;
// id:any;
/*--------------------------------*/
resultado:any[]=[]
constructor( public http: Http,public navParams: NavParams,public navCtrl: NavController ,public db:AngularFireDatabase,public _G:LocalizacionProvider,public _CO:ConexionesProvider) {
this._G.iniciar_localizacion();
this.Pmensajero();
}
Pmensajero(){
let url = `${ URL_SERVICIOS }/pmensajero/${this._CO.token}/${this._CO.id}`;
// let url = URL_SERVICIOS+'/pmensajero/'+this.mensajero;
this.http.get(url).map(res=>res.json()).subscribe(resp=>{
if(resp.error){
}else{
this.resultado = resp.ordenes
/*----------socket------------*/
let socket:any;
let socketHost:string=URL_SERVICIOS;
socket = io.connect(socketHost)
socket.on("nuevo pedido",(msg)=>{
})
socket.emit('resultado',this.resultado);
/*---------------fin de socket--------------------*/
console.log(this.resultado)
}
})
}
}
orry I’m translating and it does not translate well, when I say that it works for me is that lapirest only that socket does not work for me and I do not know what the reason is
Yeah. By default your root accesses /socket.io/ as I said was correct. Make sure the script src is in your index.html to /socket.io/socket.io.js then it should work locally. Like I said, worry about your API after you have your server/client locally connecting.