Last active
August 24, 2017 12:47
-
-
Save knowuh/0d87fb9d2d8de429f6d0aabf0d3d18a5 to your computer and use it in GitHub Desktop.
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 SharingContext from "./sharing-context" | |
export type Jpeg = {type: "image/jpeg", extension: "jpg" } | |
export type Csv = {type: "text/csv", extension: "csv" } | |
export type Binary = {type: "application/octet-stream", extension: "bin" } | |
export type Json = {type: "application/json", extension: "json" } | |
export type RepresentationType = Jpeg | Csv | Binary | Json | |
export type Url = string | |
export type Identifier = string | number | |
export interface Representation { | |
type: RepresentationType | |
dataUrl: Url | |
} | |
export interface LaunchApplication { | |
launchUrl: Url | |
name: string | |
} | |
export const PublishMessageName = "SharinatorPublish" | |
export const PublishResponseMessageName = "SharinatorPublishResponse" | |
export interface Publishable { | |
context: SharingContext | |
createdAt: Date | |
application: LaunchApplication | |
representations: Representation[] | |
} |
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 SharingContext from "./sharing-context" | |
export const InitMessageName = "SharinatorInit" | |
export interface SharinatorInitArgs { | |
context: SharingContext | |
version: string | |
requestTime: Date | |
} |
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 SharingContext from "./sharing-context" | |
import {InitMessageName, SharinatorInitArgs} from "./sharinator-init-args" | |
import { | |
LaunchApplication, | |
Publishable, | |
PublishMessageName, | |
PublishResponseMessageName, | |
Representation} from "./publishable" | |
interface listener{ } | |
type MessageContent = any | |
type MessageType = string | object | |
interface IFramePhone { | |
initialize():void | |
getListenerNames(): listener[] | |
addListener(messageName:string, listener:Function): void | |
removeAllListeners(): void | |
disconnect(): void | |
post(type:MessageType, content:MessageContent): void | |
} | |
export interface SharableApp { | |
application: LaunchApplication | |
getDataFunc(): Representation[] | |
} | |
export class SharinatorPhoneClient { | |
phone: IFramePhone | |
context: SharingContext | |
app: SharableApp | |
constructor(phone:IFramePhone, app:SharableApp) { | |
this.phone = phone | |
this.app = app | |
// For now assume that its ready to add listeners … (TBD) | |
this.phone.addListener( | |
InitMessageName, | |
(args:SharinatorInitArgs) => | |
this.context = args.context | |
) | |
this.phone.addListener(PublishMessageName, (args:any) => this.sendPublish()) | |
} | |
sendPublish() { | |
const representations = this.app.getDataFunc() | |
const publishContent:Publishable = { | |
context: this.context, | |
createdAt: new Date(), | |
application: this.app.application, | |
representations: representations | |
} | |
this.phone.post(PublishResponseMessageName, publishContent) | |
} | |
} |
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
export type Identifier = string | number | |
export interface User { | |
displayName: string | |
id: Identifier | |
} | |
export interface Group { | |
displayName: string | |
id: Identifier | |
} | |
export interface Offering { | |
displayName: string | |
id: Identifier | |
} | |
export default interface SharingContext { | |
userId: User | |
groupId: Group | |
offeringId: Offering | |
localId: Identifier | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like a great start - just a couple of comments: