Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d1d81015
authored
Jun 03, 2026
by
aa.gustiana@gmail.com
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Refactor printer integration to use new WebSocket parameters and add error handl…
…ing for server responses
1 parent
ce2320cd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
9 deletions
opensipkd/base/__init__.py
opensipkd/base/views/printers.py
pyproject.toml
opensipkd/base/__init__.py
View file @
d1d8101
...
...
@@ -520,8 +520,9 @@ class BaseApp():
self
.
reg_nip
=
0
self
.
single_device
=
"false"
self
.
is_pylpr
=
False
self
.
ws_print_url
=
""
self
.
ws_print_id
=
""
self
.
wsp_url
=
""
self
.
wsp_client_id
=
""
self
.
wsp_client_key
=
""
def
get_route_file
(
self
,
filename
=
"routes.csv"
):
fullpath
=
os
.
path
.
join
(
self
.
base_dir
,
'scripts'
,
'data'
,
filename
)
...
...
@@ -567,8 +568,9 @@ class BaseApp():
self
.
login_tpl
=
get_params
(
"login_tpl"
,
""
,
settings
=
settings
)
self
.
login_captcha
=
int
(
get_params
(
"login_captcha"
,
0
,
settings
=
settings
))
self
.
ws_print_url
=
settings
.
get
(
"ws_print_url"
,
""
)
self
.
ws_print_id
=
settings
.
get
(
"ws_print_id"
,
""
)
self
.
wsp_url
=
settings
.
get
(
"wsp_url"
,
""
)
self
.
wsp_client_id
=
settings
.
get
(
"wsp_client_id"
,
""
)
self
.
wsp_client_key
=
settings
.
get
(
"wsp_client_key"
,
""
)
def
add_menu
(
self
,
config
,
route_menus
,
parent
=
None
,
paket
=
"opensipkd.base.views"
,
template_path
=
"views/templates/"
):
...
...
opensipkd/base/views/printers.py
View file @
d1d8101
...
...
@@ -97,7 +97,7 @@ class AddSchema(colander.Schema):
epson_values
=
[
(
"0"
,
"Other"
),
(
"1"
,
"Epson Type"
),]
if
BASE_CLASS
.
ws
_print
_url
:
if
BASE_CLASS
.
ws
p
_url
:
epson_values
.
append
((
"2"
,
"Web Socket"
))
schema
[
"is_epson"
]
.
widget
.
values
=
epson_values
...
...
@@ -220,7 +220,7 @@ class Views(BaseView):
async
def
print_text
(
user_id
=
None
,
print_id
=
None
,
text
=
None
,
filename
=
None
,
ws_url
=
BASE_CLASS
.
ws
_print
_url
):
ws_url
=
BASE_CLASS
.
ws
p
_url
):
if
not
user_id
and
not
print_id
:
log
.
error
(
"User ID or Print ID must be provided."
)
raise
Exception
(
"User ID or Print ID must be provided."
)
...
...
@@ -236,8 +236,8 @@ async def print_text(user_id=None, print_id=None, text=None, filename=None,
timeout
=
printer
.
timeout
if
printer
else
10
# Timeout in seconds
if
is_ws
:
printer_name
=
printer
.
nama
if
printer
else
"unknown"
printer_name
=
BASE_CLASS
.
ws
_pri
nt_id
+
'_'
+
printer_name
ws_url
=
ws_url
or
BASE_CLASS
.
ws
_print
_url
printer_name
=
BASE_CLASS
.
ws
p_clie
nt_id
+
'_'
+
printer_name
ws_url
=
ws_url
or
BASE_CLASS
.
ws
p
_url
if
not
ws_url
:
log
.
error
(
"WebSocket URL is not configured."
)
raise
Exception
(
"WebSocket URL is not configured."
)
...
...
@@ -246,10 +246,29 @@ async def print_text(user_id=None, print_id=None, text=None, filename=None,
async
with
websockets
.
connect
(
ws_url
)
as
websocket
:
# Send user on connect
log
.
info
(
f
"Connected to server at {ws_url} as {printer_name}"
)
data
=
{
"login"
:
BASE_CLASS
.
ws_print_id
}
# data = {"action": "print",
# "printer": self.printer,
# "message": message
# }
data
=
{
"action"
:
"login"
,
"client_id"
:
BASE_CLASS
.
wsp_client_id
,
"api_key"
:
BASE_CLASS
.
wsp_client_key
,
"printer"
:
BASE_CLASS
.
wsp_client_id
}
await
websocket
.
send
(
json
.
dumps
(
data
))
text
=
await
websocket
.
recv
()
log
.
info
(
f
"Received from server: {text}"
)
try
:
resp
=
json
.
loads
(
text
)
except
json
.
JSONDecodeError
as
e
:
log
.
error
(
f
"Failed to decode server response: {e}"
)
raise
Exception
(
f
"Invalid response from server: {text}"
)
from
e
if
resp
.
get
(
"status"
)
!=
True
:
log
.
error
(
f
"Login failed: {resp.get('message', 'No message provided')}"
)
raise
Exception
(
f
"Login failed: {resp.get('message', 'No message provided')}"
)
# Wait for server to process login
if
filename
and
os
.
path
.
isfile
(
filename
):
...
...
pyproject.toml
View file @
d1d8101
...
...
@@ -38,6 +38,8 @@ dependencies = [
'wheezy.captcha'
,
'ziggurat-foundations'
,
'zope.sqlalchemy'
,
'websockets'
,
"asyncio"
,
]
requires-python
=
'>=
3.8
'
authors
=
[
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment