m1k1o / neko

A self hosted virtual browser that runs in docker and uses WebRTC.
https://neko.m1k1o.net/
Apache License 2.0
5.95k stars 449 forks source link

Send message in chat or clipboard progrmmaticaly #340

Open ricou84 opened 8 months ago

ricou84 commented 8 months ago

Hello.

Thanks you for this great tools. It would make m'y lifetime as a trainer easier.

Context: i would pop UP a bunch of neko/xfce on each traînee lab. I have some command to share with my traînee that they would have to exécute on the neko dektop.

I would like to broadcast this command on the chat or on thé clipboard of each traînee if possible programmaticaly.

Can neko-rooms be used for that ?

Thanks

yesBad commented 8 months ago

Yeah you could technically use neko rooms for that

ricou84 commented 8 months ago

Thanks you i would test it.

Scality-EmerikNicole commented 8 months ago

I was not aware that neko-rooms launch rooms localy.

For network reason , I need that neko:xfce desktop have to been executed somewhere , one for each trainee.

The need to share command . each trainee will have to execute this command in the contect of their VDI.

thanks for your advice

m1k1o commented 8 months ago

I was not aware that neko-rooms launch rooms localy.

Neko-rooms is only orchestrator and can launch/manage rooms on the docker socket that you assign to them. It does not matter if that docker daemon is running locally or not.

For network reason , I need that neko:xfce desktop have to been executed somewhere , one for each trainee.

So you have dedicated server that hosts all neko rooms? And you want to only start it from remote computer?

Scality-EmerikNicole commented 8 months ago

hello thanks for your answer and the interest for my use case.

I will explain a little bit the context and what i would like.

Each trainee have a lab with a bunch of ec2 instances in the same private network per lab. One of this ec2 instance have a Public ip and it been used to jump on other machines of the lab.

today i execute neko:xfce on it and i'm happy with that. i can connect through neko with ssh and http on all machine of my lab.

The trainer have also a lab on which i would execute neko-rooms to be able to manage each neko:xfce and send some command that each trainee will have to execute on their xfce.

Thanks for your comment and help

m1k1o commented 8 months ago

That is really interesting use-case. Neko rooms is currently meant to manage multiple rooms on a single sever, not on multiple servers. But there is plan to add support for that.

But if you want to send any command to existing neko instances, you can just connect to the websocket and send any message to the chat or fill clipboard.

ricou84 commented 8 months ago

Hello thanks for this answer.

I 'm a complete newbie in websocket. If you Can point me to thé right direction and some technical Reading i will bé very happy.

Thanks

yesBad commented 8 months ago

What language would you like to use to send to the websocket?

ricou84 commented 8 months ago

Python is the one i know thé best

yesBad commented 8 months ago

Python is the one i know thé best

then I suggest checking out the https://pypi.org/project/websockets/

Scality-EmerikNicole commented 8 months ago

Hello. I tried with this code.

import asyncio
from websockets.sync.client import connect
import json

endpoint='127.0.0.1:30000'
username='user'
password='neko'

def hello():
    with connect(f"ws://{endpoint}/neko/ws?password={password}") as websocket:

        message = "Hello world!"
        events = {"event":"chat/message","content": message }
        websocket.send(json.dumps(events))
        message = websocket.recv()
        print(f"Received: {message}")
try:
    hello()
except Exception as e:
    print(e)

but it seems that something is missing. May be an offer. can you point me in the right direction?

mtami-zoor commented 1 month ago

I can see the WebSocket event "chat/message" received on the neko session, but the message content is not posted on the Chat. any Idea?

Here is a simple Python script for sending a WebSocket chat event :

## pip install websockets

import asyncio
import websockets
import json

async def send_message():
    nekoURL = ""
    nekoRoomID = ""
    nekoRoomPassword = ""
    url = f"{nekoURL}/{nekoRoomID}/ws?password={nekoRoomPassword}"
    event = "chat/message"
    message = "Hi there ¯\_(ツ)_/¯"

    payload = {
        "event": event,
        "content": message,
    }

    try:
        async with websockets.connect(url) as websocket:

            await websocket.send(json.dumps(payload))

    except websockets.exceptions.InvalidStatusCode as e:
        print(f"Failed to connect: {e}")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    asyncio.run(send_message())
image