Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadowsith committed Feb 10, 2023
0 parents commit eca5c77
Show file tree
Hide file tree
Showing 9 changed files with 6,376 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dist
/node_modules
/mattermost-vimeo-plugin
*.tar.gz
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Philip Mayer ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## mattermost-plugin-vimeo
Mattermost web app plugin to generate an embedded videoplayer for Vimeo urls

### Build:
Run `npm run build`

### License
MIT
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
./node_modules/.bin/webpack --mode=production
rm -f mattermost-vimeo-plugin.tar.gz
rm -rf mattermost-vimeo-plugin
mkdir -p mattermost-vimeo-plugin
cp -r dist/main.js mattermost-vimeo-plugin/
cp plugin.json mattermost-vimeo-plugin/
tar -czvf mattermost-vimeo-plugin.tar.gz mattermost-vimeo-plugin
6,198 changes: 6,198 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "mattermost-vimeo",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"build": "./build.sh"
},
"author": "",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"babel-loader": "^9.1.2",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
},
"dependencies": {
"react": "^18.2.0"
}
}
16 changes: 16 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "vimeo",
"name": "Vimeo",
"description": "Mattermost web app plugin to have an embedded videoplayer for Vimeo urls",
"homepage_url": "https://github.com/Shadowsith/mattermost-plugin-vimeo",
"support_url": "https://github.com/Shadowsith/mattermost-plugin-vimeo/issues",
"release_notes_url": "https://example.com/releases/v0.0.1",
"version": "1.0.0",
"webapp": {
"bundle_path": "main.js"
},
"props": {
"iframeWidth": 600,
"iframeHeight": 340
}
}
54 changes: 54 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';

class PostWillRenderEmbed extends React.Component {
static plugin = null;

render() {
let title = '';
const iframeWidth = PostWillRenderEmbed.plugin.props.iframeWidth;
const iframeHeight = PostWillRenderEmbed.plugin.props.iframeHeight;

try {
title = this.props.embed.data.title;
} catch {
}

let url = '';
if (!this.props.embed.url.includes('player.vimeo.com')) {
url = this.props.embed.url.replace('vimeo.com', 'player.vimeo.com/video');
} else {
url = this.props.embed.url;
}

return (
<div>
<h5>{title}</h5>
<iframe src={url} width={iframeWidth} height={iframeHeight}>
</iframe>
</div>
);
}
}

class VimeoPlugin {
initialize(registry, store) {
const plugin = store.getState().plugins.plugins.vimeo;
PostWillRenderEmbed.plugin = plugin;
registry.registerPostWillRenderEmbedComponent(
(embed) => {
if (embed.type == 'opengraph' && embed.url.includes('vimeo.com')) {
return true;
}
return false;
},
PostWillRenderEmbed,
false,
);
}

uninitialize() {
// No clean up required.
}
}

window.registerPlugin('vimeo', new VimeoPlugin());
46 changes: 46 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var path = require('path');

module.exports = {
entry: [
'./src/index.jsx',
],
resolve: {
modules: [
'src',
'node_modules',
],
extensions: ['*', '.js', '.jsx'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react',
[
"@babel/preset-env",
{
"modules": "commonjs",
"targets": {
"node": "current"
}
}
]
],
},
},
},
],
},
externals: {
react: 'React',
},
output: {
path: path.join(__dirname, '/dist'),
publicPath: '/',
filename: 'main.js',
},
};

0 comments on commit eca5c77

Please sign in to comment.