Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3851] - Implement the functionality to send changes of add-block #3952

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
72097b8
fixes #3913
walterbender Jun 23, 2024
200dddb
fix:resolves grid position on hamburger opening(#3914) (#3924)
BeNikk Jun 28, 2024
71fe874
Merge branch 'master' into collaboration
apsinghdev Jul 1, 2024
423b467
Fix input boxes (#3927)
apsinghdev Jul 2, 2024
0d082eb
bump version
walterbender Jul 2, 2024
eb7c23a
enhancement: scale on hover (#3926)
Anas-2357 Jul 2, 2024
6354fa8
calculate frequencies from ratio
walterbender Jul 2, 2024
474f811
Merge branch 'master' of github.com:sugarlabs/musicblocks
walterbender Jul 2, 2024
ad292d9
Merge branch 'master' into collaboration
apsinghdev Jul 3, 2024
5848e62
Add close button to extended-menu pie menu (fixes #3933) (#3934)
BeNikk Jul 3, 2024
10ab05e
Bump braces and gulp (#3903)
dependabot[bot] Jul 3, 2024
5e27904
add support for solfege accidentals in phrasemaker
walterbender Jul 4, 2024
3c57c4b
Merge branch 'master' of github.com:sugarlabs/musicblocks
walterbender Jul 4, 2024
530f330
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Jul 4, 2024
f73597e
Merge branch 'master' into collaboration
apsinghdev Jul 4, 2024
5022721
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Jul 7, 2024
55570e8
Add support for cents (#3937)
walterbender Jul 7, 2024
f88955e
Ratio transpose and Ratio interval (#3936)
walterbender Jul 7, 2024
97e811a
fix note convert
walterbender Jul 7, 2024
cba02d3
remove extra comma throwing off indexing
walterbender Jul 7, 2024
306888e
Merge branch 'master' into collaboration
apsinghdev Jul 9, 2024
2d99514
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Jul 10, 2024
944bc2e
Hyperscore link update (#3939) (#3947)
therealharshit Jul 12, 2024
aaf0f6e
Update Hyperscore example link in guide.html (#3944)
GeetenParab Jul 12, 2024
c41d9f5
Update README.md (#3943)
akilesh1706 Jul 12, 2024
69f8ee8
left_and_back_images (#3950)
khadar1020 Jul 15, 2024
472ec5c
Updated Dockerfile (#3949)
akilesh1706 Jul 15, 2024
cc0b986
Merge branch 'master' into collaboration
apsinghdev Jul 16, 2024
fd710bc
add temp collaborate button
apsinghdev Jul 16, 2024
14e8d82
Write collaboration as a class
apsinghdev Jul 16, 2024
87ae06d
bind collaboration with activity
apsinghdev Jul 16, 2024
87b9abb
Add emitter on new block creation
apsinghdev Jul 16, 2024
79f475c
connect collaborare UI with functionality
apsinghdev Jul 16, 2024
9269c32
Set local update flag
apsinghdev Jul 16, 2024
7e0ceb6
Render received data
apsinghdev Jul 16, 2024
35b8fc7
Initiate collaboration
apsinghdev Jul 16, 2024
99178ab
Make socket connection
apsinghdev Jul 16, 2024
c8873ac
Listen for emit message
apsinghdev Jul 16, 2024
2d89a50
Handle error
apsinghdev Jul 16, 2024
08787e1
remove yjs and socket.io dependecies
apsinghdev Jul 16, 2024
5749a3b
Merge branch 'collaboration' into Feat/send-changes-of-adding-block
apsinghdev Jul 16, 2024
8776750
Fixed #3956 Auto increasing and decreasing input block (#3957)
therealharshit Jul 25, 2024
6436c2f
fixes #3941
walterbender Jul 26, 2024
3b63768
Merge branch 'master' of github.com:sugarlabs/musicblocks
walterbender Jul 26, 2024
c415d53
fixes #3958
walterbender Jul 26, 2024
cc4bcef
Merge branch 'master' into collaboration
apsinghdev Jul 27, 2024
2e1c23b
Merge branch 'collaboration' into Feat/send-changes-of-adding-block
apsinghdev Jul 27, 2024
e663fe3
minor fixes
apsinghdev Jul 27, 2024
3e09e00
minor fixes
apsinghdev Jul 27, 2024
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
13 changes: 8 additions & 5 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@

FROM python:latest

# First stage: Build stage
FROM python:latest AS build

WORKDIR /app

COPY . .

COPY . .
# Second stage: Final stage
FROM python:latest

WORKDIR /app

EXPOSE 3000
COPY --from=build /app /app

EXPOSE 3000

CMD ["python", "-m", "http.server", "3000", "--bind", "0.0.0.0"]
2 changes: 1 addition & 1 deletion documentation/back_block.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion documentation/left_block.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ While a bit fanciful, this example, which can be run by clicking on
the link below, takes musical paint in a novel direction.

[RUN
LIVE](https://walterbender.github.io/musicblocks/index.html?id=1523896294964170&run=True&run=True)
LIVE](https://sugarlabs.github.io/musicblocks/index.html?id=1523896294964170&run=True&run=True)

## <a name="ENSEMBLE">3.8 Ensemble</a>

Expand Down
3 changes: 2 additions & 1 deletion guide/guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ <h2 id="2-making-sounds"><a name="NOTES">2. Making Sounds</a></h2>
<a href="#3-programming-with-music">Next Section (3. Programming with Music)</a>
</p>
<p>

Music Blocks incorporates many common elements of music, such as
<a href="#22-pitch-blocks">pitch</a>, <a href="#21-note-value-blocks">rhythm</a>,
<a href="#341-set-volume-and-crescendo">volume</a>, and, to some degree,
Expand Down Expand Up @@ -2406,7 +2407,7 @@ <h3 id="37-interactions"><a name="INTERACTIONS">3.7 Interactions</a></h3>
</p>
<p>
<a
href="https://walterbender.github.io/musicblocks/index.html?id=1523896294964170&amp;run=True&amp;run=True"
href="https://sugarlabs.github.io/musicblocks/index.html?id=1523896294964170&run=True&run=True"
>RUN LIVE</a
>
</p>
Expand Down
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,16 @@
>
<a style="color: transparent;">space&nbsp;&nbsp;&nbsp;</a>
</li>
<li>
<a
id="collaborateIcon"
class="tooltipped"
data-position="bottom"
><i class="material-icons md-48"
>groups</i
></a
>
</li>
<li>
<a
id="restoreIcon"
Expand Down
42 changes: 41 additions & 1 deletion js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,39 @@ class Activity {
})
}

// Initialize the collaboration
this._initiateCollaboration = () => {
this.collaboration.startCollaboration();
this.blocks.isLocalUpdate = true;
};

// Render the project from received data
this.renderProjectFromData = (update) => {
const data = JSON.parse(update);
document.body.style.cursor = "wait";
// this.doLoadAnimation();
this.blocks.isLocalUpdate = false;

// Render the blocks
for (const name in this.palettes.dict) {
this.palettes.dict[name].hideMenu(true);
}

this.stage.removeAllEventListeners("trashsignal");

// Wait for the old blocks to be removed.
// eslint-disable-next-line no-unused-vars
const __listener = (event) => {
this.blocks.loadNewBlocks(data);
this.stage.removeAllEventListeners("trashsignal");
};

this.stage.addEventListener("trashsignal", __listener, false);
this.sendAllToTrash(false, false);
this._allClear(false);
this.refreshCanvas();
};

/**
* Sets up plugin and palette boilerplate.
* This function initializes various properties related to the plugin objects,
Expand Down Expand Up @@ -3347,6 +3380,11 @@ class Activity {
this.refreshCanvas();
};

// Start the collaboration
const initiateCollaboration = (activity) => {
activity._initiateCollaboration();
}

this.handleKeyDown = (event) => {

if (event.ctrlKey && event.key === "z") {
Expand Down Expand Up @@ -5141,7 +5179,7 @@ class Activity {
})

document.addEventListener("mouseup", (event) => {
event.preventDefault();
// event.preventDefault();
this.isDragging = false;
this.selectionArea.style.display = "none";
this.startX = 0;
Expand Down Expand Up @@ -5377,6 +5415,7 @@ class Activity {

this.pasteBox = new PasteBox(this);
this.languageBox = new LanguageBox(this);
this.collaboration = new Collaboration(this);

// Show help on startup if first-time user.
if (this.firstTimeUser) {
Expand Down Expand Up @@ -5425,6 +5464,7 @@ class Activity {
if (_THIS_IS_MUSIC_BLOCKS_) {
this.toolbar.renderChooseKeyIcon(chooseKeyMenu);
}
this.toolbar.renderCollaborateIcon(initiateCollaboration);
this.toolbar.renderJavaScriptIcon(toggleJSWindow);
this.toolbar.renderLanguageSelectIcon(this.languageBox);
this.toolbar.renderWrapIcon();
Expand Down
5 changes: 4 additions & 1 deletion js/artwork.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions js/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,9 @@ class Block {
unhighlightSelectedBlocks(blk, selection) {
if (selection) {
this.blocks.unhighlight(blk, true);
this.disconnectedBitmap.visible = true;
if (!this.collapsed) {
this.disconnectedBitmap.visible = true;
}
this.container.updateCache();
};
}
Expand Down Expand Up @@ -3381,23 +3383,23 @@ class Block {

const labelElem = docById("labelDiv");

var safetext = function(text){
var safetext = function(text){
// Best to avoid using these special characters in text strings
// without first converting them to their "safe" form.
var table = {
'<': 'lt',
'>': 'gt',
'"': 'quot',
'\'': 'apos',
'&': 'amp',
'\r': '#10',
'\n': '#13'
};
return text.toString().replace(/[<>"'\r\n&]/g, function(chr){
return '&' + table[chr] + ';';
});
};
var table = {
'<': 'lt',
'>': 'gt',
'"': 'quot',
'\'': 'apos',
'&': 'amp',
'\r': '#10',
'\n': '#13'
};
return text.toString().replace(/[<>"'\r\n&]/g, function(chr){
return '&' + table[chr] + ';';
});
};

if (this.name === "text") {
labelElem.innerHTML =
Expand Down
23 changes: 23 additions & 0 deletions js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class Blocks {

this.selectedBlocks = [];

this.isLocalUpdate = false;

/**
* We stage deletion of prototype action blocks on the palette so
* as to avoid palette refresh race conditions.
Expand Down Expand Up @@ -3066,6 +3068,14 @@ class Blocks {
this.visible = true;
};

// Emit a message when a new block is created
this.emitAddedBlock = () => {
if (this.activity.collaboration.hasCollaborationStarted) {
const update = this.activity.collaboration.convertBlockListToHtml();
this.activity.collaboration.socket.emit("new-block-added", update);
}
};

/**
* Make a new block with connections
* @param - name - new variable
Expand Down Expand Up @@ -3168,6 +3178,15 @@ class Blocks {

/** and we need to load the images into the container. */
myBlock.imageLoad();

/** Signal that a new block is created */
if (this.activity.collaboration.hasCollaborationStarted) {
if (this.isLocalUpdate) {
setTimeout(() => {
this.emitAddedBlock();
}, 200);
};
};
return myBlock;
};

Expand Down Expand Up @@ -6525,6 +6544,10 @@ class Blocks {
}
}
}

if (this.activity.collaboration.hasCollaborationStarted) {
this.isLocalUpdate = true;
}
};

/**
Expand Down
83 changes: 53 additions & 30 deletions js/collaboration/collaboration.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-unused-vars */
// Copyright (c) 2024 Ajeet Pratap Singh
//
// This program is free software; you can redistribute it and/or
Expand All @@ -14,42 +15,64 @@

/* eslint-disable no-undef */

const RETRIES = 5;
const DELAY_DURATION = 2000;
let attempts = 0;

function stopConnection(socket) {
if(attempts >= RETRIES){
console.log("Maximum calls to make connection exceeded. Stopped making calls");
socket.disconnect();
class Collaboration {
constructor(activity) {
this.activity = activity;
this.RETRIES = 5;
this.DELAY_DURATION = 2000;
this.attempts = 0;
this.socket = null;
this.blockList = this.activity.blocks.blockList;
this.PORT = "http://localhost:8080/";
this.hasCollaborationStarted = false;
this.updatedProjectHtml = null;
}
}

function makeConnection(){
// Convert the blockList into html
convertBlockListToHtml = () => {
this.updatedProjectHtml = this.activity.prepareExport();
return this.updatedProjectHtml;
};

// connect to the local server
const socket = io("http://localhost:8080/");
socket.on("connect", () => {
try{
console.log("connected to the server");
} catch(error){
console.log("Connection failed", error);
// Stop making calls to the socket server
stopConnection = (socket) => {
if (this.attempts >= this.RETRIES) {
console.log("Maximum calls to make connection exceeded. Stopped making calls");
socket.disconnect();
}
});
};

socket.on("connect_error", (error) => {
attempts++;
console.log("Failed to connect to the socket server. Retrying in few seconds...");
setTimeout(stopConnection(socket), DELAY_DURATION);
});
}
// Make calls to the socket server
makeConnection = () => {
// connect to the local server
const socket = io(this.PORT);
socket.on("connect", () => {
this.socket = socket;
try {
console.log("connected to the server");
this.hasCollaborationStarted = true;
} catch (error) {
console.log("Connection failed", error);
}
});

function startCollaboration(){
document.addEventListener("DOMContentLoaded", () => {
makeConnection();
// initialiseDoc();
});
}
socket.on("connect_error", () => {
this.attempts++;
console.log("Failed to connect to the socket server. Retrying in few seconds...");
setTimeout(this.stopConnection(socket), this.DELAY_DURATION);
});

startCollaboration();
socket.on("new-block-added", (update) => {
this.activity.textMsg("New block added. rendering...");
setTimeout(this.activity.hideMsgs, 10000);
this.activity.renderProjectFromData(update);
});
};

// Start the collaboration
startCollaboration = () => {
this.makeConnection();
};
}

Loading