skygeario / chat-sdk-js Goto Github PK
View Code? Open in Web Editor NEWSkygear chat plugin SDK for JS
Home Page: http://skygear.io
License: Apache License 2.0
Skygear chat plugin SDK for JS
Home Page: http://skygear.io
License: Apache License 2.0
Be able to subscribe to conversation name, member and unread count changes.
import skygearChat from 'skygear-chat';
// http://stackoverflow.com/questions/36871299/how-to-extend-function-with-es6-classes
class ExtensibleFunction extends Function {
constructor(f) {
return Object.setPrototypeOf(f, new.target.prototype);
}
}
// TypingIndicator.js
export default class extends ExtensibleFunction {
constructor(conversation, debounceTime = 3000) {
super(() => {
if(this.debounceTimer) {
this.startTyping();
} else {
this.resetTimer();
}
});
this.conversation = conversation;
this.debounceTime = debounceTime;
this.debounceTimer = null;
}
startTyping() {
this.debounceTimer = setTimeout(
this.stopTyping,
this.debounceTime
);
skygearChat.sendTypingIndicator(
this.conversation, 'begin'
);
}
resetTimer() {
clearTimeout(this.debounceTimer);
this.debounceTimer = setTimeout(
this.stopTyping,
this.debounceTime
);
}
stopTyping() {
this.debounceTimer = null;
skygearChat.sendTypingIndicator(
this.conversation, 'finished'
);
}
}
import TypingIndicator from 'TypingIndicator.js';
const typing = new TypingIndicator(currentConversation);
<input type=text onChange=typing />
Platform: React-Native
import skygear from 'skygear/react-native';
import skygearChat from 'skygear-chat';
skygear.config({...}).then(() => {
skygearChat.createDirectConversation(...); // I would get api key not configured error here
});
I think the reason is that, skygear-chat
import skygear from 'skygear', while the app import skygear from 'skygear/react-native', so they are two separate skygear containers.
Good if we could include the Chat SDK as a minified external script through CDN.
Instead of sendTypingIndicator, we can just have a utility function to listen to any text input DOM element and watch it?
Would be related with UI Kit.
when createDirectConversation()
is called with one argument (the user), it throws "can't read property toJSON of undefined".
Workaround: createDirectConversation(user, null);
UserConversation Records retreved from getUserConversations()
does not have the key last_read_message
or inside the $transient
object.
Using name hook
is difficult to identify the functions are used by cloud or client. To be consistent with core sdk, use name cloud
.
Please also remember to update https://github.com/skygear-demo/cloud-chat-demo-js
Currently addAdmins()
will refuse to add the user if they are not already a participant.
It should automatically make the user a participant.
As a chat SDK, the correct typing event should be automatically sent based on input onChange
events. The debounce logic should be part of the SDK IMHO.
skygear.config is overwritten when the chat sdk is loaded using CDN
Two features:
Handle initial fetch of message, subscribe to message event together, to provide a data model for message list for a conversion, and a proxy for relevant message event.
Handle offline cache of message history.
index.js
requires underscore
but is not listed in package.json
.
Applies to current version (0.1.0) on npm.
When calling markAsLastMessageRead, it calls _getUserConversation method.
However, _getUserConversation always throws no conversation found
error.
sendTypingIndicator(conversation, state)
vs
subscribeTypingIndicator() / subscribeAllTypingIndicator(), the callback return "event"
Either call it state, or event, we should align it!
This API should only return conversations that the user is actually part of.
Currently you'll get many of other people's conversations....
Couldn't use skygear chat when both Skygear CDN and Skygear Chat CDN are included in the app.
Maybe it is due to the standalone value of Broswerify, as it is "skygear" and it duplicates with the skygear JS SDK.
get_messages
lambda throws exception because getMessages()
gives wrong paramater.
Expected Behaviour:
getMessages()
should not receive an error from get_messages
lambda.
I think much more of the client logic can be encapsulated into the SDK.... It's currently extremely hard to use.
IMO, the SDK's API should be based on ease of use and not ease of implementation..... :(
Things like "list of conversations that belongs to the current user" and "current conversation" should be part of the SDK, it's unlikely that a chat app will not have a list of chats or more than 1 current chat.
Some APIs are quite chaotic like: userConversation.$transient.conversation.$transient.last_message.body
it almost seem like a hack / workaround.
The reciept
-> read_at
date is set in the database after calling markAsRead()
.
Currently when we call getUserConversations, we can specify includeLastMessage: boolean, page: number, pageSize: number using positional argument.
The problem is, when I just want to specify "pageSize", I have to specify"includeLastMessage" and "page" as well although I just want to leave them as default.
For example, if I want to set the pageSize as 20, then I have to call getUserConversations(true, 1, 20).
Can we explore the use of option here to avoid the confusion?
The create
event should be emitted for new conversations, got update
instead.
Expected:
public getUnreadCount(): Promise<number>
getUnreadCount return the total unread message count of current user
Actual:
public getUnreadCount(): Promise<Object>
returns the total unread count of conversations and messages of the current user
when there are no conversations, returns this:
{
conversation: 0,
message: null
}
object is returned by chat:total_unread
lambda.
subscribe
will listen on all conversation events.... That's rarely what we want in practice, it should filter out messages for a specific conversion just like subscribeTypingIndicator
.
Add utilities for making MVPs easier to write. See attachment for details.
chat-SDK-JS Utilities.zip
If user passed a date object to fetch message api, use beforeTime. If user pass string to the api, fetch messages by before message id.
The main
field in package.json
should be dist/index.js
not index.js
.
Applies to current version (0.1.0
) on npm.
Currently the unread_count
attribute is only available in the UserConversation record.
This should be available in Conversation records returned by getConversaton().
Currently the last_message
transient include is only available in the UserConversation
record returned by getUserConversations()
.
This should be available in Conversation
records returned by getConversaton()
.
Currently it assume the object is browser file object. Which is not always true, developer may want to provide an skygear.asset with base64 or custom contentType.
To design the persistent store layer to support both web, ionic and react-native
Deliverables:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.