mirror of
https://github.com/wassname/talk.git
synced 2026-09-11 12:51:33 +08:00
[next] Add support for embed (#1762)
* Move talk-server/config to talk-common/config * Refactor build into /src/core/build and use common config * Add embed webpack config * Start implementing embed * Implement embed * Add pym types * Add event emitter to Talk Context * Add MatchMedia test for passing values from the context * Add support for click far away * Integrate pym click events to registerClickFarAway * Add tests * Resolve merge issues * Apply PR review
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import pym from "pym.js";
|
||||
|
||||
import { CleanupCallback, Decorator } from "./decorators";
|
||||
|
||||
interface PymControlConfig {
|
||||
id: string;
|
||||
url: string;
|
||||
title: string;
|
||||
decorators?: ReadonlyArray<Decorator>;
|
||||
}
|
||||
|
||||
export default class PymControl {
|
||||
private pym: pym.Parent;
|
||||
private cleanups: CleanupCallback[];
|
||||
|
||||
constructor(config: PymControlConfig) {
|
||||
const decorators = config.decorators || [];
|
||||
|
||||
this.pym = new pym.Parent(config.id, config.url, {
|
||||
title: config.title,
|
||||
id: `${config.id}_iframe`,
|
||||
name: `${config.id}_iframe`,
|
||||
});
|
||||
|
||||
this.cleanups = decorators
|
||||
.map(enhance => enhance(this.pym))
|
||||
.filter(cb => cb) as CleanupCallback[];
|
||||
}
|
||||
|
||||
public sendMessage(id: string, raw?: string) {
|
||||
this.pym.sendMessage(id, raw || "");
|
||||
}
|
||||
|
||||
public remove() {
|
||||
this.cleanups.forEach(cb => cb());
|
||||
this.cleanups = [];
|
||||
|
||||
// Remove the pym parent.
|
||||
this.pym.remove();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user