Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ _testoutput/
anaconda-project.yml
envs/
node_modules/
src/*/lib
src/**/lib
Untitled*
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dependencies:
- jupyterlab >=1.0.2,<1.1.0a0
- nodejs >=11,<12
- python >=3.7,<3.8.0a0
- python-socketio >=4,<4.1
7 changes: 7 additions & 0 deletions jupyter_notebook_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"NotebookApp": {
"nbserver_extensions": {
"jupyter_y_websockets": true
}
}
}
7 changes: 4 additions & 3 deletions labex.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@jupyterlab/toc@1.0.1
./src/_core
./src/blockly
./src/prosemirror
./src/ts/_core
./src/ts/blockly
./src/ts/prosemirror
./src/ts/y
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
"private": true,
"scripts": {
"bootstrap": "jlpm && jlpm build",
"build": "cd src && cd _meta && jlpm build",
"build": "cd src && cd ts && cd _meta && jlpm build",
"clean": "lerna exec --parallel --stream -- rimraf lib",
"lint": "jlpm lint:root && jlpm lint:prettier && jlpm lint:ts",
"lint:prettier": "lerna exec -- prettier --write --config=../../.prettierrc ./src/**/*.ts ./src/**/*.tsx ./style/**/*.css ./*.json ./*.md",
"lint:root": "prettier --write *.json *.md *.yml",
"lint:ts": "lerna exec -- tslint -c ../../tslint.json --fix ./src/**/*.ts",
"watch": "cd src && cd _meta && jlpm watch"
"watch": "cd src && cd ts && cd _meta && jlpm watch"
},
"version": "1.0.0",
"workspaces": [
"src/*"
"src/ts/*"
]
}
6 changes: 5 additions & 1 deletion postBuild
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ else
fi
fi

set -ex
set -eux
pushd src/py/jupyter_y_websockets
python -m pip install -e . --ignore-installed --no-deps
popd

jlpm --ignore-optional || jlpm || echo "well, let's try anyway"
jlpm bootstrap
jupyter labextension install $(cat labex.txt)
27 changes: 27 additions & 0 deletions src/py/jupyter_y_websockets/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2018, Dead Pixels Collective
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of [project] nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions src/py/jupyter_y_websockets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# jupyter_y_websockets

> Inspired by https://github.com/y-js/y-websockets-server
42 changes: 42 additions & 0 deletions src/py/jupyter_y_websockets/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[metadata]
name = jupyter_y_websockets
version = 0.1.0
description = a yjs-websockets backend for jupyter
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/deathbeds/jupyterlab-outsource
author = dead pixels collective
author_email = ripxl@googlegroups.com
license = BSD-3-Clause
keywords =
Interactive
license_file = LICENSE
classifiers =
Framework :: Jupyter
Intended Audience :: Developers
Intended Audience :: Information Technology
License :: OSI Approved :: BSD License
Programming Language :: Python

[options]
install_requires =
notebook
python-socketio
package_dir =
= src
packages =
jupyter_y_websockets
include_package_data = True
zip_safe = False

[options.extras_require]
tests =
pytest

[options.packages.find]
where =
src

[flake8]
exclude = .git,__pycache__,envs
max-line-length = 88
1 change: 1 addition & 0 deletions src/py/jupyter_y_websockets/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__("setuptools").setup()
19 changes: 19 additions & 0 deletions src/py/jupyter_y_websockets/src/jupyter_y_websockets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from notebook.utils import url_path_join as ujoin

from ._version import __version__
from .manager import YWebSocketsManager


def _jupyter_server_extension_paths():
raise Exception("POOP")
return [{"module": "jupyter_y_websockets"}]


def load_jupyter_server_extension(nbapp):
mgr = YWebSocketsManager(parent=nbapp)

app = nbapp.web_app
url = ujoin(app.settings["base_url"], "/y/ws/")
handler = mgr.get_handler()
app.add_handlers(".*$", [(url, handler)])
nbapp.log.debug(f"y is listening on {url}")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
63 changes: 63 additions & 0 deletions src/py/jupyter_y_websockets/src/jupyter_y_websockets/manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import traitlets as T
from traitlets.config import LoggingConfigurable

import socketio as S


class YWebSocketsManager(LoggingConfigurable):
sio = T.Instance(S.AsyncServer)

def get_handler(self):

_Handler = S.get_tornado_handler(self.sio)

mgr = self

class SocketHandler(_Handler):
def check_xsrf_cookie(self):
pass

async def on_message(self, message):
mgr.log.error(f"MSG {msg}")
await super().on_message(message)

return SocketHandler

@T.default("sio")
def _default_sio(self):
s = S.AsyncServer(async_mode="tornado")

@s.on("connect")
async def connect(sid, environ): return await self._on_connect(sid, environ)

@s.on("disconnect")
async def disconnect(sid): return await self._on_disconnect(sid)

@s.on("joinRoom")
async def join(sid, data): return await self._on_join(sid, data)

@s.on("yjsEvent")
async def y_event(sid, data): return await self._on_receive(sid, data)

@s.on("leaveRoom")
async def leave(sid, data): return await self._on_leave(sid, data)

return s

@property
def web_app(self):
return self.parent.web_app

async def _on_connect(self, sid, enviorn):
self.parent.log.error(f"Connected {sid}")

