Last active
July 2, 2021 15:35
-
-
Save jurgob/aa265e42fe3bda2318e9cc3d1cc5c293 to your computer and use it in GitHub Desktop.
This file contains 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
{ | |
"id": "<#/components/schemas/event_id>", | |
"conversation_id": "<#/components/schemas/conversation_id>", | |
"application_id": "<#/components/schemas/application_id>", | |
"timestamp": "<#/components/schemas/date>", | |
"from": "<#/components/schemas/member_id>", | |
"_embedded": "<#/components/schemas/event_embedded>", | |
"type": "member:joined", | |
"body": { | |
"user": { | |
"member_id": "<#/components/schemas/member_id>", | |
"user_id": "<#/components/schemas/user_id>", | |
"name": "<#/components/schemas/member_name>", | |
"display_name": "<#/components/schemas/empty_display_name>" | |
}, | |
"conversation": { | |
"conversation_id": "<#/components/schemas/conversation_id>", | |
"display_name": "<#/components/schemas/empty_display_name>", | |
"name": "<#/components/schemas/name_conversation>", | |
"image_url": "<#/components/schemas/image_url>" | |
}, | |
"timestamp": "<#/components/schemas/member_timestamp>", | |
} | |
} | |
{ | |
"id": "<#/components/schemas/event_id>", | |
"conversation_id": "<#/components/schemas/conversation_id>", | |
"application_id": "<#/components/schemas/application_id>", | |
"timestamp": "<#/components/schemas/date>", | |
"from": "<#/components/schemas/member_id>", | |
"_embedded": "<#/components/schemas/event_embedded>", | |
"type": "member:invited", | |
"body": { | |
"conversation": { | |
"conversation_id": "<#/components/schemas/conversation_id>", | |
"display_name": "<#/components/schemas/empty_display_name>", | |
"name": "<#/components/schemas/name_conversation>", | |
"image_url": "<#/components/schemas/image_url>" | |
}, | |
"user": { | |
"member_id": "<#/components/schemas/member_id>", | |
"user_id": "<#/components/schemas/user_id>", | |
"display_name": "<#/components/schemas/display_name>", | |
"name": "<string>" | |
}, | |
"timestamp": "<#/components/schemas/member_timestamp>", | |
}, | |
} | |
{ | |
"id": "<#/components/schemas/event_id>", | |
"conversation_id": "<#/components/schemas/conversation_id>", | |
"application_id": "<#/components/schemas/application_id>", | |
"timestamp": "<#/components/schemas/date>", | |
"from": "<#/components/schemas/member_id>", | |
"_embedded": "<#/components/schemas/event_embedded>", | |
"type": "member:left" | |
"body": { | |
"timestamp": "<#/components/schemas/member_timestamp>", | |
"user": { | |
"member_id": "<#/components/schemas/member_id>", | |
"user_id": "<#/components/schemas/user_id>", | |
"display_name": "<#/components/schemas/display_name>", | |
"name": "<string>" | |
} | |
}, | |
} | |
/** | |
const engine = new Engine(); | |
engine.dispatch(new MemberJoined()) | |
engine.onEvent((event, dispatch) => { | |
//event is a MemberJoined | |
dispatch(new MemberInvite()) | |
}) | |
*/ | |
/** | |
DESIGN ?!?! | |
MAIN SDK COMPONENTS | |
getter | |
reducer | |
store | |
onEvent //where the side effects happend | |
dispatcher //it accept events generated by: | |
- socket.io | |
- user interraction //sdk function calls | |
- http response | |
- push notification | |
- media event | |
*/ | |
//AN EXAMPLE, given some kotlin stuff, how to implement the objective-c / android wrapper" | |
/** | |
//the engine class and the types for events / object can be implemented in kotlin and exported in the native language | |
const engine = new Engine(); | |
engine.dispatch(new MemberJoined()) | |
engine.onEvent((event, dispatch) => { | |
//event is a MemberJoined | |
dispatch(new MemberInvite()) | |
}) | |
//once you got those, you can an sdk like this: | |
import {EventJoinConversation,EventConversationJoined } from 'sdk-events' | |
import engine from 'engine' | |
class SDK { | |
constructor(){ | |
engine.onEvent((event, dispatch) => { | |
if(event.type === 'join:conversation'){ | |
const res = await httpRequest({url:"/conversations/:cid.member"}) | |
dispatch(new EventConversationJoined(res)) | |
} | |
}) | |
socketioClient.onpacket(socketioEvent => { | |
engine.dispatch(new FactorySocketEvents(socketioEvent)) | |
}) | |
} | |
joinConversation(params){ | |
engine.dispatch(new EventJoinConversation(params)) | |
} | |
onEvent(cb){ | |
engine.onEvent(cb) | |
} | |
} | |
//in the kotlin code, you can test stuff in an `almost end to end` way | |
test('I add a conversation', () => { | |
engine.onEvent = mock() | |
engine.dispatch(new EventJoinConversation(params)) | |
engine.dispatch(new EventConversationJoined(res)) | |
const conversations = engine.getConversations() | |
expect(conversations.length).equals(1) | |
expect(engine.onEvent).calls.once | |
}) | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment