socket: SocketIOClient.Socket;
subscribeToSocket() {
this.socket = io("http://13.232.53.10:3000", {
"transports": ["polling", "websocket"]
});
this.socket.on("sync", (data) => {
console.log("sync event fired, syncing numbers")
if (data.uniqueId != CobrowsingformComponent.uniqueId) {
CobrowsingformComponent.prevSequenceNumberReceived = data.nextSequenceNumber - 10;
private fb: FormBuilder;
initializeForm() {
this.validateForm = this.fb.group({
accountNumber: [null, [ Validators.required]],
firstName: [null, [Validators.required]],
middleName: [null],
lastName: [null, [Validators.required]],
/** Initializing all forms and socket to handle changes to form, Our current focus is on this.watchForChange*/
ngOnInit(): void {
this.userType = "";
CobrowsingformComponent.uniqueId = this.cobrowsingService.getUniqueId();
CobrowsingformComponent.mysequenceNumber = parseInt(this.cobrowsingService.getSequenceNumber());
this.initLoginForm();
this.initializeForm();
this.watchForChange();
}
handleData(data: any) {
if(data.uniqueId === CobrowsingformComponent.uniqueId) {
console.log("same id returning", CobrowsingformComponent.uniqueId, data.uniqueId)
return;
}
if(CobrowsingformComponent.prevSequenceNumberReceived >= data.nextsequenceNumber) {
return;
}
watchForChange() {
this.validateForm.valueChanges.subscribe(change=>{
CobrowsingformComponent.mysequenceNumber = CobrowsingformComponent.mysequenceNumber+10;
const msg = {
nextsequenceNumber: CobrowsingformComponent.mysequenceNumber,
uniqueId: CobrowsingformComponent.uniqueId,
change
}
let pokemonBall = function() {
console.log(this.name, this.powers)
}
pokemonBall()
What will be the output of the above function. undefined!
But what if we had a pokemon, with a real name and powers!. So lets go ahead and catch a pokemon. But how do we do that?
Please go through the post of bind before proceeding, this article will make much more sense. The difference between bind and apply is apply doesnot return a new function, it instantly calls the function that is being bounded to the object.
Here is the object we will be using for demonstrating the use of apply
var object = {
firstName: "pika",
lastName: "chu",
Promises give you hope of your wishes being granted somewhere in the future. Everyone has been promised by someone at some point in their life, and that's a sure thing. The only problem is promises aren't always fulfilled.
We make promises when we claim to do something in the future and javascript promises are the same. Promises always result in fulfillment or rejection. Enough talk, lets begin coding.
let mommysPromise = new Promise((resolve, reject)=>{
setTimeout(()=>resolve("Buys a birthday present!"), 2000)
switch (data.type) { | |
case 'offer': | |
// Doctor will initiate the offer | |
// console.log('msg received', Object.keys(this.connections), data, connection.userData); | |
// if UserB exists then send him offer detail | |
// TODO: if patient has joined then send the offer. else send message that patient not available | |
// to check patient has joined | |
// get oversides connection | |
if (aptData && aptData.userConnectionId) { | |
// get connectionId of patient and send offer |