Skip to content

Instantly share code, notes, and snippets.

View cfsilence's full-sized avatar

Todd Sharp cfsilence

View GitHub Profile
this.currentChannel.on('messageAdded', (m) => {
this.messages.push(m);
const el = this.chatDisplay.nativeElement;
this.notifyMessage(m);
setTimeout( () => {
el.scrollTop = el.scrollHeight;
});
});
this.currentChannel.on('messageAdded', (m) => {
this.messages.push(m);
const el = this.chatDisplay.nativeElement;
this.notifyMessage(m);
setTimeout( () => {
el.scrollTop = el.scrollHeight;
});
});
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";
sendMessage() {
this.currentChannel.sendMessage(this.chatMessage);
this.chatMessage = null;
}
typing() {
this.currentChannel.typing();
}
leaveChannel() {
if( this.currentChannel ) {
return this.currentChannel.leave().then( (channel: Channel) => {
channel.removeAllListeners('messageAdded');
channel.removeAllListeners('typingStarted');
channel.removeAllListeners('typingEnded');
});
}
else {
return Promise.resolve();
createChannel() {
this.chatService.createChannel(`Channel ${this.channels.length+1}`);
return false;
}
getChannels() {
this.isGettingChannels = true;
this.chatService.getPublicChannels().then( (channels: any) => {
this.channelObj = channels;
this.channels = this.channelObj.items;
console.log(channels);
this.isGettingChannels = false;
});
}
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();
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 {