Skip to content

Commit

Permalink
extracting peer
Browse files Browse the repository at this point in the history
  • Loading branch information
pablitar committed Nov 27, 2019
1 parent 28919da commit c5824a3
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 60 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See https://docs.bazel.build/versions/master/build-ref.html#workspace
workspace(
# How this workspace would be referenced with absolute labels from another workspace
name = "dcl_comms_proto",
name = "comms",
# Map the @npm bazel workspace to the node_modules directory.
# This lets Bazel use the same node_modules as other local tooling.
managed_directories = {"@npm": ["node_modules"]},
Expand Down
1 change: 1 addition & 0 deletions lighthouse/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ts_library(

nodejs_binary(
name = "server",
module_name = "@comms/comms_lighthouse"
data = [
":comms_lighthouse",
],
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dcl_comms_proto",
"name": "comms",
"version": "0.1.0",
"private": true,
"devDependencies": {
Expand All @@ -13,9 +13,9 @@
"typescript": "^3.7.2"
},
"scripts": {
"startClient": "ibazel run peer:devserver",
"startClient": "ibazel run peer-react-app:devserver",
"startServer": "ibazel run lighthouse:server",
"start": "ibazel run peer:devserver & ibazel run lighthouse:server"
"start": "ibazel run peer-react-app:devserver & ibazel run lighthouse:server"
},
"dependencies": {
"@types/cors": "^2.8.6",
Expand Down
11 changes: 2 additions & 9 deletions peer/App.tsx → peer-react-app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
// currently third part packages frmo npm are not available due to issue:
import React from "react";
import ReactDOM from "react-dom";
import {connect} from "comms/peer"

import Peer from 'peerjs';

const peer = new Peer(new Date().getTime().toString());

const conn = peer.connect('another-peers-id');

conn.on('open', () => {
conn.send('hi!');
});
connect()

class App extends React.Component {
constructor(props: {}) {
Expand Down
53 changes: 53 additions & 0 deletions peer-react-app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
load("@npm_bazel_typescript//:index.bzl", "ts_devserver", "ts_library")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "static",
srcs = glob(
include = [
"static/**/*",
],
),
)

ts_library(
name = "peer-react-app",
srcs = glob(include =
[
"*.tsx",
"*.ts",
]),
tsconfig = "//:tsconfig.json",
deps = [
"//peer",
"@npm//@types/react",
"@npm//@types/react-dom",
"@npm//react",
"@npm//react-dom",
],
)

ts_devserver(
name = "devserver",
additional_root_paths = [
"npm/node_modules/react/umd",
"npm/node_modules/react-dom/umd",
"react_samples/src/styles",
],
entry_module = "comms/peer-react-app/index",
port = 3001,
# This is the path we'll request from the browser, see index.html
serving_path = "/bundle.js",
# The devserver can serve our static files too
static_files = [
"index.html",
"static/index.css",
],
deps = [
"static/config.js",
":peer-react-app",
"@npm//react",
"@npm//react-dom",
],
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 6 additions & 46 deletions peer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,53 +1,13 @@
load("@npm_bazel_typescript//:index.bzl", "ts_devserver", "ts_library")
load("@npm_bazel_typescript//:index.bzl", "ts_library")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "static",
srcs = glob(
include = [
"static/**/*",
],
),
)

ts_library(
name = "peer",
srcs = glob(include =
[
"*.tsx",
"*.ts",
]),
module_name = "@comms/peer",
srcs = glob(["*.ts"]),
tsconfig = "//:tsconfig.json",
deps = [
"@npm//@types/react",
"@npm//@types/react-dom",
"@npm//peerjs",
"@npm//react",
"@npm//react-dom",
],
)

ts_devserver(
name = "devserver",
additional_root_paths = [
"npm/node_modules/react/umd",
"npm/node_modules/react-dom/umd",
"react_samples/src/styles",
],
entry_module = "dcl_comms_proto/peer/index",
port = 3001,
# This is the path we'll request from the browser, see index.html
serving_path = "/bundle.js",
# The devserver can serve our static files too
static_files = [
"index.html",
"static/index.css",
],
deps = [
"static/config.js",
":peer",
"@npm//react",
"@npm//react-dom",
],
)
"@npm//peerjs"
]
)
11 changes: 11 additions & 0 deletions peer/Peer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Peer from "peerjs";

export function connect() {
const peer = new Peer(new Date().getTime().toString());

const conn = peer.connect("another-peers-id");

conn.on("open", () => {
conn.send("hi!");
});
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
"lib": ["es2017", "dom", "esnext.asynciterable", "esnext"]
},
"exclude": ["node_modules", "bazel-*", "**/node_modules/*"],
"include": ["peer/**/*", "lighthouse/**/*"]
"include": ["peer/**/*", "lighthouse/**/*", "peer-react-client"]
}

0 comments on commit c5824a3

Please sign in to comment.