async def _on_disconnect(self, sid):
self.parent.log.error(f"disconnect {sid}")

async def _on_join(self, sid, data):
self.parent.log.error(f"{sid} joins {data}")
return await self.sio.enter_root(sid, data["room"])

async def _on_receieve(self, sid, data):
self.parent.log.error(f"{sid} SAYS {data}")
return await self.sio.emit("yjsEvent", data, skip_sid=sid)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/_core/tsconfig.json → src/ts/_core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfigbase",
"extends": "../../../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
Expand Down
3 changes: 2 additions & 1 deletion src/_meta/package.json → src/ts/_meta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dependencies": {
"@deathbeds/jupyterlab-outsource": "^1.0.0",
"@deathbeds/jupyterlab-outsource-blockly": "^1.0.0",
"@deathbeds/jupyterlab-outsource-prosemirror": "^1.0.0"
"@deathbeds/jupyterlab-outsource-prosemirror": "^1.0.0",
"@deathbeds/jupyterlab-outsource-y": "^1.0.0"
},
"description": "Alternate editors for JupyterLab Source",
"files": [
Expand Down
1 change: 1 addition & 0 deletions src/_meta/src/index.ts → src/ts/_meta/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@deathbeds/jupyterlab-outsource';
import '@deathbeds/jupyterlab-outsource-blockly';
import '@deathbeds/jupyterlab-outsource-prosemirror';
import '@deathbeds/jupyterlab-outsource-y';
5 changes: 4 additions & 1 deletion src/_meta/tsconfig.json → src/ts/_meta/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfigbase",
"extends": "../../../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
Expand All @@ -16,6 +16,9 @@
},
{
"path": "../prosemirror"
},
{
"path": "../y"
}
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/blockly/tsconfig.json → src/ts/blockly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfigbase",
"extends": "../../../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfigbase",
"extends": "../../../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
Expand Down
51 changes: 51 additions & 0 deletions src/ts/y/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"author": "Dead Pixels Collective",
"bugs": {
"url": "https://github.com/deathbeds/jupyterlab-outsource/issues"
},
"peerDependencies": {
"@deathbeds/jupyterlab-outsource": "^1.0.0",
"@jupyterlab/application": "^1.0.0",
"@jupyterlab/launcher": "^1.0.0"
},
"dependencies": {
"y-websockets-client": "^8.0.0-0",
"yjs": "^12.0.0-0",
"y-text": "*",
"y-array": "*",
"y-memory": "*",
"y-map": "*"
},
"devDependencies": {
"@deathbeds/jupyterlab-outsource": "^1.0.0",
"@jupyterlab/application": "^1.0.0",
"@jupyterlab/launcher": "^1.0.0"
},
"description": "YJS for outsource",
"files": [
"{lib,style}/**/*.{css,d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}"
],
"homepage": "https://github.com/deathbeds/jupyterlab-outsource",
"jupyterlab": {
"extension": "lib/extension.js"
},
"keywords": [
"jupyter",
"jupyterlab",
"jupyterlab-extension",
"yjs"
],
"license": "BSD-3-Clause",
"main": "lib/index.js",
"name": "@deathbeds/jupyterlab-outsource-y",
"repository": {
"type": "git",
"url": "https://github.com/deathbeds/jupyterlab-outsource.git"
},
"scripts": {
"build": "tsc -b",
"watch": "tsc -b --watch"
},
"types": "lib/index.d.ts",
"version": "1.0.0"
}
37 changes: 37 additions & 0 deletions src/ts/y/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {JupyterFrontEnd, JupyterFrontEndPlugin} from '@jupyterlab/application';
import { ILauncher } from '@jupyterlab/launcher';

import {IOutsourceY, PLUGIN_ID} from '.';


import '../style/index.css';

const CMD = 'outsource-y:scratch-path';

const extension: JupyterFrontEndPlugin<IOutsourceY> = {
id: PLUGIN_ID,
autoStart: true,
provides: IOutsourceY,
requires: [ILauncher],
activate: (_app: JupyterFrontEnd, launcher: ILauncher): IOutsourceY => {
_app.commands.addCommand(CMD, {
label: 'Y',
execute: async (_args: any) => {
(window as any).ws = WebSocket;
const {makeWidget} = await import(/* webpackChunkName: "yjs" */ './widget');
const widget = await makeWidget();
_app.shell.add(widget, 'main');
console.log('added widget');
}
});

launcher.add({
command: CMD,
category: 'Other'
});

return {};
},
};

export default extension;
13 changes: 13 additions & 0 deletions src/ts/y/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Token} from '@phosphor/coreutils';

export const PLUGIN_ID = '@deathbeds/jupyterlab-outsource:y';

/* tslint:disable */
export const IOutsourceY = new Token<IOutsourceY>(PLUGIN_ID);
/* tslint:enable */

export interface IOutsourceY {}

export const CSS = {};

export const API = '/y/ws/';
8 changes: 8 additions & 0 deletions src/ts/y/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'socket.io-client' {}
declare module 'ws' {}
declare module 'y-array/src/Array' {}
declare module 'y-map/src/Map' {}
declare module 'y-memory/src/Memory' {}
declare module 'y-text/src/Text' {}
declare module 'y-websockets-client/src/Websockets-client' {}
declare module 'yjs/src/y' {}
Loading