Skip to content

Instantly share code, notes, and snippets.

@knowuh
Last active August 24, 2017 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knowuh/0d87fb9d2d8de429f6d0aabf0d3d18a5 to your computer and use it in GitHub Desktop.
Save knowuh/0d87fb9d2d8de429f6d0aabf0d3d18a5 to your computer and use it in GitHub Desktop.
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[]
}
import SharingContext from "./sharing-context"
export const InitMessageName = "SharinatorInit"
export interface SharinatorInitArgs {
context: SharingContext
version: string
requestTime: Date
}
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)
}
}
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
}
@dougmartin
Copy link

Looks like a great start - just a couple of comments:

  1. We need to check on the json serialization/deserialization for JavaScript Date types - you use them in a couple of structures.
  2. I think app.getDataFunc() would need to be passed a completion callback since it (in the case of the collaboration space) would need to send async publish messages to its children and wait for their response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment