This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.currentChannel.on('messageAdded', (m) => { | |
this.messages.push(m); | |
const el = this.chatDisplay.nativeElement; | |
this.notifyMessage(m); | |
setTimeout( () => { | |
el.scrollTop = el.scrollHeight; | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.currentChannel.on('messageAdded', (m) => { | |
this.messages.push(m); | |
const el = this.chatDisplay.nativeElement; | |
this.notifyMessage(m); | |
setTimeout( () => { | |
el.scrollTop = el.scrollHeight; | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; | |
import {ChatService} from "../../services/chat.service"; | |
import {AuthService} from "../../services/auth.service"; | |
import {Observable} from "rxjs/Observable"; | |
import {Channel} from "twilio-chat/lib/channel"; | |
import 'rxjs/add/observable/fromEvent'; | |
import "rxjs/Rx"; | |
import {Message} from "twilio-chat/lib/message"; | |
import {Member} from "twilio-chat/lib/member"; | |
import {Util} from "../../util/util"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sendMessage() { | |
this.currentChannel.sendMessage(this.chatMessage); | |
this.chatMessage = null; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typing() { | |
this.currentChannel.typing(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
leaveChannel() { | |
if( this.currentChannel ) { | |
return this.currentChannel.leave().then( (channel: Channel) => { | |
channel.removeAllListeners('messageAdded'); | |
channel.removeAllListeners('typingStarted'); | |
channel.removeAllListeners('typingEnded'); | |
}); | |
} | |
else { | |
return Promise.resolve(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createChannel() { | |
this.chatService.createChannel(`Channel ${this.channels.length+1}`); | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getChannels() { | |
this.isGettingChannels = true; | |
this.chatService.getPublicChannels().then( (channels: any) => { | |
this.channelObj = channels; | |
this.channels = this.channelObj.items; | |
console.log(channels); | |
this.isGettingChannels = false; | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit() { | |
this.isConnecting = true; | |
this.chatService.connect(localStorage.getItem('twackToken')); | |
this.conSub = this.chatService.chatConnectedEmitter.subscribe( () => { | |
this.isConnected = true; | |
this.isConnecting = false; | |
this.getChannels(); | |
this.chatService.chatClient.on('channelAdded', () => { | |
this.getChannels(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {EventEmitter, Injectable} from '@angular/core'; | |
import * as Twilio from 'twilio-chat'; | |
import Client from "twilio-chat"; | |
import {Util} from "../util/util"; | |
import {Channel} from "twilio-chat/lib/channel"; | |
import {Router} from "@angular/router"; | |
import {AuthService} from "./auth.service"; | |
@Injectable() | |
export class ChatService { |